ensure that zip tmpfile gets deleted on error

This commit is contained in:
Kyle Drake 2017-07-10 09:09:14 -07:00
parent ce21e9a519
commit 29d65b4d16

View file

@ -780,6 +780,7 @@ class Site < Sequel::Model
tmpfile = Tempfile.new 'neocities-site-zip' tmpfile = Tempfile.new 'neocities-site-zip'
tmpfile.close tmpfile.close
begin
Zip::Archive.open(tmpfile.path, Zip::CREATE) do |ar| Zip::Archive.open(tmpfile.path, Zip::CREATE) do |ar|
ar.add_dir(zip_name) ar.add_dir(zip_name)
@ -792,6 +793,10 @@ class Site < Sequel::Model
end end
end end
end end
rescue => e
tmpfile.unlink
raise e
end
tmpfile.path tmpfile.path
end end