From 5defbdd76e3a9d3908d77f983e642d771f175cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Sun, 4 Nov 2018 01:33:50 +0100 Subject: [PATCH] Remove temp files after export-all ZIP generation [SCI-2646] --- app/models/team_zip_export.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/team_zip_export.rb b/app/models/team_zip_export.rb index 06e5757b3..2ee99cc58 100644 --- a/app/models/team_zip_export.rb +++ b/app/models/team_zip_export.rb @@ -30,7 +30,10 @@ class TeamZipExport < ZipExport fill_content(dir_to_zip, data, type, options) zip!(dir_to_zip, output_file.path) self.zip_file = File.open(output_file) - generate_notification(user) if save + if save + FileUtils.rm_rf([dir_to_zip, output_file], secure: true) + generate_notification(user) + end end handle_asynchronously :generate_exportable_zip @@ -128,6 +131,9 @@ class TeamZipExport < ZipExport file = FileUtils.touch("#{root}/#{pdf_name}").first File.open(file, 'wb') { |f| f.write(project_report_pdf) } end + + # Change current dir outside tmp_dir, since tmp_dir will be deleted + Dir.chdir(File.join(Rails.root, 'tmp')) end def generate_notification(user)