debian-mirror-gitlab/lib/gitlab/import_export/file_importer.rb

51 lines
1.1 KiB
Ruby
Raw Normal View History

2016-06-22 15:30:34 +05:30
module Gitlab
module ImportExport
class FileImporter
include Gitlab::ImportExport::CommandLineUtil
2016-08-24 12:49:21 +05:30
MAX_RETRIES = 8
2016-06-22 15:30:34 +05:30
def self.import(*args)
new(*args).import
end
def initialize(archive_file:, shared:)
@archive_file = archive_file
@shared = shared
end
def import
FileUtils.mkdir_p(@shared.export_path)
2016-08-24 12:49:21 +05:30
wait_for_archived_file do
decompress_archive
end
2016-06-22 15:30:34 +05:30
rescue => e
@shared.error(e)
false
end
private
2016-08-24 12:49:21 +05:30
# Exponentially sleep until I/O finishes copying the file
def wait_for_archived_file
MAX_RETRIES.times do |retry_number|
break if File.exist?(@archive_file)
sleep(2**retry_number)
end
yield
end
2016-06-22 15:30:34 +05:30
def decompress_archive
2016-08-24 12:49:21 +05:30
result = untar_zxf(archive: @archive_file, dir: @shared.export_path)
raise Projects::ImportService::Error.new("Unable to decompress #{@archive_file} into #{@shared.export_path}") unless result
true
2016-06-22 15:30:34 +05:30
end
end
end
end