From: Mark Wooding Date: Tue, 24 Dec 2024 13:09:16 +0000 (+0000) Subject: mason/.perl-libs/TrivGal.pm (clean_temp_files: Rewrite without `autodie'. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/tgal/commitdiff_plain/719873691f9c7e265036a65cd14a05aab8d2f4a7 mason/.perl-libs/TrivGal.pm (clean_temp_files: Rewrite without `autodie'. The `kill' call here would fail with `autodie', and, because the module invokes `clean_temp_files' at load time, this causes it to be marked as broken and all later loads will also fail. Rewrite the function with `autodie' switched off and check for errors by hand. --- diff --git a/mason/.perl-lib/TrivGal.pm b/mason/.perl-lib/TrivGal.pm index 2bd64ed..0b70d4c 100644 --- a/mason/.perl-lib/TrivGal.pm +++ b/mason/.perl-lib/TrivGal.pm @@ -154,12 +154,12 @@ sub init () { export qw{clean_temp_files}; sub clean_temp_files () { + no autodie qw{kill opendir unlink}; my $d; - eval { opendir $d, $TMP; }; - if ($@) { - if ($@->isa("autodie::exception") && $@->errno == ENOENT) { return; } - else { die $@; } + unless (opendir $d, $TMP) { + if ($! == ENOENT) { return } + else { die "failed to read temporary directory `$TMP': $!"; } } my $now = time; FILE: while (my $name = readdir $d) { @@ -167,9 +167,16 @@ sub clean_temp_files () { my $pid = $1; next FILE if kill 0, $pid; my $f = "$TMP/$name"; - my $st = stat $name; + my $st = stat $f; + if (!defined $st) { + if ($! == ENOENT) { next FILE; } + else { die "failed to read file metadata for `$f': $!"; } + } next FILE if $now - $st->mtime() < 300; - unlink $f; + unless (unlink $f) { + if ($! == ENOENT) { next FILE; } + else { die "failed to delete file `$f': $!"; } + } } closedir $d; } @@ -405,6 +412,4 @@ sub find_covering_file ($$$) { ###----- That's all, folks -------------------------------------------------- -clean_temp_files; - 1;