support new mode: set mtime back 20 years for expirelist.
authorMichael Meier <michael.meier@fau.de>
Mon, 6 Jun 2016 08:31:55 +0000 (10:31 +0200)
committerMichael Meier <michael.meier@fau.de>
Mon, 6 Jun 2016 08:31:55 +0000 (10:31 +0200)
This naturally is intended to be used together with mod_tile which would then try to rerender those old files when they're requested.

scripts/osmtilecleanup.pl

index d539415d6a8e2105038fd566e8565d59a441c5e8..fcbeac58145aa0b4a3009df5049af04f03afd275 100755 (executable)
@@ -13,6 +13,7 @@ $rmemptydirs = 0;
 $action = 0;
 $rrs = '/bin/echo';
 $minage = 0;  # In hours!
+$setbackinterval = 7305 * 86400; # 20 years (including leap years)
 
 # Sort function for candidate list
 sub sortbydateasc {
@@ -173,7 +174,7 @@ sub calcpathfromcomponents($$) {
   return $res[0] . "/" . $res[1] . "/" . $res[2] . "/" . $res[3] . "/" . $res[4];
 }
 
-sub dorerenderexpiredlist() {
+sub dohandleexpiredlist() {
   my $ll;
   %rerenderlist = ();
   while ($ll = <STDIN>) {
@@ -208,30 +209,55 @@ sub dorerenderexpiredlist() {
         #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");
@@ -278,6 +304,8 @@ for ($i = 0; $i < @ARGV; $i++) {
         $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);
@@ -320,8 +348,8 @@ if ($fspath eq '') {
   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 = ();
This page took 0.100475 seconds and 4 git commands to generate.