mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
ensure that zip tmpfile gets deleted on error
This commit is contained in:
parent
ce21e9a519
commit
29d65b4d16
1 changed files with 13 additions and 8 deletions
|
@ -780,17 +780,22 @@ class Site < Sequel::Model
|
||||||
tmpfile = Tempfile.new 'neocities-site-zip'
|
tmpfile = Tempfile.new 'neocities-site-zip'
|
||||||
tmpfile.close
|
tmpfile.close
|
||||||
|
|
||||||
Zip::Archive.open(tmpfile.path, Zip::CREATE) do |ar|
|
begin
|
||||||
ar.add_dir(zip_name)
|
Zip::Archive.open(tmpfile.path, Zip::CREATE) do |ar|
|
||||||
|
ar.add_dir(zip_name)
|
||||||
|
|
||||||
Dir.glob("#{base_files_path}/**/*").each do |path|
|
Dir.glob("#{base_files_path}/**/*").each do |path|
|
||||||
relative_path = path.gsub(base_files_path+'/', '')
|
relative_path = path.gsub(base_files_path+'/', '')
|
||||||
if File.directory?(path)
|
if File.directory?(path)
|
||||||
ar.add_dir(zip_name+'/'+relative_path)
|
ar.add_dir(zip_name+'/'+relative_path)
|
||||||
else
|
else
|
||||||
ar.add_file(zip_name+'/'+relative_path, path) # add_file(<entry name>, <source path>)
|
ar.add_file(zip_name+'/'+relative_path, path) # add_file(<entry name>, <source path>)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
tmpfile.unlink
|
||||||
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
tmpfile.path
|
tmpfile.path
|
||||||
|
|
Loading…
Add table
Reference in a new issue