diff options
author | Matthew Lemon <y@yulqen.org> | 2024-12-13 13:00:40 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-12-13 13:00:40 +0000 |
commit | 936fdfce2c3306479b515e038e5352b1c941dad2 (patch) | |
tree | 3b6e64e6ef52d0eaf8327fd701395e37f2f11e14 | |
parent | 462ba9835e36ca3b42ceb59f33c03a98a22c19af (diff) |
Adds guard before deleting temp files
-rw-r--r-- | app/services/pdf_processor_service.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/services/pdf_processor_service.rb b/app/services/pdf_processor_service.rb index dd3718a..70133b4 100644 --- a/app/services/pdf_processor_service.rb +++ b/app/services/pdf_processor_service.rb @@ -56,10 +56,11 @@ class PdfProcessorService end def process_page(pdf_path, page_index) - temp_files = create_page_images(pdf_path, page_index) - attach_processed_image(temp_files[:reduced], page_index) + temp_files = nil + temp_files = create_page_images(pdf_path, page_index) # Generate temp files + attach_processed_image(temp_files[:reduced], page_index) # Attach image ensure - cleanup_temp_files(temp_files) + cleanup_temp_files(temp_files) # Cleanup, even if an error occurs end def create_page_images(pdf_path, index) @@ -119,8 +120,9 @@ class PdfProcessorService end def cleanup_temp_files(temp_files) + return if temp_files.nil? # Safeguard in case temp_files is nil temp_files.values.each do |path| - File.delete(path) if File.exist?(path) + File.delete(path) if File.exist?(path) # Safely delete files end end -end
\ No newline at end of file +end
\ No newline at end of file |