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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
fb12eaef
Commit
fb12eaef
authored
Feb 16, 2018
by
Micaël Bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enforce the use of hashed storage for remote file uploads
parent
fb0b98a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
34 deletions
+40
-34
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+22
-14
spec/uploaders/file_uploader_spec.rb
spec/uploaders/file_uploader_spec.rb
+18
-20
No files found.
app/uploaders/file_uploader.rb
View file @
fb12eaef
...
...
@@ -51,17 +51,15 @@ class FileUploader < GitlabUploader
#
# Returns a String without a trailing slash
def
self
.
model_path_segment
(
model
)
if
model
.
hashed_storage?
(
:attachments
)
model
.
disk_path
case
model
when
Storage
::
HashedProject
then
model
.
disk_path
when
Project
then
model
.
hashed_storage?
(
:attachments
)
?
model
.
disk_path
:
model
.
full_path
else
model
.
full_path
end
end
def
self
.
upload_path
(
secret
,
identifier
)
File
.
join
(
secret
,
identifier
)
end
def
self
.
generate_secret
SecureRandom
.
hex
end
...
...
@@ -75,8 +73,12 @@ class FileUploader < GitlabUploader
apply_context!
(
uploader_context
)
end
# enforce the usage of Hashed storage when storing to
# remote store as the FileMover doesn't support OS
def
base_dir
self
.
class
.
base_dir
(
@model
)
model
=
file_storage?
?
@model
:
Storage
::
HashedProject
.
new
(
@model
)
self
.
class
.
base_dir
(
model
)
end
# we don't need to know the actual path, an uploader instance should be
...
...
@@ -86,15 +88,18 @@ class FileUploader < GitlabUploader
end
def
upload_path
self
.
class
.
upload_path
(
dynamic_segment
,
identifier
)
end
def
model_path_segment
self
.
class
.
model_path_segment
(
@model
)
if
file_storage?
# Legacy
File
.
join
(
dynamic_segment
,
identifier
)
else
File
.
join
(
store_dir
,
identifier
)
end
end
def
store_dir
File
.
join
(
base_dir
,
dynamic_segment
)
def
store_dirs
{
Store
::
LOCAL
=>
local_store_dir
=
File
.
join
(
base_dir
,
dynamic_segment
),
Store
::
REMOTE
=>
local_store_dir
}
end
def
markdown_link
...
...
@@ -134,6 +139,9 @@ class FileUploader < GitlabUploader
private
def
hashed_model
end
def
apply_context!
(
uploader_context
)
@secret
,
@identifier
=
uploader_context
.
values_at
(
:secret
,
:identifier
)
...
...
spec/uploaders/file_uploader_spec.rb
View file @
fb12eaef
...
...
@@ -11,34 +11,30 @@ describe FileUploader do
shared_examples
'builds correct legacy storage paths'
do
include_examples
'builds correct paths'
,
store_dir:
%r{awesome/project/
\h
+}
,
upload_path:
%r{
\h
+/<filename>}
,
absolute_path:
%r{
#{
described_class
.
root
}
/awesome/project/secret/foo.jpg}
end
shared_examples
'uses hashed storage'
do
context
'when rolled out attachments'
do
let
(
:project
)
{
build_stubbed
(
:project
,
namespace:
group
,
name:
'project'
)
}
context
'legacy storage'
do
it_behaves_like
'builds correct legacy storage paths'
before
do
allow
(
project
).
to
receive
(
:disk_path
).
and_return
(
'ca/fe/fe/ed'
)
end
context
'uses hashed storage'
do
context
'when rolled out attachments'
do
let
(
:project
)
{
build_stubbed
(
:project
,
namespace:
group
,
name:
'project'
)
}
it_behaves_like
'builds correct paths'
,
store_dir:
%r{ca/fe/fe/ed
/
\h
+}
,
absolute_path:
%r{
#{
described_class
.
root
}
/ca/fe/fe/ed/secret/foo.jpg
}
end
include_examples
'builds correct paths'
,
store_dir:
%r{@hashed/
\h
{2}/
\h
{2}
/
\h
+}
,
upload_path:
%r{
\h
+/<filename>
}
end
context
'when only repositories are rolled out'
do
let
(
:project
)
{
build_stubbed
(
:project
,
namespace:
group
,
name:
'project'
,
storage_version:
Project
::
HASHED_STORAGE_FEATURES
[
:repository
])
}
context
'when only repositories are rolled out'
do
let
(
:project
)
{
build_stubbed
(
:project
,
namespace:
group
,
name:
'project'
,
storage_version:
Project
::
HASHED_STORAGE_FEATURES
[
:repository
])
}
it_behaves_like
'builds correct legacy storage paths'
it_behaves_like
'builds correct legacy storage paths'
end
end
end
context
'legacy storage'
do
it_behaves_like
'builds correct legacy storage paths'
include_examples
'uses hashed storage'
end
context
'object store is remote'
do
before
do
stub_uploads_object_storage
...
...
@@ -46,8 +42,10 @@ describe FileUploader do
include_context
'with storage'
,
described_class
::
Store
::
REMOTE
it_behaves_like
'builds correct legacy storage paths'
include_examples
'uses hashed storage'
# always use hashed storage path for remote uploads
it_behaves_like
'builds correct paths'
,
store_dir:
%r{@hashed/
\h
{2}/
\h
{2}/
\h
+}
,
upload_path:
%r{@hashed/
\h
{2}/
\h
{2}/
\h
+/
\h
+/<filename>}
end
describe
'initialize'
do
...
...
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