gitlab-org--gitlab-foss/lib/gitlab/import_export/version_checker.rb

43 lines
1 KiB
Ruby
Raw Normal View History

2016-05-16 06:39:42 -04:00
module Gitlab
module ImportExport
2016-06-02 04:59:54 -04:00
class VersionChecker
def self.check!(*args)
new(*args).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)
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)
if different_version?(version)
raise Gitlab::ImportExport::Error.new("Import version mismatch: Required #{Gitlab::ImportExport.version} but was #{version}")
2016-05-16 06:39:42 -04:00
else
true
end
end
def different_version?(version)
Gem::Version.new(version) != Gem::Version.new(Gitlab::ImportExport.version)
rescue => e
Rails.logger.error("Import/Export error: #{e.message}")
raise Gitlab::ImportExport::Error.new('Incorrect VERSION format')
end
2016-05-16 06:39:42 -04:00
end
end
end