diff options
author | James Lopez <james@jameslopez.es> | 2018-07-11 11:24:59 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2018-07-11 11:24:59 +0300 |
commit | 7c9f21683ce2eea8f1f901d81b32ad775d7f9ba6 (patch) | |
tree | 9e7f9721d2b7b202969291a8b9efbc3c6d5e22ef /lib/gitlab/import_export | |
parent | a27d4d9e524ee0b7eb5f5518fc6f8af00e1e6dfe (diff) |
add restore method
Diffstat (limited to 'lib/gitlab/import_export')
-rw-r--r-- | lib/gitlab/import_export/avatar_saver.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/import_export/uploads_manager.rb | 19 |
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 |