]> sipb.mit.edu Git - ikiwiki.git/commitdiff
fix bestlink to not return just-deleted pages
authorJoey Hess <joey@gnu.kitenet.net>
Mon, 30 Nov 2009 22:16:44 +0000 (17:16 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Mon, 30 Nov 2009 22:34:29 +0000 (17:34 -0500)
bestlink was looking at whether %links existed for a page in order to tell
if the page exists, but just-deleted pages still have entries in there (for
reasons it may be best not to explore). So bestlink would return
just-deleted pages. Instead, make bestlink use %pagesources.

Also, when finding a deleted page, %pagecase was not cleared of that page.
This, again, made bestlink return just-deleted pages. Now that is cleared.

Fixing bestlink exposed another issue though. The backlink calculation code
uses bestlink. So when a page was deleted, no backlinks to it are found,
and pages that really did backlink to it were not updated, and had broken
links.

To fix that, the code that actually removes deleted pages had to be split
out from find_del_files, so it can run a bit later. It is run just after
backlinks are calculated. This way, backlink calculation still sees the
deleted pages, but everything afterwards does not.

However, it does not address the original bug report that started this
whole thing, [[bugs/bestlink_returns_deleted_pages]]. Because there
bestlink is run in the needsbuild hook. And that happens before backlink
calculation, and so bestlink still returns deleted pages then. Also in the
scan hook.

If bestlink needs to work consistently during those hooks, a more involved
fix will be needed.

IkiWiki.pm
IkiWiki/Render.pm

index 99d5724ebca49593ac1078bb8880d00de510128f..3430c57420df18fc02ea6bca88229534d5b59d15 100644 (file)
@@ -881,7 +881,7 @@ sub bestlink ($$) {
                $l.="/" if length $l;
                $l.=$link;
 
-               if (exists $links{$l}) {
+               if (exists $pagesources{$l}) {
                        return $l;
                }
                elsif (exists $pagecase{lc $l}) {
@@ -891,7 +891,7 @@ sub bestlink ($$) {
 
        if (length $config{userdir}) {
                my $l = "$config{userdir}/".lc($link);
-               if (exists $links{$l}) {
+               if (exists $pagesources{$l}) {
                        return $l;
                }
                elsif (exists $pagecase{lc $l}) {
index ab3a71671455874a0b8032bfd8d09f5b362339aa..dec9293adcf25d6c8531d46e11a6068fa0676b71 100644 (file)
@@ -392,27 +392,39 @@ sub find_del_files ($) {
                                push @internal_del, $pagesources{$page};
                        }
                        else {
-                               debug(sprintf(gettext("removing old page %s"), $page));
                                push @del, $pagesources{$page};
                        }
                        $links{$page}=[];
                        $renderedfiles{$page}=[];
                        $pagemtime{$page}=0;
-                       foreach my $old (@{$oldrenderedfiles{$page}}) {
-                               prune($config{destdir}."/".$old);
-                       }
-                       delete $pagesources{$page};
-                       foreach my $source (keys %destsources) {
-                               if ($destsources{$source} eq $page) {
-                                       delete $destsources{$source};
-                               }
-                       }
                }
        }
 
        return \@del, \@internal_del;
 }
 
+sub remove_del (@) {
+       foreach my $file (@_) {
+               my $page=pagename($file);
+               if (isinternal($page)) {
+                       debug(sprintf(gettext("removing old page %s"), $page));
+               }
+       
+               foreach my $old (@{$oldrenderedfiles{$page}}) {
+                       prune($config{destdir}."/".$old);
+               }
+
+               foreach my $source (keys %destsources) {
+                       if ($destsources{$source} eq $page) {
+                               delete $destsources{$source};
+                       }
+               }
+       
+               delete $pagecase{lc $page};
+               delete $pagesources{$page};
+       }
+}
+
 sub find_changed ($) {
        my $files=shift;
        my @changed;
@@ -633,6 +645,8 @@ sub refresh () {
        }
 
        calculate_links();
+       
+       remove_del(@$del, @$internal_del);
 
        foreach my $file (@$changed) {
                render($file, sprintf(gettext("building %s"), $file));