Skip to content

Commit

Permalink
Use File::Path::Tiny to clean up temp dir
Browse files Browse the repository at this point in the history
This avoids thread-based issues with File::Path
as used by File::Temp.
  • Loading branch information
shawnlaffan committed Aug 17, 2024
1 parent 385e944 commit be57d1f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/Excel/Writer/XLSX/Workbook.pm
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ sub DESTROY {
local ( $@, $!, $^E, $? );

$self->close() if not $self->{_fileclosed};
if (defined $self->{_tempdir_object} && -d $self->{_tempdir_object}) {
use File::Path::Tiny;
# say STDERR $self->{_tempdir_object};
File::Path::Tiny::rm($self->{_tempdir_object}->dirname, 1);
}
delete $self->{_tempdir_object};
}

Expand Down Expand Up @@ -1129,14 +1134,15 @@ sub get_default_url_format {
sub _store_workbook {

my $self = shift;
my $tempdir = File::Temp->newdir( DIR => $self->{_tempdir} );
my $tempdir = File::Temp->newdir(DIR => $self->{_tempdir});

# Store the File::Temp object within $self so that the temporary files
# Store the temp dir object within $self so that the temporary files
# are only removed when the workbook object is destroyed.
# This control over timing is required because the removal
# of File::Temp temporary directories is not thread-safe.
# This control over timing is required because File::Temp uses
# File::Path for directory removal, and it is not thread-safe
# so we need to use a different cleanup approach.
$tempdir->unlink_on_destroy(0);
$self->{_tempdir_object} = $tempdir;

my $packager = Excel::Writer::XLSX::Package::Packager->new();
my $zip = Archive::Zip->new();

Expand Down

0 comments on commit be57d1f

Please sign in to comment.