From c45d2eb055b006b20ae280d34aee8f871b79d456 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 9 Aug 2005 17:06:40 +0000 Subject: [PATCH] Automatically clean up old output files etc. after N days (configurable). --- config.pm | 3 +++ last.pl | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/config.pm b/config.pm index e8bde1a..c268b34 100644 --- 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 days old a file must be to be deleted in routine cleanups. +our $minimum_age = 3; + 1; diff --git a/last.pl b/last.pl index 99ee2f5..6024739 100755 --- 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; } +# 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 :-) -- 2.39.2