gitlab-org--gitlab-foss/lib/gitlab/import_export/version_checker.rb
gfyoung 7ec8af5017 Enable even more frozen string for lib/gitlab
Enables frozen string for the following:

* lib/gitlab/hook_data/**/*.rb
* lib/gitlab/i18n/**/*.rb
* lib/gitlab/import/**/*.rb
* lib/gitlab/import_export/**/*.rb
* lib/gitlab/kubernetes/**/*.rb
* lib/gitlab/legacy_github_import/**/*.rb
* lib/gitlab/manifest_import/**/*.rb
* lib/gitlab/metrics/**/*.rb
* lib/gitlab/middleware/**/*.rb

Partially addresses gitlab-org/gitlab-ce#47424.
2018-11-16 17:41:14 -08:00

44 lines
1.1 KiB
Ruby

# frozen_string_literal: true
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)
if different_version?(version)
raise Gitlab::ImportExport::Error.new("Import version mismatch: Required #{Gitlab::ImportExport.version} but was #{version}")
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
end
end
end