$action = 0;
$rrs = '/bin/echo';
$minage = 0; # In hours!
+$setbackinterval = 7305 * 86400; # 20 years (including leap years)
# Sort function for candidate list
sub sortbydateasc {
return $res[0] . "/" . $res[1] . "/" . $res[2] . "/" . $res[3] . "/" . $res[4];
}
-sub dorerenderexpiredlist() {
+sub dohandleexpiredlist() {
my $ll;
%rerenderlist = ();
while ($ll = <STDIN>) {
#print("Checking: $z $x $y - Path: $p\n");
$filesseen++;
if (-e $p) {
- $filesdone++;
- print("Sending rendering request for z=$z x=$x y=$y to regenerate '$p'\n");
- if (system("$rrs $z $x $y")) {
- print("Error executing $rrs $z $x $y\n");
+ if ($action == 3) {
+ $filesdone++;
+ print("Sending rendering request for z=$z x=$x y=$y to regenerate '$p'\n");
+ if (system("$rrs $z $x $y")) {
+ print("Error executing $rrs $z $x $y\n");
+ }
+ } elsif ($action == 4) {
+ my $mtime = (stat($p))[9];
+ my $curtime = time();
+ if (($curtime - $setbackinterval) > $mtime) {
+ # Do not touch again - it's already 20 years back.
+ print("Not touching '$p', it's over 20 years old so probably has already been set back.\n");
+ } else {
+ my $newmtime = $mtime - $setbackinterval;
+ print("Touching '$p' (z=$z x=$x y=$y)\n");
+ if (utime($curtime, $newmtime, $p) < 1) {
+ print("Error touching '$p': $!\n");
+ }
+ }
+ } else {
+ print("Internal error - action variable invalid. This is a programming error.\n");
+ exit(1);
}
}
}
}
}
- print("Sent re-rendering-requests for $filesdone files that actually existed (of $filesseen candidates)\n");
+ if ($action == 3) {
+ print("Sent re-rendering-requests for $filesdone files that actually existed (of $filesseen candidates)\n");
+ } elsif ($action == 4) {
+ print("Touched $filesdone files (of $filesseen candidates)\n");
+ }
}
$fspath = '';
for ($i = 0; $i < @ARGV; $i++) {
$curarg = $ARGV[$i];
if ($curarg eq '--help') {
- print("Syntax: $0 [--help] [--zoom z] [--limit n] [--action a] [--rmemptydirs] [--rrs path] [--minage hrs] directory\n");
+ print("Syntax: $0 [--help] [--zoom z] [--limit n] [--action a] [--rmemptydirs]\n");
+ print(" [--rrs path] [--minage hrs] directory\n");
print(" --zoom z[-z2]: Zoom level(s) to handle (default: 0-20).\n");
print(" --limit n: Limit to the n oldest files (default: no limit)\n");
print(" --action what: what action to perform with the found files.\n");
- print(" valid actions are: print delete rerender rerenderexpiredlist (default: print)\n");
- print(" rerenderexpiredlist: this is very different from all other commands, as it\n");
- print(" expects to read a list of expired tiles to rerender on STDIN. The list has\n");
- print(" to be in the format that osm2pgsql spits out.\n");
+ print(" valid actions are: print delete rerender rerenderexpiredlist\n");
+ print(" touchexpiredlist (default: print)\n");
+ print(" rerenderexpiredlist and touchexpiredlist: these are very different from the\n");
+ print(" other commands, as they expect to read a list of expired tiles to rerender\n");
+ print(" or touch on STDIN. The list has to be in the format that osm2pgsql spits\n");
+ print(" out. touchexpiredlist sets the mtime of the tiles back 20 years.\n");
print(" --rmemptydirs: remove empty subdirectories\n");
print(" --rrs path: if action is rerender, this gives the path to the rerender script.\n");
print(" it gets called with three parameters: z x y\n");
$action = 2;
} elsif ($ARGV[$i] eq 'rerenderexpiredlist') {
$action = 3;
+ } elsif ($ARGV[$i] eq 'touchexpiredlist') {
+ $action = 4;
} else {
print("Error: Invalid action selected.\n");
exit(1);
print("ERROR: No path to clear given.\n");
exit(1);
}
-if ($action == 3) { # This significantly differs from the rest of our operations
- dorerenderexpiredlist();
+if (($action == 3) || ($action == 4)) { # This significantly differs from the rest of our operations
+ dohandleexpiredlist();
exit(0);
}
@allentries = ();