Commit 6930f9a9 authored by James Lopez's avatar James Lopez

Merge branches 'feature/project-export-ui-experimental' and...

Merge branches 'feature/project-export-ui-experimental' and 'feature/project-import' of gitlab.com:gitlab-org/gitlab-ce into feature/project-export-ui-experimental
parents 3c3559cf c3747003
...@@ -4,12 +4,16 @@ module Projects ...@@ -4,12 +4,16 @@ module Projects
def execute(options = {}) def execute(options = {})
@shared = Gitlab::ImportExport::Shared.new(relative_path: File.join(project.path_with_namespace, 'work')) @shared = Gitlab::ImportExport::Shared.new(relative_path: File.join(project.path_with_namespace, 'work'))
save_all if [save_project_tree, bundle_repo, bundle_wiki_repo].all? save_all if [save_version, save_project_tree, bundle_repo, bundle_wiki_repo].all?
notify_worker if @shared.errors.any? cleanup_and_notify_worker if @shared.errors.any?
end end
private private
def save_version
Gitlab::ImportExport::VersionSaver.save(shared: @shared)
end
def save_project_tree def save_project_tree
Gitlab::ImportExport::ProjectTreeSaver.new(project: project, shared: @shared).save Gitlab::ImportExport::ProjectTreeSaver.new(project: project, shared: @shared).save
end end
...@@ -26,7 +30,8 @@ module Projects ...@@ -26,7 +30,8 @@ module Projects
Gitlab::ImportExport::Saver.save(shared: @shared) Gitlab::ImportExport::Saver.save(shared: @shared)
end end
def notify_worker def cleanup_and_notify_worker
FileUtils.rm_rf(@shared.export_path)
raise Gitlab::ImportExport::Error.new(@shared.errors.join(', ')) raise Gitlab::ImportExport::Error.new(@shared.errors.join(', '))
end end
end end
......
...@@ -2,6 +2,8 @@ module Gitlab ...@@ -2,6 +2,8 @@ module Gitlab
module ImportExport module ImportExport
extend self extend self
VERSION = '0.1.0'
def export_path(relative_path:) def export_path(relative_path:)
File.join(storage_path, relative_path) File.join(storage_path, relative_path)
end end
...@@ -17,5 +19,9 @@ module Gitlab ...@@ -17,5 +19,9 @@ module Gitlab
def project_bundle_filename def project_bundle_filename
"project.bundle" "project.bundle"
end end
def version_filename
'VERSION'
end
end end
end end
...@@ -16,7 +16,7 @@ module Gitlab ...@@ -16,7 +16,7 @@ module Gitlab
def execute def execute
Gitlab::ImportExport::Importer.import(archive_file: @archive_file, Gitlab::ImportExport::Importer.import(archive_file: @archive_file,
shared: @shared) 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 project_tree.project
else else
project_tree.project.destroy if project_tree.project project_tree.project.destroy if project_tree.project
...@@ -26,6 +26,10 @@ module Gitlab ...@@ -26,6 +26,10 @@ module Gitlab
private private
def restore_version
Gitlab::ImportExport::VersionRestorer.restore(shared: @shared)
end
def restore_project_tree def restore_project_tree
project_tree.restore project_tree.restore
end 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
module Gitlab
module ImportExport
class VersionSaver
def self.save(*args)
new(*args).save
end
def initialize(shared:)
@shared = shared
end
def save
File.open(version_file, 'w') do |file|
file.write(Gitlab::ImportExport.VERSION)
end
rescue => e
@shared.error(e)
false
end
private
def version_file
File.join(@shared.export_path, Gitlab::ImportExport.version_filename)
end
end
end
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