2016-04-14 14:57:25 +00:00
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class Saver
|
|
|
|
include Gitlab::ImportExport::CommandLineUtil
|
|
|
|
|
|
|
|
def self.save(*args)
|
|
|
|
new(*args).save
|
|
|
|
end
|
|
|
|
|
2016-07-15 10:47:06 +00:00
|
|
|
def initialize(project:, shared:)
|
|
|
|
@project = project
|
2016-05-10 15:15:20 +00:00
|
|
|
@shared = shared
|
2016-04-14 14:57:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
if compress_and_save
|
2016-05-11 12:51:25 +00:00
|
|
|
remove_export_path
|
2016-05-03 09:13:10 +00:00
|
|
|
Rails.logger.info("Saved project export #{archive_file}")
|
2016-04-14 14:57:25 +00:00
|
|
|
archive_file
|
|
|
|
else
|
2016-07-07 07:49:46 +00:00
|
|
|
@shared.error(Gitlab::ImportExport::Error.new("Unable to save #{archive_file} into #{@shared.export_path}"))
|
2016-04-14 14:57:25 +00:00
|
|
|
false
|
|
|
|
end
|
2016-05-10 15:15:20 +00:00
|
|
|
rescue => e
|
2016-05-13 10:33:13 +00:00
|
|
|
@shared.error(e)
|
2016-05-10 15:15:20 +00:00
|
|
|
false
|
2016-04-14 14:57:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def compress_and_save
|
2016-05-11 12:51:25 +00:00
|
|
|
tar_czf(archive: archive_file, dir: @shared.export_path)
|
2016-04-14 14:57:25 +00:00
|
|
|
end
|
|
|
|
|
2016-05-11 12:51:25 +00:00
|
|
|
def remove_export_path
|
|
|
|
FileUtils.rm_rf(@shared.export_path)
|
2016-04-14 14:57:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def archive_file
|
2018-01-08 15:42:41 +00:00
|
|
|
@archive_file ||= File.join(@shared.archive_path, Gitlab::ImportExport.export_filename(project: @project))
|
2016-04-14 14:57:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|