From cec4ae55b728c76f797ada20125d5bbf2af0adb9 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Wed, 27 Apr 2016 18:07:40 +0200 Subject: [PATCH] quite a few fixes - import service --- lib/gitlab/import_export/command_line_util.rb | 12 +++--------- lib/gitlab/import_export/import_service.rb | 4 ++-- lib/gitlab/import_export/importer.rb | 1 + lib/gitlab/import_export/project_tree_restorer.rb | 4 +++- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/gitlab/import_export/command_line_util.rb b/lib/gitlab/import_export/command_line_util.rb index 3665e2edb7d..e8d41a6bd3d 100644 --- a/lib/gitlab/import_export/command_line_util.rb +++ b/lib/gitlab/import_export/command_line_util.rb @@ -6,11 +6,11 @@ module Gitlab end def untar_czf(archive:, dir:) - untar_with_options(archive: archive, dir: dir, options: 'czf') + tar_with_options(archive: archive, dir: dir, options: 'czf') end def untar_cf(archive:, dir:) - untar_with_options(archive: archive, dir: dir, options: 'cf') + tar_with_options(archive: archive, dir: dir, options: 'cf') end def tar_czf(archive:, dir:) @@ -24,13 +24,7 @@ module Gitlab end def tar_with_options(archive:, dir:, options:) - cmd = %W(tar -#{options} #{archive} -C #{dir}) - _output, status = Gitlab::Popen.popen(cmd) - status.zero? - end - - def untar_with_options(archive:, dir:, options:) - cmd = %W(tar -#{options} #{archive} -C #{dir}) + cmd = %W(tar -#{options} #{archive} #{dir}) _output, status = Gitlab::Popen.popen(cmd) status.zero? end diff --git a/lib/gitlab/import_export/import_service.rb b/lib/gitlab/import_export/import_service.rb index 5152d6ac182..226499030af 100644 --- a/lib/gitlab/import_export/import_service.rb +++ b/lib/gitlab/import_export/import_service.rb @@ -3,7 +3,7 @@ module Gitlab class ImportService def self.execute(*args) - new(args).execute + new(*args).execute end def initialize(archive_file:, owner:, namespace_id:, project_path:) @@ -26,7 +26,7 @@ module Gitlab end def project_tree - @project_tree ||= Gitlab::ImportExport::ProjectTreeRestorer.new(path: storage_path, user: @current_user) + @project_tree ||= Gitlab::ImportExport::ProjectTreeRestorer.new(path: storage_path, user: @current_user, project_path: @project_path) end def restore_repo diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb index 9f399845437..225e6f34991 100644 --- a/lib/gitlab/import_export/importer.rb +++ b/lib/gitlab/import_export/importer.rb @@ -13,6 +13,7 @@ module Gitlab end def import + FileUtils.mkdir_p(@storage_path) decompress_archive end diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb index 445f1d884d0..7b41ba0685b 100644 --- a/lib/gitlab/import_export/project_tree_restorer.rb +++ b/lib/gitlab/import_export/project_tree_restorer.rb @@ -3,9 +3,10 @@ module Gitlab class ProjectTreeRestorer attr_reader :project - def initialize(path:, user:) + def initialize(path:, user:, project_path:) @path = File.join(path, 'project.json') @user = user + @project_path = project_path end def restore @@ -48,6 +49,7 @@ module Gitlab project_params = @tree_hash.reject { |_key, value| value.is_a?(Array) } project = Gitlab::ImportExport::ProjectFactory.create( project_params: project_params, user: @user) + project.path = @project_path project.save project.import_start project -- GitLab