From 9dad96c871615a7eb3d0c0b66b51c755622f1dc6 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 28 Jan 2011 17:36:20 +0100 Subject: [PATCH] inline: cope with addition/removal of file Since the inline times must be updated during the scan of the inlining (rather than of the inlined) document(s), we must find the inlining pages before the scan phase (specifically, during the needsbuild phase) and mark them as changed too. Additionally, we must also consider if there are pages being removed, and in the affirmative case we must know which ones they are so that they be ignored during the scan phase. --- IkiWiki/Plugin/inline.pm | 55 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index ab4726d4d..2f794a641 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -111,15 +111,63 @@ sub checkconfig () { } } +sub inline_depend ($$$) { + my $page = shift; + my $dep = shift; + my $list = shift; + my $cond = (ref $list eq 'HASH') ? $list->{$page} : $list; + return ($dep & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE)) && $cond; +} + +my %mark_deleted; + sub needsbuild (@) { my $needsbuild=shift; + my $deleted = shift; + my @depfiles = (@$needsbuild, @$deleted); + my %lcnames = map { lc(pagename($_)) => 1 } @depfiles; + + # we need to remember which files are going to be deleted + # so that they can be skipped in the scan phase + %mark_deleted = (); + foreach my $del (@$deleted) { + $mark_deleted{pagename($del)} = 1; + } + foreach my $page (keys %pagestate) { if (exists $pagestate{$page}{inline}) { + # if this is a page that needs building, remove state if (exists $pagesources{$page} && grep { $_ eq $pagesources{$page} } @$needsbuild) { - # remove state, it will be re-added - # if the preprocessor directive is still - # there during the rebuild + delete $pagestate{$page}{inline}; + next; + } + # otherwise, check if the page depends by content or + # presence on any of the pages that need building + my $depends = 0; + if (exists $IkiWiki::depends_simple{$page}) { + while (my ($p, $dep) = each %{$IkiWiki::depends_simple{$page}}) { + $depends = inline_depend($p, $dep, \%lcnames); + last if $depends; + } + } + if (!$depends && exists $IkiWiki::depends{$page}) { + while (my ($spec, $dep) = each %{$IkiWiki::depends{$page}}) { + my $sub = IkiWiki::pagespec_translate($spec); + next unless defined $sub; + foreach my $file (@depfiles) { + my $p = pagename($file); + $depends = inline_depend($p, $dep, + $sub->($p, location => $page) + ); + last if $depends; + } + last if $depends; + } + } + # if it does, mark it as changed and clear its state + if ($depends) { + push @$needsbuild, $pagesources{$page} if $pagesources{$page}; delete $pagestate{$page}{inline}; } } @@ -196,6 +244,7 @@ sub preprocess_inline (@) { my $ctime = $pagestate{$page}{inline}{ctime}; my $mtime = $pagestate{$page}{inline}{mtime}; foreach my $inner (@list) { + next if $mark_deleted{$inner}; $ctime = $pagectime{$inner} if !defined $ctime || $ctime < $pagectime{$inner}; # use the meta plugin information if available if (defined &IkiWiki::Plugin::meta::get_sort_key) { -- 2.32.0.93.g670b81a890