more refactoring - easier guessing path changes

This commit is contained in:
James Lopez 2016-04-22 12:45:20 +02:00
parent 45032bf403
commit 8f973b8f68
5 changed files with 17 additions and 13 deletions

View File

@ -2,8 +2,8 @@ module Projects
module ImportExport module ImportExport
class ExportService < BaseService class ExportService < BaseService
def execute(options = {}) def execute(options = {})
archive_file = options[:archive_file]
@import_path = options[:import_path] Gitlab::ImportExport::Importer.import(archive_file: archive_file, storage_path: storage_path)
restore_project_tree restore_project_tree
restore_repo(project_tree.project) restore_repo(project_tree.project)
end end
@ -15,11 +15,15 @@ module Projects
end end
def project_tree 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 end
def restore_repo(project) 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 end
end end

View File

@ -24,13 +24,13 @@ module Gitlab
end end
def tar_with_options(archive:, dir:, options:) 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) _output, status = Gitlab::Popen.popen(cmd)
status.zero? status.zero?
end end
def untar_with_options(archive:, dir:, options:) 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) _output, status = Gitlab::Popen.popen(cmd)
status.zero? status.zero?
end end

View File

@ -7,19 +7,19 @@ module Gitlab
new(*args).import new(*args).import
end end
def initialize(archive_file:, storage_path:) def initialize(archive_file: , storage_path:)
@archive_file = archive_file @archive_file = archive_file
@storage_path = storage_path @storage_path = storage_path
end end
def import def import
decompress_export decompress_archive
end end
private private
def decompress def decompress_archive
untar_czf(archive: archive_file, dir: @storage_path) untar_czf(archive: @archive_file, dir: @storage_path)
end end
end end
end end

View File

@ -4,7 +4,7 @@ module Gitlab
attr_reader :project attr_reader :project
def initialize(path:, user:) def initialize(path:, user:)
@path = path @path = File.join(path, 'project.json')
@user = user @user = user
end end

View File

@ -3,9 +3,9 @@ module Gitlab
class RepoRestorer class RepoRestorer
include Gitlab::ImportExport::CommandLineUtil include Gitlab::ImportExport::CommandLineUtil
def initialize(project: , path: ) def initialize(project: , path:, bundler_file: )
@project = project @project = project
@path = path @path = File.join(path, bundler_file)
end end
def restore def restore