2016-05-19 11:02:57 +00:00
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class UploadsSaver
|
|
|
|
|
|
|
|
def initialize(project:, shared:)
|
|
|
|
@project = project
|
|
|
|
@shared = shared
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
return true unless File.directory?(uploads_path)
|
|
|
|
|
2016-05-19 13:36:20 +00:00
|
|
|
copy_files(uploads_path, uploads_export_path)
|
2016-05-19 11:02:57 +00:00
|
|
|
rescue => e
|
2016-05-19 13:36:20 +00:00
|
|
|
@shared.error(e)
|
2016-05-19 11:02:57 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-05-19 13:36:20 +00:00
|
|
|
def copy_files(source, destination)
|
|
|
|
FileUtils.mkdir_p(destination)
|
|
|
|
FileUtils.copy_entry(source, destination)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2016-05-19 11:02:57 +00:00
|
|
|
def uploads_export_path
|
|
|
|
File.join(@shared.export_path, 'uploads')
|
|
|
|
end
|
|
|
|
|
|
|
|
def uploads_path
|
2016-05-19 13:36:20 +00:00
|
|
|
File.join(Rails.root.join('public/uploads'), @project.path_with_namespace)
|
2016-05-19 11:02:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|