summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2018-07-11 10:24:59 +0200
committerJames Lopez <james@jameslopez.es>2018-07-11 10:24:59 +0200
commit7c9f21683ce2eea8f1f901d81b32ad775d7f9ba6 (patch)
tree9e7f9721d2b7b202969291a8b9efbc3c6d5e22ef
parenta27d4d9e524ee0b7eb5f5518fc6f8af00e1e6dfe (diff)
downloadgitlab-ce-7c9f21683ce2eea8f1f901d81b32ad775d7f9ba6.tar.gz
add restore method
-rw-r--r--lib/gitlab/import_export/avatar_saver.rb2
-rw-r--r--lib/gitlab/import_export/uploads_manager.rb19
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/gitlab/import_export/avatar_saver.rb b/lib/gitlab/import_export/avatar_saver.rb
index 848c05f116b..31ef0490cb3 100644
--- a/lib/gitlab/import_export/avatar_saver.rb
+++ b/lib/gitlab/import_export/avatar_saver.rb
@@ -16,7 +16,7 @@ module Gitlab
shared: @shared,
relative_export_path: 'avatar',
from: avatar_path
- ).copy
+ ).save
rescue => e
@shared.error(e)
false
diff --git a/lib/gitlab/import_export/uploads_manager.rb b/lib/gitlab/import_export/uploads_manager.rb
index 63935fc6822..d47b1f2e8f7 100644
--- a/lib/gitlab/import_export/uploads_manager.rb
+++ b/lib/gitlab/import_export/uploads_manager.rb
@@ -10,8 +10,8 @@ module Gitlab
@from = from || default_uploads_path
end
- def copy
- copy_files(@from, uploads_export_path) if File.directory?(@from)
+ def save
+ copy_files(@from, default_uploads_path) if File.directory?(@from)
if File.file?(@from) && @relative_export_path == 'avatar'
copy_files(@from, File.join(uploads_export_path, @project.avatar.filename))
@@ -25,6 +25,21 @@ module Gitlab
false
end
+ def restore
+ Dir["#{uploads_export_path}/**/*"].each do |upload|
+ next if File.directory?(upload)
+
+ upload_path = File.join(uploads_export_path, upload)
+
+ UploadService.new(@project, File.open(upload_path, 'r'), FileUploader).execute
+ end
+
+ true
+ rescue => e
+ @shared.error(e)
+ false
+ end
+
private
def copy_from_object_storage