summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-06-24 10:22:44 +0000
committerRobert Speicher <rspeicher@gmail.com>2016-06-24 11:31:41 -0400
commitac7cea308467709413f7a67b9e95fd0a0e2dcafe (patch)
tree808d51109ed3142c6fd99b523b4fb85098b78643
parent12af7464cf94dcb4d1983f1b32934e67567e2940 (diff)
downloadgitlab-ce-ac7cea308467709413f7a67b9e95fd0a0e2dcafe.tar.gz
Merge branch 'fix/gitlab-import-project-file-fix' into 'master'
Fix temp file being deleted after the request while importing a GitLab project Fixes https://gitlab.com/gitlab-com/infrastructure/issues/151 In production, the temporary uploaded file is getting deleted straight after the request so the Sidekiq worker is unable to find it in `/tmp` Also, improved erroring/logging of this situation. See merge request !4894
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/import/gitlab_projects_controller.rb6
-rw-r--r--lib/gitlab/import_export/file_importer.rb6
-rw-r--r--lib/gitlab/import_export/importer.rb15
4 files changed, 23 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 14cc4b4329a..02c1e191b8b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -34,6 +34,7 @@ v 8.9.1 (unreleased)
- Remove width restriction for logo on sign-in page. !4888
- Bump gitlab_git to 10.2.3 to fix false truncated warnings with ISO-8559 files. !4884
- Apply selected value as label. !4886
+ - Fix temp file being deleted after the request while importing a GitLab project. !4894
v 8.9.0
- Fix builds API response not including commit data
diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb
index f99aa490d3e..513348c39af 100644
--- a/app/controllers/import/gitlab_projects_controller.rb
+++ b/app/controllers/import/gitlab_projects_controller.rb
@@ -12,9 +12,13 @@ class Import::GitlabProjectsController < Import::BaseController
return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." })
end
+ imported_file = project_params[:file].path + "-import"
+
+ FileUtils.copy_entry(project_params[:file].path, imported_file)
+
@project = Gitlab::ImportExport::ProjectCreator.new(project_params[:namespace_id],
current_user,
- File.expand_path(project_params[:file].path),
+ File.expand_path(imported_file),
project_params[:path]).execute
if @project.saved?
diff --git a/lib/gitlab/import_export/file_importer.rb b/lib/gitlab/import_export/file_importer.rb
index 0e70d9282d5..82d1e1805c5 100644
--- a/lib/gitlab/import_export/file_importer.rb
+++ b/lib/gitlab/import_export/file_importer.rb
@@ -23,7 +23,11 @@ module Gitlab
private
def decompress_archive
- untar_zxf(archive: @archive_file, dir: @shared.export_path)
+ result = untar_zxf(archive: @archive_file, dir: @shared.export_path)
+
+ raise Projects::ImportService::Error.new("Unable to decompress #{@archive_file} into #{@shared.export_path}") unless result
+
+ true
end
end
end
diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb
index d209e04f7be..595b20a09bd 100644
--- a/lib/gitlab/import_export/importer.rb
+++ b/lib/gitlab/import_export/importer.rb
@@ -10,17 +10,22 @@ module Gitlab
end
def execute
- Gitlab::ImportExport::FileImporter.import(archive_file: @archive_file,
- shared: @shared)
- if check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore)
+ if import_file && check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore)
project_tree.restored_project
else
raise Projects::ImportService::Error.new(@shared.errors.join(', '))
end
+
+ remove_import_file
end
private
+ def import_file
+ Gitlab::ImportExport::FileImporter.import(archive_file: @archive_file,
+ shared: @shared)
+ end
+
def check_version!
Gitlab::ImportExport::VersionChecker.check!(shared: @shared)
end
@@ -59,6 +64,10 @@ module Gitlab
def wiki_repo_path
File.join(@shared.export_path, 'project.wiki.bundle')
end
+
+ def remove_import_file
+ FileUtils.rm_rf(@archive_file)
+ end
end
end
end