Cleanup empty directories when expiring tiles
authorTom Hughes <tom@compton.nu>
Wed, 6 May 2015 18:47:23 +0000 (19:47 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 6 May 2015 18:47:23 +0000 (19:47 +0100)
cookbooks/tile/templates/default/cleanup-tiles.erb

index b0a6a74..8278545 100644 (file)
@@ -5,6 +5,7 @@
 use strict;
 use warnings;
 
+use File::Basename;
 use File::Temp qw(tmpnam);
 use Filesys::Df;
 use LockFile::Simple;
@@ -34,6 +35,11 @@ if (df($tiledir)->{per} > 90)
                 my($time,$tile) = split(/ /, $line);
 
                 unlink($tile) || warn "Can't remove $tile: $!";
+
+                for (my $dir = dirname($tile); $dir ne $tiledir; $dir = dirname($dir))
+                {
+                    unlink($dir);
+                }
             }
             else
             {