From: David Riebenbauer Date: Sat, 30 Jan 2010 17:12:01 +0000 (+0100) Subject: Code deduplication fin find_src_files() X-Git-Tag: 3.20100427~62^2~28^2~12 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/f3abeac919c4736429bd3362af6edf51ede8e7fe Code deduplication fin find_src_files() This also has the advantage that I can use the resulting new function elsewhere. --- diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 3ebb1a324..44b2fb9c2 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -280,6 +280,27 @@ sub srcdir_check () { } +sub verify_src_file ($$) { + my $file=decode_utf8(shift); + my $dir=shift; + + return if -l $file || -d $file; + $file=~s/^\Q$dir\E\/?//; + return if ! length $file; + my $page = pagename($file); + if (! exists $pagesources{$page} && + file_pruned($file)) { + $File::Find::prune=1; + return; + } + + my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint + if (! defined $f) { + warn(sprintf(gettext("skipping bad filename %s"), $file)."\n"); + } + return ($file,$page,$f); +} + sub find_src_files () { my @files; my %pages; @@ -288,22 +309,9 @@ sub find_src_files () { find({ no_chdir => 1, wanted => sub { - my $file=decode_utf8($_); - $file=~s/^\Q$config{srcdir}\E\/?//; - return if -l $_ || -d _ || ! length $file; - my $page = pagename($file); - if (! exists $pagesources{$page} && - file_pruned($file)) { - $File::Find::prune=1; - return; - } - - my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint - if (! defined $f) { - warn(sprintf(gettext("skipping bad filename %s"), $file)."\n"); - } - else { - push @files, $f; + my ($file,$page,$f) = verify_src_file($_,$config{srcdir}); + if ($file) { + push @files, $file; if ($pages{$page}) { debug(sprintf(gettext("%s has multiple possible source pages"), $page)); } @@ -315,24 +323,11 @@ sub find_src_files () { find({ no_chdir => 1, wanted => sub { - my $file=decode_utf8($_); - $file=~s/^\Q$dir\E\/?//; - return if -l $_ || -d _ || ! length $file; - my $page=pagename($file); - if (! exists $pagesources{$page} && - file_pruned($file)) { - $File::Find::prune=1; - return; - } - - my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint - if (! defined $f) { - warn(sprintf(gettext("skipping bad filename %s"), $file)."\n"); - } - else { + my ($file,$page,$f) = verify_src_file($_,$dir); + if ($f) { # avoid underlaydir override # attacks; see security.mdwn - if (! -l "$config{srcdir}/$f" && + if (! -l "$config{srcdir}/$f" && ! -e _) { if (! $pages{$page}) { push @files, $f;