-my $real_num_last = scalar @thumbnails;
-if ($real_num_last > $num_last) {
- $real_num_last = $num_last;
+my $real_show_last = scalar @thumbnails;
+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;
+ }