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
Jérome Perrin
gitlab-ce
Commits
58f32622
Commit
58f32622
authored
Nov 24, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes to Attachments Migration for EE and Geo compatibility
parent
dc62441f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
8 deletions
+22
-8
app/services/projects/hashed_storage/migrate_attachments_service.rb
...es/projects/hashed_storage/migrate_attachments_service.rb
+12
-5
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+9
-2
spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb
...ojects/hashed_storage/migrate_attachments_service_spec.rb
+1
-1
No files found.
app/services/projects/hashed_storage/migrate_attachments_service.rb
View file @
58f32622
...
...
@@ -3,7 +3,7 @@ module Projects
AttachmentMigrationError
=
Class
.
new
(
StandardError
)
class
MigrateAttachmentsService
<
BaseService
attr_reader
:logger
attr_reader
:logger
,
:old_path
,
:new_path
def
initialize
(
project
,
logger
=
nil
)
@project
=
project
...
...
@@ -11,16 +11,21 @@ module Projects
end
def
execute
old_path
=
FileUploader
.
dynamic_path_segment
(
project
)
@old_path
=
project
.
full_path
@new_path
=
project
.
disk_path
origin
=
FileUploader
.
dynamic_path_segment
(
project
)
project
.
storage_version
=
::
Project
::
HASHED_STORAGE_FEATURES
[
:attachments
]
new_path
=
FileUploader
.
dynamic_path_segment
(
project
)
target
=
FileUploader
.
dynamic_path_segment
(
project
)
move_folder!
(
old_path
,
new_path
)
result
=
move_folder!
(
origin
,
target
)
project
.
save!
if
block_given?
if
result
&&
block_given?
yield
end
result
end
private
...
...
@@ -41,6 +46,8 @@ module Projects
FileUtils
.
mv
(
old_path
,
new_path
)
logger
.
info
(
"Migrated project attachments from '
#{
old_path
}
' to '
#{
new_path
}
' (PROJECT_ID=
#{
project
.
id
}
)"
)
true
end
end
end
...
...
app/uploaders/file_uploader.rb
View file @
58f32622
...
...
@@ -31,12 +31,19 @@ class FileUploader < GitlabUploader
# Returns a String without a trailing slash
def
self
.
dynamic_path_segment
(
project
)
if
project
.
hashed_storage?
(
:attachments
)
File
.
join
(
CarrierWave
.
root
,
base_dir
,
project
.
disk_path
)
dynamic_path_builder
(
project
.
disk_path
)
else
File
.
join
(
CarrierWave
.
root
,
base_dir
,
project
.
full_path
)
dynamic_path_builder
(
project
.
full_path
)
end
end
# Auxiliary method to build dynamic path segment when not using a project model
#
# Prefer to use the `.dynamic_path_segment` as it includes Hashed Storage specific logic
def
self
.
dynamic_path_builder
(
path
)
File
.
join
(
CarrierWave
.
root
,
base_dir
,
path
)
end
attr_accessor
:model
attr_reader
:secret
...
...
spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb
View file @
58f32622
...
...
@@ -58,6 +58,6 @@ describe Projects::HashedStorage::MigrateAttachmentsService do
end
def
base_path
(
storage
)
File
.
join
(
CarrierWave
.
root
,
FileUploader
.
base_dir
,
storage
.
disk_path
)
File
Uploader
.
dynamic_path_builder
(
storage
.
disk_path
)
end
end
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