BigW Consortium Gitlab

version_checker.rb 1.03 KB
Newer Older
1 2
module Gitlab
  module ImportExport
3
    class VersionChecker
4 5
      def self.check!(*args)
        new(*args).check!
6 7 8 9 10 11
      end

      def initialize(shared:)
        @shared = shared
      end

12
      def check!
13 14 15 16 17 18 19 20 21 22 23 24 25 26
        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)
27
        if different_version?(version)
28
          raise Gitlab::ImportExport::Error.new("Import version mismatch: Required #{Gitlab::ImportExport.version} but was #{version}")
29 30 31 32
        else
          true
        end
      end
33 34 35 36 37 38 39

      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
40 41 42
    end
  end
end