aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Riebenbauer <davrieb@liegesta.at>2010-01-30 18:12:01 +0100
committerDavid Riebenbauer <davrieb@liegesta.at>2010-02-02 14:04:28 +0100
commitf3abeac919c4736429bd3362af6edf51ede8e7fe (patch)
treedbb15b4d2cd3fee919b019ad1037edc0d62f57e6
parent4af4d26582f0c2b915d7102fb4a604b176385748 (diff)
downloadikiwiki-f3abeac919c4736429bd3362af6edf51ede8e7fe.tar
ikiwiki-f3abeac919c4736429bd3362af6edf51ede8e7fe.tar.gz
Code deduplication fin find_src_files()
This also has the advantage that I can use the resulting new function elsewhere.
-rw-r--r--IkiWiki/Render.pm59
1 files changed, 27 insertions, 32 deletions
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;