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
|
2021-01-03 14:25:43 +05:30
|
|
|
def self.check!(*args, **kwargs)
|
|
|
|
new(*args, **kwargs).check!
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(shared:)
|
|
|
|
@shared = shared
|
|
|
|
end
|
|
|
|
|
|
|
|
def check!
|
|
|
|
version = File.open(version_file, &:readline)
|
|
|
|
verify_version!(version)
|
2021-06-08 01:23:25 +05:30
|
|
|
rescue StandardError => e
|
2016-06-22 15:30:34 +05:30
|
|
|
@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)
|
2021-06-08 01:23:25 +05:30
|
|
|
raise Gitlab::ImportExport::Error, "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)
|
2023-03-17 16:20:25 +05:30
|
|
|
Gitlab::VersionInfo.parse(version) != Gitlab::VersionInfo.parse(Gitlab::ImportExport.version)
|
2021-06-08 01:23:25 +05:30
|
|
|
rescue StandardError => e
|
2020-06-23 00:09:42 +05:30
|
|
|
Gitlab::Import::Logger.error(
|
|
|
|
message: 'Import error',
|
|
|
|
error: e.message
|
|
|
|
)
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
raise Gitlab::ImportExport::Error, 'Incorrect VERSION format'
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|