split two helper functions of of render()

master
Joey Hess 2009-07-20 05:23:16 +02:00
parent 7d56f17891
commit 73ae87a4d4
1 changed files with 22 additions and 13 deletions

View File

@ -246,7 +246,7 @@ sub prune ($) {
} }
} }
sub refresh () { sub srcdir_check () {
# security check, avoid following symlinks in the srcdir path by default # security check, avoid following symlinks in the srcdir path by default
my $test=$config{srcdir}; my $test=$config{srcdir};
while (length $test) { while (length $test) {
@ -258,11 +258,10 @@ sub refresh () {
} }
} }
run_hooks(refresh => sub { shift->() }); }
# find existing pages sub find_src_files () {
my %exists; my (@files, %pages);
my @files;
eval q{use File::Find}; eval q{use File::Find};
error($@) if $@; error($@) if $@;
find({ find({
@ -281,10 +280,10 @@ sub refresh () {
$f=~s/^\Q$config{srcdir}\E\/?//; $f=~s/^\Q$config{srcdir}\E\/?//;
push @files, $f; push @files, $f;
my $pagename = pagename($f); my $pagename = pagename($f);
if ($exists{$pagename}) { if ($pages{$pagename}) {
debug(sprintf(gettext("%s has multiple possible source pages"), $pagename)); debug(sprintf(gettext("%s has multiple possible source pages"), $pagename));
} }
$exists{$pagename}=1; $pages{$pagename}=1;
} }
} }
}, },
@ -310,9 +309,9 @@ sub refresh () {
if (! -l "$config{srcdir}/$f" && if (! -l "$config{srcdir}/$f" &&
! -e _) { ! -e _) {
my $page=pagename($f); my $page=pagename($f);
if (! $exists{$page}) { if (! $pages{$page}) {
push @files, $f; push @files, $f;
$exists{$page}=1; $pages{$page}=1;
} }
} }
} }
@ -321,9 +320,19 @@ sub refresh () {
}, $dir); }, $dir);
}; };
# Returns a list of all source files found, and a hash of
# the corresponding page names.
return \@files, \%pages;
}
sub refresh () {
srcdir_check();
run_hooks(refresh => sub { shift->() });
my ($files, $exists)=find_src_files();
my (%rendered, @add, @del, @internal); my (%rendered, @add, @del, @internal);
# check for added or removed pages # check for added or removed pages
foreach my $file (@files) { foreach my $file (@$files) {
my $page=pagename($file); my $page=pagename($file);
if (exists $pagesources{$page} && $pagesources{$page} ne $file) { if (exists $pagesources{$page} && $pagesources{$page} ne $file) {
# the page has changed its type # the page has changed its type
@ -353,7 +362,7 @@ sub refresh () {
} }
} }
foreach my $page (keys %pagemtime) { foreach my $page (keys %pagemtime) {
if (! $exists{$page}) { if (! $exists->{$page}) {
if (isinternal($page)) { if (isinternal($page)) {
push @internal, $pagesources{$page}; push @internal, $pagesources{$page};
} }
@ -377,7 +386,7 @@ sub refresh () {
# find changed and new files # find changed and new files
my @needsbuild; my @needsbuild;
foreach my $file (@files) { foreach my $file (@$files) {
my $page=pagename($file); my $page=pagename($file);
my ($srcfile, @stat)=srcfile_stat($file); my ($srcfile, @stat)=srcfile_stat($file);
if (! exists $pagemtime{$page} || if (! exists $pagemtime{$page} ||
@ -435,7 +444,7 @@ sub refresh () {
my @changed=(keys %rendered, @del); my @changed=(keys %rendered, @del);
# rebuild dependant pages # rebuild dependant pages
foreach my $f (@files) { foreach my $f (@$files) {
next if $rendered{$f}; next if $rendered{$f};
my $p=pagename($f); my $p=pagename($f);
if (exists $depends{$p}) { if (exists $depends{$p}) {