fix bestlink to not return just-deleted pages

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.
master
Joey Hess 2009-11-30 17:16:44 -05:00
parent cdd9ef8d58
commit f1ddf4bd98
2 changed files with 26 additions and 12 deletions

View 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}) {

View 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));