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
07ec2c7b
Commit
07ec2c7b
authored
Jul 13, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use fileuploader dynamic path method in uploads manager and add spec
parent
1263367c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
10 deletions
+18
-10
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+6
-2
lib/gitlab/import_export/uploads_manager.rb
lib/gitlab/import_export/uploads_manager.rb
+1
-6
spec/lib/gitlab/import_export/uploads_manager_spec.rb
spec/lib/gitlab/import_export/uploads_manager_spec.rb
+2
-2
spec/uploaders/file_uploader_spec.rb
spec/uploaders/file_uploader_spec.rb
+9
-0
No files found.
app/uploaders/file_uploader.rb
View file @
07ec2c7b
...
...
@@ -15,7 +15,7 @@ class FileUploader < GitlabUploader
prepend
ObjectStorage
::
Extension
::
RecordsUploads
MARKDOWN_PATTERN
=
%r{
\!
?
\[
.*?
\]\(
/uploads/(?<secret>[0-9a-f]{32})/(?<file>.*?)
\)
}
DYNAMIC_PATH_PATTERN
=
%r{(?<secret>
\h
{32})/(?<identifier>.*)}
DYNAMIC_PATH_PATTERN
=
%r{
.*
(?<secret>
\h
{32})/(?<identifier>.*)}
after
:remove
,
:prune_store_dir
...
...
@@ -67,6 +67,10 @@ class FileUploader < GitlabUploader
SecureRandom
.
hex
end
def
self
.
extract_dynamic_path
(
path
)
DYNAMIC_PATH_PATTERN
.
match
(
path
)
end
def
upload_paths
(
identifier
)
[
File
.
join
(
secret
,
identifier
),
...
...
@@ -143,7 +147,7 @@ class FileUploader < GitlabUploader
return
if
apply_context!
(
value
.
uploader_context
)
# fallback to the regex based extraction
if
matches
=
DYNAMIC_PATH_PATTERN
.
matc
h
(
value
.
path
)
if
matches
=
self
.
class
.
extract_dynamic_pat
h
(
value
.
path
)
@secret
=
matches
[
:secret
]
@identifier
=
matches
[
:identifier
]
end
...
...
lib/gitlab/import_export/uploads_manager.rb
View file @
07ec2c7b
...
...
@@ -43,12 +43,7 @@ module Gitlab
private
def
add_upload
(
upload
)
secret
,
identifier
=
upload
.
split
(
'/'
).
last
(
2
)
uploader_context
=
{
secret:
secret
,
identifier:
identifier
}
uploader_context
=
FileUploader
.
extract_dynamic_path
(
upload
).
named_captures
.
symbolize_keys
UploadService
.
new
(
@project
,
File
.
open
(
upload
,
'r'
),
FileUploader
,
uploader_context
).
execute
end
...
...
spec/lib/gitlab/import_export/uploads_manager_spec.rb
View file @
07ec2c7b
...
...
@@ -64,8 +64,8 @@ describe Gitlab::ImportExport::UploadsManager do
stub_feature_flags
(
import_export_object_storage:
true
)
stub_uploads_object_storage
(
FileUploader
)
FileUtils
.
mkdir_p
(
File
.
join
(
shared
.
export_path
,
'uploads/
random
'
))
FileUtils
.
touch
(
File
.
join
(
shared
.
export_path
,
'uploads/
random
'
,
"dummy.txt"
))
FileUtils
.
mkdir_p
(
File
.
join
(
shared
.
export_path
,
'uploads/
72a497a02fe3ee09edae2ed06d390038
'
))
FileUtils
.
touch
(
File
.
join
(
shared
.
export_path
,
'uploads/
72a497a02fe3ee09edae2ed06d390038
'
,
"dummy.txt"
))
end
it
'restores the file'
do
...
...
spec/uploaders/file_uploader_spec.rb
View file @
07ec2c7b
...
...
@@ -124,6 +124,15 @@ describe FileUploader do
end
end
describe
'.extract_dynamic_path'
do
it
'works with hashed storage'
do
path
=
'export/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a/test/uploads/72a497a02fe3ee09edae2ed06d390038/dummy.txt'
expect
(
described_class
.
extract_dynamic_path
(
path
)[
:identifier
]).
to
eq
(
'dummy.txt'
)
expect
(
described_class
.
extract_dynamic_path
(
path
)[
:secret
]).
to
eq
(
'72a497a02fe3ee09edae2ed06d390038'
)
end
end
describe
'#secret'
do
it
'generates a secret if none is provided'
do
expect
(
described_class
).
to
receive
(
:generate_secret
).
and_return
(
'secret'
)
...
...
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