]> git.sesse.net Git - webpdf/commitdiff
Automatically clean up old output files etc. after N days (configurable).
authorSteinar H. Gunderson <sesse@samfundet.no>
Tue, 9 Aug 2005 17:06:40 +0000 (17:06 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Tue, 9 Aug 2005 17:06:40 +0000 (17:06 +0000)
config.pm
last.pl

index e8bde1a55afb5d3e3319d5dd9faaa11b2d0e78b3..c268b349a7b309fbe6d8a8384979685c3bee68a2 100644 (file)
--- a/config.pm
+++ b/config.pm
@@ -13,4 +13,7 @@ our $outputdir = "/home/cassarossa/itk/sesse/public_html/pdf/output";
 # How many thumbnails to show in the “last uploaded” page.
 our $show_last = 20;
 
 # How many thumbnails to show in the “last uploaded” page.
 our $show_last = 20;
 
+# How many days old a file must be to be deleted in routine cleanups.
+our $minimum_age = 3;
+
 1;
 1;
diff --git a/last.pl b/last.pl
index 99ee2f5ac082cec37afc8165e99f241e93063d59..602473901f71f49dfa106ddbef2c63eada94a441 100755 (executable)
--- a/last.pl
+++ b/last.pl
@@ -14,6 +14,18 @@ if ($real_show_last > $pdfweb::config::show_last) {
        $real_show_last = $pdfweb::config::show_last;
 }
 
        $real_show_last = $pdfweb::config::show_last;
 }
 
+# This is probably the simplest place to clean up files that we no longer
+# need having around.
+for my $t (@thumbnails[$pdfweb::config::show_last..$#thumbnails]) {
+       if (-M $t > $pdfweb::config::minimum_age) {
+               (my $base = $t) =~ s/\.png$//;
+               my @to_delete = <$base*>;
+
+               warn "Deleting " . join(', ', @to_delete);
+               unlink @to_delete;
+       }
+}
+
 # Sorry, no HTML templating. I didn't want to pull in yet another
 # dependency :-)
 
 # Sorry, no HTML templating. I didn't want to pull in yet another
 # dependency :-)