chiark / gitweb /
mason/.perl-libs/TrivGal.pm (clean_temp_files: Rewrite without `autodie'.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 24 Dec 2024 13:09:16 +0000 (13:09 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 24 Dec 2024 13:09:16 +0000 (13:09 +0000)
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.

mason/.perl-lib/TrivGal.pm

index 2bd64edcd9ff0c83adcced28d54aad0976e47fd2..0b70d4ce16d34b81c03a2ef04b4f151be4cd44bb 100644 (file)
@@ -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;