summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-04-15 18:14:28 +0200
committerJames Lopez <james@jameslopez.es>2016-04-15 18:14:28 +0200
commitae777ea0618e8db8a552a831dc331fe7a7b1fe7a (patch)
tree0e28d0fac0db940e7fca23518e1764cb34e44f3e
parent97c3aff16fa94cee622cd00ffaa2e3a6469c1439 (diff)
downloadgitlab-ce-ae777ea0618e8db8a552a831dc331fe7a7b1fe7a.tar.gz
WIP - importing file and repo
-rw-r--r--app/services/projects/import_export/import_service.rb11
-rw-r--r--lib/gitlab/import_export/command_line_util.rb14
-rw-r--r--lib/gitlab/import_export/importer.rb26
-rw-r--r--lib/gitlab/import_export/repo_restorer.rb31
4 files changed, 80 insertions, 2 deletions
diff --git a/app/services/projects/import_export/import_service.rb b/app/services/projects/import_export/import_service.rb
index d188b2dc83b..b252692cd77 100644
--- a/app/services/projects/import_export/import_service.rb
+++ b/app/services/projects/import_export/import_service.rb
@@ -2,17 +2,24 @@ module Projects
module ImportExport
class ExportService < BaseService
def execute(options = {})
+
@import_path = options[:import_path]
+ restore_project_tree
+ restore_repo(project_tree.project)
end
private
def restore_project_tree
- Gitlab::ImportExport::ProjectTreeRestorer.new(path: @import_path).restore
+ project_tree.restore
end
- def restore_repo
+ def project_tree
+ @project_tree ||= Gitlab::ImportExport::ProjectTreeRestorer.new(path: @import_path, user: @current_user)
+ end
+ def restore_repo(project)
+ Gitlab::ImportExport::RepoRestorer.new(path: @import_path, project: project).restore
end
end
end
diff --git a/lib/gitlab/import_export/command_line_util.rb b/lib/gitlab/import_export/command_line_util.rb
index 7bf4b476b6c..f9041e9f4e5 100644
--- a/lib/gitlab/import_export/command_line_util.rb
+++ b/lib/gitlab/import_export/command_line_util.rb
@@ -5,6 +5,14 @@ module Gitlab
tar_with_options(archive: archive, dir: dir, options: 'cf')
end
+ def untar_czf(archive:, dir:)
+ untar_with_options(archive: archive, dir: dir, options: 'czf')
+ end
+
+ def untar_cf(archive:, dir:)
+ untar_with_options(archive: archive, dir: dir, options: 'cf')
+ end
+
def tar_czf(archive:, dir:)
tar_with_options(archive: archive, dir: dir, options: 'czf')
end
@@ -20,6 +28,12 @@ module Gitlab
_output, status = Gitlab::Popen.popen(cmd)
status.zero?
end
+
+ def untar_with_options(archive:, dir:, options:)
+ cmd = %W(tar -#{options} #{archive)} -C #{dir})
+ _output, status = Gitlab::Popen.popen(cmd)
+ status.zero?
+ end
end
end
end
diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb
new file mode 100644
index 00000000000..79f54000bb0
--- /dev/null
+++ b/lib/gitlab/import_export/importer.rb
@@ -0,0 +1,26 @@
+module Gitlab
+ module ImportExport
+ class Importer
+ include Gitlab::ImportExport::CommandLineUtil
+
+ def self.import(*args)
+ new(*args).import
+ end
+
+ def initialize(archive_file:, storage_path:)
+ @archive_file = archive_file
+ @storage_path = storage_path
+ end
+
+ def import
+ decompress_export
+ end
+
+ private
+
+ def decompress
+ untar_czf(archive: archive_file, dir: @storage_path)
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/import_export/repo_restorer.rb b/lib/gitlab/import_export/repo_restorer.rb
new file mode 100644
index 00000000000..42126cabd97
--- /dev/null
+++ b/lib/gitlab/import_export/repo_restorer.rb
@@ -0,0 +1,31 @@
+module Gitlab
+ module ImportExport
+ class RepoRestorer
+ include Gitlab::ImportExport::CommandLineUtil
+
+ def initialize(project: , path: )
+ @project = project
+ @path = path
+ end
+
+ def restore
+ return false unless File.exists?(@path)
+ # Move repos dir to 'repositories.old' dir
+
+ FileUtils.mkdir_p(repos_path)
+ FileUtils.mkdir_p(path_to_repo)
+ untar_cf(archive: @path, dir: path_to_repo)
+ end
+
+ private
+
+ def repos_path
+ Gitlab.config.gitlab_shell.repos_path
+ end
+
+ def path_to_repo
+ @project.repository.path_to_repo
+ end
+ end
+ end
+end