summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/transient.pm
blob: c482b8552f78efbe218b71de14bf21cf97a6cd2c (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::transient;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. sub import {
  7. hook(type => "getsetup", id => "transient", call => \&getsetup);
  8. hook(type => "checkconfig", id => "transient", call => \&checkconfig);
  9. hook(type => "change", id => "transient", call => \&change);
  10. }
  11. sub getsetup () {
  12. return
  13. plugin => {
  14. # this plugin is safe but only makes sense as a
  15. # dependency; similarly, it needs a rebuild but
  16. # only if something else does
  17. safe => 0,
  18. rebuild => 0,
  19. },
  20. }
  21. our $transientdir;
  22. sub checkconfig () {
  23. eval q{use Cwd 'abs_path'};
  24. error($@) if $@;
  25. $transientdir = abs_path($config{wikistatedir})."/transient";
  26. add_underlay($transientdir);
  27. }
  28. sub change (@) {
  29. foreach my $file (@_) {
  30. # If the corresponding file exists in the transient underlay
  31. # and isn't actually being used, we can get rid of it.
  32. # Assume that the file that just changed has the same extension
  33. # as the obsolete transient version: this'll be true for web
  34. # edits, and avoids invoking File::Find.
  35. my $casualty = "$transientdir/$file";
  36. if (srcfile($file) ne $casualty && -e $casualty) {
  37. debug(sprintf(gettext("removing transient version of %s"), $file));
  38. IkiWiki::prune($casualty);
  39. }
  40. }
  41. }
  42. 1;