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
Show 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
...
@@ -51,17 +51,15 @@ class FileUploader < GitlabUploader
#
#
# Returns a String without a trailing slash
# Returns a String without a trailing slash
def
self
.
model_path_segment
(
model
)
def
self
.
model_path_segment
(
model
)
if
model
.
hashed_storage?
(
:attachments
)
case
model
model
.
disk_path
when
Storage
::
HashedProject
then
model
.
disk_path
when
Project
then
model
.
hashed_storage?
(
:attachments
)
?
model
.
disk_path
:
model
.
full_path
else
else
model
.
full_path
model
.
full_path
end
end
end
end
def
self
.
upload_path
(
secret
,
identifier
)
File
.
join
(
secret
,
identifier
)
end
def
self
.
generate_secret
def
self
.
generate_secret
SecureRandom
.
hex
SecureRandom
.
hex
end
end
...
@@ -75,8 +73,12 @@ class FileUploader < GitlabUploader
...
@@ -75,8 +73,12 @@ class FileUploader < GitlabUploader
apply_context!
(
uploader_context
)
apply_context!
(
uploader_context
)
end
end
# enforce the usage of Hashed storage when storing to
# remote store as the FileMover doesn't support OS
def
base_dir
def
base_dir
self
.
class
.
base_dir
(
@model
)
model
=
file_storage?
?
@model
:
Storage
::
HashedProject
.
new
(
@model
)
self
.
class
.
base_dir
(
model
)
end
end
# we don't need to know the actual path, an uploader instance should be
# we don't need to know the actual path, an uploader instance should be
...
@@ -86,15 +88,18 @@ class FileUploader < GitlabUploader
...
@@ -86,15 +88,18 @@ class FileUploader < GitlabUploader
end
end
def
upload_path
def
upload_path
self
.
class
.
upload_path
(
dynamic_segment
,
identifier
)
if
file_storage?
# Legacy
File
.
join
(
dynamic_segment
,
identifier
)
else
File
.
join
(
store_dir
,
identifier
)
end
end
def
model_path_segment
self
.
class
.
model_path_segment
(
@model
)
end
end
def
store_dir
def
store_dirs
File
.
join
(
base_dir
,
dynamic_segment
)
{
Store
::
LOCAL
=>
local_store_dir
=
File
.
join
(
base_dir
,
dynamic_segment
),
Store
::
REMOTE
=>
local_store_dir
}
end
end
def
markdown_link
def
markdown_link
...
@@ -134,6 +139,9 @@ class FileUploader < GitlabUploader
...
@@ -134,6 +139,9 @@ class FileUploader < GitlabUploader
private
private
def
hashed_model
end
def
apply_context!
(
uploader_context
)
def
apply_context!
(
uploader_context
)
@secret
,
@identifier
=
uploader_context
.
values_at
(
:secret
,
:identifier
)
@secret
,
@identifier
=
uploader_context
.
values_at
(
:secret
,
:identifier
)
...
...
spec/uploaders/file_uploader_spec.rb
View file @
fb12eaef
...
@@ -11,20 +11,20 @@ describe FileUploader do
...
@@ -11,20 +11,20 @@ describe FileUploader do
shared_examples
'builds correct legacy storage paths'
do
shared_examples
'builds correct legacy storage paths'
do
include_examples
'builds correct paths'
,
include_examples
'builds correct paths'
,
store_dir:
%r{awesome/project/
\h
+}
,
store_dir:
%r{awesome/project/
\h
+}
,
upload_path:
%r{
\h
+/<filename>}
,
absolute_path:
%r{
#{
described_class
.
root
}
/awesome/project/secret/foo.jpg}
absolute_path:
%r{
#{
described_class
.
root
}
/awesome/project/secret/foo.jpg}
end
end
shared_examples
'uses hashed storage'
do
context
'legacy storage'
do
it_behaves_like
'builds correct legacy storage paths'
context
'uses hashed storage'
do
context
'when rolled out attachments'
do
context
'when rolled out attachments'
do
let
(
:project
)
{
build_stubbed
(
:project
,
namespace:
group
,
name:
'project'
)
}
let
(
:project
)
{
build_stubbed
(
:project
,
namespace:
group
,
name:
'project'
)
}
before
do
include_examples
'builds correct paths'
,
allow
(
project
).
to
receive
(
:disk_path
).
and_return
(
'ca/fe/fe/ed'
)
store_dir:
%r{@hashed/
\h
{2}/
\h
{2}/
\h
+}
,
end
upload_path:
%r{
\h
+/<filename>}
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
end
context
'when only repositories are rolled out'
do
context
'when only repositories are rolled out'
do
...
@@ -33,10 +33,6 @@ describe FileUploader do
...
@@ -33,10 +33,6 @@ describe FileUploader do
it_behaves_like
'builds correct legacy storage paths'
it_behaves_like
'builds correct legacy storage paths'
end
end
end
end
context
'legacy storage'
do
it_behaves_like
'builds correct legacy storage paths'
include_examples
'uses hashed storage'
end
end
context
'object store is remote'
do
context
'object store is remote'
do
...
@@ -46,8 +42,10 @@ describe FileUploader do
...
@@ -46,8 +42,10 @@ describe FileUploader do
include_context
'with storage'
,
described_class
::
Store
::
REMOTE
include_context
'with storage'
,
described_class
::
Store
::
REMOTE
it_behaves_like
'builds correct legacy storage paths'
# always use hashed storage path for remote uploads
include_examples
'uses hashed storage'
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
end
describe
'initialize'
do
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