Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
7c43692f
Commit
7c43692f
authored
Nov 08, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make regexes more readable
parent
41412fec
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
13 deletions
+13
-13
lib/gitlab/background_migration/populate_untracked_uploads.rb
...gitlab/background_migration/populate_untracked_uploads.rb
+11
-11
spec/migrations/track_untracked_uploads_spec.rb
spec/migrations/track_untracked_uploads_spec.rb
+2
-2
No files found.
lib/gitlab/background_migration/populate_untracked_uploads.rb
View file @
7c43692f
...
...
@@ -5,7 +5,8 @@ module Gitlab
self
.
table_name
=
'unhashed_upload_files'
# Ends with /:random_hex/:filename
FILE_UPLOADER_PATH_PATTERN
=
/\/\h+\/[^\/]+\z/
FILE_UPLOADER_PATH_PATTERN
=
%r{/
\h
+/[^/]+
\z
}
FILE_UPLOADER_CAPTURE_FULL_PATH_PATTERN
=
%r{
\A
(.+)
#{
FILE_UPLOADER_PATH_PATTERN
}
}
# These regex patterns are tested against a relative path, relative to
# the upload directory.
...
...
@@ -13,32 +14,32 @@ module Gitlab
# it indicates the model_id.
PATH_PATTERNS
=
[
{
pattern:
/\A-\/system\/appearance\/logo\/(\d+)/
,
pattern:
%r{
\A
-/system/appearance/logo/(
\d
+)/}
,
uploader:
'AttachmentUploader'
,
model_type:
'Appearance'
},
{
pattern:
/\A-\/system\/appearance\/header_logo\/(\d+)/
,
pattern:
%r{
\A
-/system/appearance/header_logo/(
\d
+)/}
,
uploader:
'AttachmentUploader'
,
model_type:
'Appearance'
},
{
pattern:
/\A-\/system\/note\/attachment\/(\d+)/
,
pattern:
%r{
\A
-/system/note/attachment/(
\d
+)/}
,
uploader:
'AttachmentUploader'
,
model_type:
'Note'
},
{
pattern:
/\A-\/system\/user\/avatar\/(\d+)/
,
pattern:
%r{
\A
-/system/user/avatar/(
\d
+)/}
,
uploader:
'AvatarUploader'
,
model_type:
'User'
},
{
pattern:
/\A-\/system\/group\/avatar\/(\d+)/
,
pattern:
%r{
\A
-/system/group/avatar/(
\d
+)/}
,
uploader:
'AvatarUploader'
,
model_type:
'Namespace'
},
{
pattern:
/\A-\/system\/project\/avatar\/(\d+)/
,
pattern:
%r{
\A
-/system/project/avatar/(
\d
+)/}
,
uploader:
'AvatarUploader'
,
model_type:
'Project'
},
...
...
@@ -90,7 +91,7 @@ module Gitlab
if
uploader
==
'FileUploader'
# Path relative to project directory in uploads
matchd
=
path_relative_to_upload_dir
.
match
(
FILE_UPLOADER_PATH_PATTERN
)
matchd
[
0
].
sub
(
/\A\//
,
''
)
# remove leading slash
matchd
[
0
].
sub
(
%r{
\A
/}
,
''
)
# remove leading slash
else
path_relative_to_carrierwave_root
end
...
...
@@ -120,7 +121,7 @@ module Gitlab
# Not including a leading slash
def
path_relative_to_upload_dir
@path_relative_to_upload_dir
||=
path
.
sub
(
/\A
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhashedUploads
::
UPLOAD_DIR
}
\//
,
''
)
@path_relative_to_upload_dir
||=
path
.
sub
(
%r{
\A
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhashedUploads
::
UPLOAD_DIR
}
/}
,
''
)
end
# Not including a leading slash
...
...
@@ -141,8 +142,7 @@ module Gitlab
end
def
file_uploader_model_id
pattern_to_capture_full_path
=
/\A(.+)
#{
FILE_UPLOADER_PATH_PATTERN
}
/
matchd
=
path_relative_to_upload_dir
.
match
(
pattern_to_capture_full_path
)
matchd
=
path_relative_to_upload_dir
.
match
(
FILE_UPLOADER_CAPTURE_FULL_PATH_PATTERN
)
raise
"Could not capture project full_path from a FileUploader path:
\"
#{
path_relative_to_upload_dir
}
\"
"
unless
matchd
full_path
=
matchd
[
1
]
project
=
Project
.
find_by_full_path
(
full_path
)
...
...
spec/migrations/track_untracked_uploads_spec.rb
View file @
7c43692f
...
...
@@ -59,7 +59,7 @@ describe TrackUntrackedUploads, :migration, :sidekiq do
user1
.
update
(
avatar:
uploaded_file
)
project1
.
update
(
avatar:
uploaded_file
)
upload_result
=
UploadService
.
new
(
project1
,
uploaded_file
,
FileUploader
).
execute
# Markdown upload
@project1_markdown_upload_path
=
upload_result
[
:url
].
sub
(
/\A\/uploads\//
,
''
)
@project1_markdown_upload_path
=
upload_result
[
:url
].
sub
(
%r{
\A
/uploads/}
,
''
)
appearance
.
update
(
logo:
uploaded_file
)
# Untracked, by doing normal file upload then deleting records from DB
...
...
@@ -68,7 +68,7 @@ describe TrackUntrackedUploads, :migration, :sidekiq do
user2
.
uploads
.
delete_all
project2
.
update
(
avatar:
uploaded_file
)
upload_result
=
UploadService
.
new
(
project2
,
uploaded_file
,
FileUploader
).
execute
# Markdown upload
@project2_markdown_upload_path
=
upload_result
[
:url
].
sub
(
/\A\/uploads\//
,
''
)
@project2_markdown_upload_path
=
upload_result
[
:url
].
sub
(
%r{
\A
/uploads/}
,
''
)
project2
.
uploads
.
delete_all
appearance
.
update
(
header_logo:
uploaded_file
)
appearance
.
uploads
.
last
.
destroy
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment