This repository was archived by the owner on Oct 7, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,9 @@ public function __invoke(ExportableToGoogleSheet $export): void
2222 }
2323
2424 $ writer = app (Writer::class)->export ($ export , Excel::CSV );
25- $ handle = fopen ($ writer ->getLocalPath (), 'r ' );
25+ $ temporaryFilePath = $ writer ->getLocalPath ();
26+
27+ $ handle = fopen ($ temporaryFilePath , 'r ' );
2628
2729 $ sheetName = $ export ->title ();
2830
@@ -42,16 +44,21 @@ public function __invoke(ExportableToGoogleSheet $export): void
4244 values: $ chunk ->values ()->all (),
4345 );
4446 });
45-
46- if (is_resource ($ handle )) {
47- fclose ($ handle );
48- }
4947 } catch (GoogleException $ e ) {
5048 // Clear the complete sheet if (a chunk) fails.
5149 // We don't want to end up with a half-filled sheet.
5250 $ this ->googleSheetService ->clearSheet ($ export ->googleSpreadsheetId (), $ sheetName );
5351
5452 throw $ e ;
53+ } finally {
54+ if (is_resource ($ handle )) {
55+ fclose ($ handle );
56+ }
57+
58+ // Clean up the local file
59+ if (is_file ($ temporaryFilePath ) && file_exists ($ temporaryFilePath )) {
60+ unlink ($ temporaryFilePath );
61+ }
5562 }
5663 }
5764}
You can’t perform that action at this time.
0 commit comments