Skip to content
Snippets Groups Projects
Commit 4d55bf51 authored by Jacob Vosmaer's avatar Jacob Vosmaer
Browse files

Only create the archive file when it is done

Because GitLab caches repository archive files on disk it is important
to avoid leaving a corrupt archive when a Unicorn worker gets
interrupted. If we do not watch out for this, the next user to download
the same revision as an archive gets the unfinished file from the
interrupted worker.

This change uses a (hopefully atomic) rename to put the archive file
in its expected location.
parent 3ac88e7a
No related branches found
No related tags found
1 merge request!7Only create the archive file when it is done
Loading
Loading
@@ -821,13 +821,14 @@ module Gitlab
# Put files into a prefix directory in the archive
prefix = File.basename(name)
extension = Pathname.new(file_path).extname
temp_file_path = file_path + ".#{Process.pid}"
 
if extension == '.zip'
create_zip_archive(ref_name, file_path, prefix)
create_zip_archive(ref_name, temp_file_path, prefix)
else
# Open the file with the final result
FileUtils.mkdir_p(Pathname.new(file_path).dirname)
archive_file = File.new(file_path, 'wb')
FileUtils.mkdir_p(Pathname.new(temp_file_path).dirname)
archive_file = File.new(temp_file_path, 'wb')
 
# Create a pipe to communicate with the compressor process
pipe_rd, pipe_wr = IO.pipe
Loading
Loading
@@ -852,6 +853,8 @@ module Gitlab
 
Process.waitpid(compress_pid)
end
FileUtils.mv(temp_file_path, file_path)
end
 
# Create a zip file with the contents of the repo
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment