2016-04-14 10:57:25 -04:00
|
|
|
module Gitlab
|
2016-03-08 06:35:37 -05:00
|
|
|
module ImportExport
|
|
|
|
class Shared
|
2018-02-27 09:11:13 -05:00
|
|
|
attr_reader :errors, :project
|
2016-05-10 11:15:20 -04:00
|
|
|
|
2018-02-27 09:11:13 -05:00
|
|
|
def initialize(project)
|
2017-12-02 14:49:01 -05:00
|
|
|
@project = project
|
2016-05-10 11:15:20 -04:00
|
|
|
@errors = []
|
2016-03-08 06:35:37 -05:00
|
|
|
end
|
|
|
|
|
2017-12-02 14:49:01 -05:00
|
|
|
def active_export_count
|
|
|
|
Dir[File.join(archive_path, '*')].count { |name| File.directory?(name) }
|
|
|
|
end
|
|
|
|
|
2016-03-08 06:35:37 -05:00
|
|
|
def export_path
|
2018-01-08 10:42:41 -05:00
|
|
|
@export_path ||= Gitlab::ImportExport.export_path(relative_path: relative_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def archive_path
|
|
|
|
@archive_path ||= Gitlab::ImportExport.export_path(relative_path: relative_archive_path)
|
2016-03-08 06:35:37 -05:00
|
|
|
end
|
2016-05-10 11:15:20 -04:00
|
|
|
|
2016-05-13 06:33:13 -04:00
|
|
|
def error(error)
|
|
|
|
error_out(error.message, caller[0].dup)
|
2018-03-30 11:45:59 -04:00
|
|
|
add_error_message(error.message)
|
2018-01-26 08:48:47 -05:00
|
|
|
|
2016-05-13 06:33:13 -04:00
|
|
|
# Debug:
|
2018-01-26 08:48:47 -05:00
|
|
|
if error.backtrace
|
|
|
|
Rails.logger.error("Import/Export backtrace: #{error.backtrace.join("\n")}")
|
|
|
|
else
|
|
|
|
Rails.logger.error("No backtrace found")
|
|
|
|
end
|
2016-05-10 11:15:20 -04:00
|
|
|
end
|
|
|
|
|
2018-03-30 11:45:59 -04:00
|
|
|
def add_error_message(error_message)
|
|
|
|
@errors << error_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_export_in_progress?
|
|
|
|
File.exist?(after_export_lock_file)
|
|
|
|
end
|
|
|
|
|
2016-05-10 11:15:20 -04:00
|
|
|
private
|
|
|
|
|
2018-01-08 10:42:41 -05:00
|
|
|
def relative_path
|
2017-12-02 14:49:01 -05:00
|
|
|
File.join(relative_archive_path, SecureRandom.hex)
|
2018-01-08 10:42:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def relative_archive_path
|
2018-02-27 09:11:13 -05:00
|
|
|
@project.disk_path
|
2018-01-08 10:42:41 -05:00
|
|
|
end
|
|
|
|
|
2016-05-10 11:15:20 -04:00
|
|
|
def error_out(message, caller)
|
|
|
|
Rails.logger.error("Import/Export error raised on #{caller}: #{message}")
|
|
|
|
end
|
2018-03-30 11:45:59 -04:00
|
|
|
|
|
|
|
def after_export_lock_file
|
|
|
|
AfterExportStrategies::BaseAfterExportStrategy.lock_file_path(project)
|
|
|
|
end
|
2016-03-08 06:35:37 -05:00
|
|
|
end
|
|
|
|
end
|
2016-03-08 12:20:32 -05:00
|
|
|
end
|