From 8f973b8f6887da082c4e4c777dc3961fae32ab16 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 22 Apr 2016 12:45:20 +0200 Subject: [PATCH] more refactoring - easier guessing path changes --- .../projects/import_export/import_service.rb | 12 ++++++++---- lib/gitlab/import_export/command_line_util.rb | 4 ++-- lib/gitlab/import_export/importer.rb | 8 ++++---- lib/gitlab/import_export/project_tree_restorer.rb | 2 +- lib/gitlab/import_export/repo_restorer.rb | 4 ++-- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/services/projects/import_export/import_service.rb b/app/services/projects/import_export/import_service.rb index b252692cd77..20eda2f228d 100644 --- a/app/services/projects/import_export/import_service.rb +++ b/app/services/projects/import_export/import_service.rb @@ -2,8 +2,8 @@ module Projects module ImportExport class ExportService < BaseService def execute(options = {}) - - @import_path = options[:import_path] + archive_file = options[:archive_file] + Gitlab::ImportExport::Importer.import(archive_file: archive_file, storage_path: storage_path) restore_project_tree restore_repo(project_tree.project) end @@ -15,11 +15,15 @@ module Projects end def project_tree - @project_tree ||= Gitlab::ImportExport::ProjectTreeRestorer.new(path: @import_path, user: @current_user) + @project_tree ||= Gitlab::ImportExport::ProjectTreeRestorer.new(path: storage_path, user: @current_user) end def restore_repo(project) - Gitlab::ImportExport::RepoRestorer.new(path: @import_path, project: project).restore + Gitlab::ImportExport::RepoRestorer.new(path: storage_path, project: project).restore + end + + def storage_path + @storage_path ||= Gitlab::ImportExport.export_path(relative_path: project.path_with_namespace) end end end diff --git a/lib/gitlab/import_export/command_line_util.rb b/lib/gitlab/import_export/command_line_util.rb index f9041e9f4e5..3665e2edb7d 100644 --- a/lib/gitlab/import_export/command_line_util.rb +++ b/lib/gitlab/import_export/command_line_util.rb @@ -24,13 +24,13 @@ module Gitlab end def tar_with_options(archive:, dir:, options:) - cmd = %W(tar -#{options} #{archive} -C #{dir} .) + 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} -C #{dir}) _output, status = Gitlab::Popen.popen(cmd) status.zero? end diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb index 79f54000bb0..9f399845437 100644 --- a/lib/gitlab/import_export/importer.rb +++ b/lib/gitlab/import_export/importer.rb @@ -7,19 +7,19 @@ module Gitlab new(*args).import end - def initialize(archive_file:, storage_path:) + def initialize(archive_file: , storage_path:) @archive_file = archive_file @storage_path = storage_path end def import - decompress_export + decompress_archive end private - def decompress - untar_czf(archive: archive_file, dir: @storage_path) + def decompress_archive + untar_czf(archive: @archive_file, dir: @storage_path) end end end diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb index 4c0f6a2267b..4e0f555afe9 100644 --- a/lib/gitlab/import_export/project_tree_restorer.rb +++ b/lib/gitlab/import_export/project_tree_restorer.rb @@ -4,7 +4,7 @@ module Gitlab attr_reader :project def initialize(path:, user:) - @path = path + @path = File.join(path, 'project.json') @user = user end diff --git a/lib/gitlab/import_export/repo_restorer.rb b/lib/gitlab/import_export/repo_restorer.rb index 42126cabd97..47be303e22a 100644 --- a/lib/gitlab/import_export/repo_restorer.rb +++ b/lib/gitlab/import_export/repo_restorer.rb @@ -3,9 +3,9 @@ module Gitlab class RepoRestorer include Gitlab::ImportExport::CommandLineUtil - def initialize(project: , path: ) + def initialize(project: , path:, bundler_file: ) @project = project - @path = path + @path = File.join(path, bundler_file) end def restore