2018-11-16 19:37:17 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-05-16 06:39:42 -04:00
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
2016-06-02 04:59:54 -04:00
|
|
|
class VersionChecker
|
2020-10-15 14:08:43 -04:00
|
|
|
def self.check!(*args, **kwargs)
|
|
|
|
new(*args, **kwargs).check!
|
2016-05-16 06:39:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(shared:)
|
|
|
|
@shared = shared
|
|
|
|
end
|
|
|
|
|
2016-06-02 04:59:54 -04:00
|
|
|
def check!
|
2016-05-16 06:39:42 -04:00
|
|
|
version = File.open(version_file, &:readline)
|
|
|
|
verify_version!(version)
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => e
|
2016-05-16 06:39:42 -04:00
|
|
|
@shared.error(e)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def version_file
|
|
|
|
File.join(@shared.export_path, Gitlab::ImportExport.version_filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify_version!(version)
|
2016-10-27 11:10:19 -04:00
|
|
|
if different_version?(version)
|
2021-05-04 11:10:36 -04:00
|
|
|
raise Gitlab::ImportExport::Error, "Import version mismatch: Required #{Gitlab::ImportExport.version} but was #{version}"
|
2016-05-16 06:39:42 -04:00
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2016-10-27 11:10:19 -04:00
|
|
|
|
|
|
|
def different_version?(version)
|
|
|
|
Gem::Version.new(version) != Gem::Version.new(Gitlab::ImportExport.version)
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => e
|
2020-05-25 11:07:58 -04:00
|
|
|
Gitlab::Import::Logger.error(
|
|
|
|
message: 'Import error',
|
|
|
|
error: e.message
|
|
|
|
)
|
|
|
|
|
2021-05-04 11:10:36 -04:00
|
|
|
raise Gitlab::ImportExport::Error, 'Incorrect VERSION format'
|
2016-10-27 11:10:19 -04:00
|
|
|
end
|
2016-05-16 06:39:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|