Skip to content

Commit

Permalink
bugfix: could not fetch files from subdir of subdirs, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Jan 15, 2010
1 parent 120dc4f commit 52aa901
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -9,6 +9,7 @@ requires 'HTML::LinkExtor';
requires 'LWP::Simple';
requires 'Scope::Guard';

test_requires 'File::Slurp';
test_requires 'Test::More' => 0.88;

install_script 'nopan';
Expand Down
10 changes: 6 additions & 4 deletions lib/App/NoPAN.pm
Expand Up @@ -69,15 +69,15 @@ sub fetch_all {
$self->fetch_all(
$base_url,
$dir,
$f,
[ $self->files_from_dir("$base_url$f") ],
"$subdir$f",
[ $self->files_from_dir("$base_url$subdir$f") ],
$fetched,
);
} elsif (! $fetched->{"$subdir$f"}) {
print "$subdir$f\n";
my $r = LWP::Simple::mirror("$base_url$subdir$f", "$dir/$subdir$f");
die "failed to fetch URL:$base_url$subdir$f, got $r"
unless $r == 200;
unless $r == 200; # || $r == 304;
$fetched->{"$subdir$f"} = 1;
}
}
Expand All @@ -88,7 +88,9 @@ sub files_from_dir {

my $body = LWP::Simple::get($url)
or die "failed to fetch URL:$url";
return map {
return grep {
$_ !~ m{^(\.{1,2}|)$},
} map {
$_ =~ /^$url/ ? ($') : ()
} map {
my ($tag, %attr) = @$_;
Expand Down
16 changes: 16 additions & 0 deletions t/00base.t
@@ -1,8 +1,24 @@
use strict;
use warnings;

use Cwd;
use File::Basename qw(basename);
use File::Slurp qw(read_file);
use File::Temp qw(tempdir);
use Test::More;

use_ok('App::NoPAN');

my $nopan = App::NoPAN->new();

my $url = "file://@{[getcwd]}/t/assets/rget/";

my @root_files = sort $nopan->files_from_dir($url);
is_deeply \@root_files, [ qw(a/ zzz.txt) ], 'files_from_dir';

my $tempdir = tempdir(CLEANUP => 1);
$nopan->fetch_all($url, $tempdir, '', \@root_files);
is read_file("t/assets/rget/$_"), read_file("$tempdir/$_"), "compare $_"
for qw(zzz.txt a/b/hello.txt);

done_testing;

0 comments on commit 52aa901

Please sign in to comment.