Commit 51487575 authored by James Lopez's avatar James Lopez

added version check on import

parent 8c478874
......@@ -16,7 +16,7 @@ module Gitlab
def execute
Gitlab::ImportExport::Importer.import(archive_file: @archive_file,
shared: @shared)
if [restore_project_tree, restore_repo, restore_wiki_repo].all?
if [restore_version, restore_project_tree, restore_repo, restore_wiki_repo].all?
project_tree.project
else
project_tree.project.destroy if project_tree.project
......@@ -26,6 +26,10 @@ module Gitlab
private
def restore_version
Gitlab::ImportExport::VersionRestorer.restore(shared: @shared)
end
def restore_project_tree
project_tree.restore
end
......
module Gitlab
module ImportExport
class VersionRestorer
def self.restore(*args)
new(*args).restore
end
def initialize(shared:)
@shared = shared
end
def restore
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 Gem::Version.new(version) > Gem::Version.new(Gitlab::ImportExport.VERSION)
raise Gitlab::ImportExport::Error("Import version mismatch: Required <= #{Gitlab::ImportExport.VERSION} but was #{version}")
else
true
end
end
end
end
end
......@@ -15,7 +15,7 @@ module Gitlab
file.write(Gitlab::ImportExport.VERSION)
end
rescue => e
@shared.error(e.message)
@shared.error(e)
false
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment