summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/transient.pm
blob: 9811aa010e3d31672dd930596082f83d69d7a02c (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. $transientdir = $config{wikistatedir}."/transient";
  24. # add_underlay treats relative underlays as relative to the installed
  25. # location, not the cwd. That's not what we want here.
  26. IkiWiki::add_literal_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;