diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-07-19 15:32:56 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-08-07 14:31:45 +0200 |
commit | aae947cb1c1252a642e0464c61132ec2e965eb80 (patch) | |
tree | 6ea056b09a118f5be2aa4cbfe60abd9879472f79 | |
parent | 7c5757ad9a416c9947bb0e9fae9065af47da8a0d (diff) | |
download | gitlab-ce-aae947cb1c1252a642e0464c61132ec2e965eb80.tar.gz |
Fixes race condition in project uploads
Originally picked as: 3fc0dbcbebcd470fe14f8b5fb7ad55dc3912402e. But
given the internals changed, this was changed now. The changelog was
removed too.
-rw-r--r-- | app/services/projects/gitlab_projects_import_service.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/import_export.rb | 4 | ||||
-rw-r--r-- | spec/features/projects/import_export/import_file_spec.rb | 1 |
3 files changed, 7 insertions, 5 deletions
diff --git a/app/services/projects/gitlab_projects_import_service.rb b/app/services/projects/gitlab_projects_import_service.rb index 5ba1b6436f4..4ca6414b73b 100644 --- a/app/services/projects/gitlab_projects_import_service.rb +++ b/app/services/projects/gitlab_projects_import_service.rb @@ -22,8 +22,11 @@ module Projects private def import_upload_path - @import_upload_path ||= Gitlab::ImportExport - .import_upload_path(filename: "#{params[:namespace_id]}-#{params[:path]}") + @import_upload_path ||= Gitlab::ImportExport.import_upload_path(filename: tmp_filename) + end + + def tmp_filename + "#{SecureRandom.hex}_#{params[:path]}" end def file diff --git a/lib/gitlab/import_export.rb b/lib/gitlab/import_export.rb index 30b536383f9..3470a09eaf0 100644 --- a/lib/gitlab/import_export.rb +++ b/lib/gitlab/import_export.rb @@ -15,9 +15,7 @@ module Gitlab end def import_upload_path(filename:) - milliseconds = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond) - - File.join(storage_path, 'uploads', "#{milliseconds}-#{filename}") + File.join(storage_path, 'uploads', filename) end def project_filename diff --git a/spec/features/projects/import_export/import_file_spec.rb b/spec/features/projects/import_export/import_file_spec.rb index c0cfb9eafe2..9b4235d9186 100644 --- a/spec/features/projects/import_export/import_file_spec.rb +++ b/spec/features/projects/import_export/import_file_spec.rb @@ -31,6 +31,7 @@ feature 'Import/Export - project import integration test', js: true do expect(page).to have_content('GitLab project export') expect(URI.parse(current_url).query).to eq("namespace_id=#{namespace.id}&path=test-project-path") + expect(Gitlab::ImportExport).to receive(:import_upload_path).with(filename: /\A[0-9a-f]{32}_test_project_export\.tar\.gz\z/).and_call_original attach_file('file', file) |