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 VersionChecker
|
|
|
|
def self.check!(*args)
|
|
|
|
new(*args).check!
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(shared:)
|
|
|
|
@shared = shared
|
|
|
|
end
|
|
|
|
|
|
|
|
def check!
|
|
|
|
version = File.open(version_file, &:readline)
|
|
|
|
verify_version!(version)
|
|
|
|
rescue => e
|
|
|
|
@shared.error(e)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def version_file
|
|
|
|
File.join(@shared.export_path, Gitlab::ImportExport.version_filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify_version!(version)
|
2016-11-03 12:29:30 +05:30
|
|
|
if different_version?(version)
|
2016-09-29 09:46:39 +05:30
|
|
|
raise Gitlab::ImportExport::Error.new("Import version mismatch: Required #{Gitlab::ImportExport.version} but was #{version}")
|
2016-06-22 15:30:34 +05:30
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
def different_version?(version)
|
|
|
|
Gem::Version.new(version) != Gem::Version.new(Gitlab::ImportExport.version)
|
|
|
|
rescue => e
|
2020-06-23 00:09:42 +05:30
|
|
|
Gitlab::Import::Logger.error(
|
|
|
|
message: 'Import error',
|
|
|
|
error: e.message
|
|
|
|
)
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
raise Gitlab::ImportExport::Error.new('Incorrect VERSION format')
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|