GC unused pages in the transient underlay
authorSimon McVittie <smcv@debian.org>
Sat, 27 Nov 2010 13:40:11 +0000 (13:40 +0000)
committerSimon McVittie <smcv@debian.org>
Fri, 7 Jan 2011 18:53:27 +0000 (18:53 +0000)
IkiWiki/Plugin/transient.pm

index 5764467ab0092827651f65b0485a96862e82c4ed..2784164f607c2d8210d7a3e88a729ef3f880326c 100644 (file)
@@ -8,6 +8,7 @@ use IkiWiki 3.00;
 sub import {
        hook(type => "getsetup", id => "transient",  call => \&getsetup);
        hook(type => "checkconfig", id => "transient", call => \&checkconfig);
+       hook(type => "change", id => "transient", call => \&change);
 }
 
 sub getsetup () {
@@ -30,4 +31,17 @@ sub checkconfig () {
        add_underlay($transientdir);
 }
 
+sub change (@) {
+       foreach my $file (@_) {
+               # if the corresponding file exists in the transient underlay
+               # and isn't actually being used, we can get rid of it
+               my $page = pagename($file);
+               my $casualty = "$transientdir/$page.$config{default_pageext}";
+               if (srcfile($file) ne $casualty && -e $casualty) {
+                       debug(sprintf(gettext("removing transient version of %s"), $page));
+                       IkiWiki::prune($casualty);
+               }
+       }
+}
+
 1;