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

45 lines
1.1 KiB
Ruby
Raw Normal View History

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
2019-09-30 21:07:59 +05:30
Rails.logger.error("Import/Export error: #{e.message}") # rubocop:disable Gitlab/RailsLogger
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