2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class RepoSaver
|
|
|
|
include Gitlab::ImportExport::CommandLineUtil
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
attr_reader :exportable, :shared
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
def initialize(exportable:, shared:)
|
|
|
|
@exportable = exportable
|
2016-06-22 15:30:34 +05:30
|
|
|
@shared = shared
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2019-12-21 20:55:43 +05:30
|
|
|
return true unless repository_exists? # it's ok to have no repo
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
bundle_to_disk
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
def repository
|
|
|
|
@repository ||= @exportable.repository
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
private
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def repository_exists?
|
|
|
|
repository.exists? && !repository.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def bundle_full_path
|
2021-03-11 19:13:27 +05:30
|
|
|
File.join(shared.export_path, bundle_filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
def bundle_filename
|
|
|
|
::Gitlab::ImportExport.project_bundle_filename
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
def bundle_to_disk
|
2021-03-11 19:13:27 +05:30
|
|
|
mkdir_p(File.dirname(bundle_full_path))
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
repository.bundle_to_disk(bundle_full_path)
|
2021-06-08 01:23:25 +05:30
|
|
|
rescue StandardError => e
|
2019-12-21 20:55:43 +05:30
|
|
|
shared.error(e)
|
2016-06-22 15:30:34 +05:30
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|