add paths to plugin files in copyright
[ikiwiki.git] / IkiWiki / Plugin / transient.pm
blob9811aa010e3d31672dd930596082f83d69d7a02c
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::transient;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
9 hook(type => "getsetup", id => "transient", call => \&getsetup);
10 hook(type => "checkconfig", id => "transient", call => \&checkconfig);
11 hook(type => "change", id => "transient", call => \&change);
14 sub getsetup () {
15 return
16 plugin => {
17 # this plugin is safe but only makes sense as a
18 # dependency; similarly, it needs a rebuild but
19 # only if something else does
20 safe => 0,
21 rebuild => 0,
25 our $transientdir;
27 sub checkconfig () {
28 $transientdir = $config{wikistatedir}."/transient";
29 # add_underlay treats relative underlays as relative to the installed
30 # location, not the cwd. That's not what we want here.
31 IkiWiki::add_literal_underlay($transientdir);
34 sub change (@) {
35 foreach my $file (@_) {
36 # If the corresponding file exists in the transient underlay
37 # and isn't actually being used, we can get rid of it.
38 # Assume that the file that just changed has the same extension
39 # as the obsolete transient version: this'll be true for web
40 # edits, and avoids invoking File::Find.
41 my $casualty = "$transientdir/$file";
42 if (srcfile($file) ne $casualty && -e $casualty) {
43 debug(sprintf(gettext("removing transient version of %s"), $file));
44 IkiWiki::prune($casualty);