Archive-BagIt-Fast

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

t/src/src_bag/tagmanifest-md5.txt
t/src/src_bag_deep/bag-info.txt
t/src/src_bag_deep/bagit.txt
t/src/src_bag_deep/data/3
t/src/src_bag_deep/data/subdir1/1
t/src/src_bag_deep/data/subdir2/subsubdir/2
t/src/src_bag_deep/manifest-md5.txt
t/src/src_bag_deep/tagmanifest-md5.txt
t/src/src_files/1
t/src/src_files/2
t/verify_bag.t
xt/author/critic.t
xt/author/distmeta.t
xt/author/eol.t
xt/author/minimum-version.t
xt/author/mojibake.t
xt/author/no-tabs.t
xt/author/pod-coverage.t
xt/author/pod-linkcheck.t
xt/author/pod-syntax.t
xt/author/portability.t

lib/Archive/BagIt/Fast.pm  view on Meta::CPAN

            if ($filesize < $MMAP_MIN ) {
                return sysread_based_digest($digestobj, $fh, $filesize);
            }
            elsif ( $filesize < 1500000000) {
                return mmap_based_digest($digestobj, $fh, $filesize);
            }
            else {
                $digest = $digestobj->get_hash_string($fh);
            }
            my $finish_time = time();
            $self->{stats}->{files}->{"$filename"}->{verify_time}= ($finish_time - $start_time);
            $self->{stats}->{verify_time} += ($finish_time-$start_time);
            close($fh);
            return $digest;
        };
        return $sub;
    }
);

1;

__END__

t/fast.t  view on Meta::CPAN

my $SRC_BAG   = File::Spec->catdir( @ROOT, 'src_bag' );
my $SRC_FILES = File::Spec->catdir( @ROOT, 'src_files' );
my $DST_BAG   = File::Spec->catdir( @ROOT, 'dst_bag' );

{
    # Still using old interface
    my $bag = $Class->new($SRC_BAG);
    ok( $bag, "Object created" );
    isa_ok( $bag, $Class );

    my $result = $bag->verify_bag;
    ok( $result, "Bag verifies" );
}

{
    note "copying to $DST_BAG";
    if ( -d $DST_BAG ) {
        rmtree($DST_BAG);
    }
    mkdir($DST_BAG);
    copy( $SRC_FILES . "/1",       $DST_BAG );

t/fast.t  view on Meta::CPAN

    my $bag;
    my $warning =
        Test::Warnings::warning { $bag = $Class->make_bag($DST_BAG) };
    like(
        $warning,
        qr/no payload path/,
        'Got expected warning from make_bag()',
    ) or diag 'got unexpected warnings:', explain($warning);
    ok( $bag, "Object created" );
    isa_ok( $bag, $Class );
    my $result = $bag->verify_bag();
    ok( $result, "Bag verifies" );
    rmtree($DST_BAG);
}

{
    note "copying to $DST_BAG";
    if ( -d $DST_BAG ) {
        rmtree($DST_BAG);
    }
    mkdir($DST_BAG);

t/fast.t  view on Meta::CPAN

    like(
        $warning,
        qr/no payload path/,
        'Got expected warning from make_bag()',
    ) or diag 'got unexpected warnings:', explain($warning);
    ok( $bag, "Object created" );
    isa_ok( $bag, $ClassBase );
    $bag = $Class->new($DST_BAG);
    ok( $bag, "Object created" );
    isa_ok( $bag, $Class );
    my $result = $bag->verify_bag;
    ok( $result, "Bag verifies" );
    rmtree($DST_BAG);
}


##
# prepare tempfile
use_ok('Archive::BagIt::Plugin::Algorithm::MD5');
use_ok('Archive::BagIt::Plugin::Algorithm::SHA512');
my $obj2 = new_ok('Archive::BagIt::Fast');

t/verify_bag.t  view on Meta::CPAN

use Test::More tests => 33;
use Test::Exception;
use File::Spec;
use File::Path;
use File::Copy;
use File::Temp qw(tempdir);
use File::Slurp qw( read_file write_file);
use lib '../lib';

## tests
# verify incorrect manifest or tagmanifest-checksums

my @alg = qw( md5 sha512);
my @prefix_manifestfiles = qw(tagmanifest manifest);

sub _prepare_bag {
  my ($bag_dir) = @_;
  mkpath($bag_dir . "/data");
  write_file("$bag_dir/data/payload1.txt", "PAYLOAD1" );
  write_file("$bag_dir/data/payload2.txt", "PAYLOAD2" );
  write_file("$bag_dir/data/payload3.txt", "PAYLOAD3" );

t/verify_bag.t  view on Meta::CPAN

note "fast tests";
my $Class_fast = 'Archive::BagIt::Fast';
use_ok($Class_fast);
foreach my $prefix (@prefix_manifestfiles) {
  foreach my $alg (@alg) {
    # preparation tests
    my $bag_dir = File::Temp::tempdir(CLEANUP => 1);
    _prepare_bag($bag_dir);
    my $bag_ok = Archive::BagIt->make_bag($bag_dir);
    isa_ok($bag_ok, 'Archive::BagIt', "create new valid IE bagit");
    ok($bag_ok->verify_bag(), "check if bag is verified correctly");
    my $bag_ok2 = Archive::BagIt->make_bag("$bag_dir/"); #add slash at end of $bag_dir
    isa_ok($bag_ok2, 'Archive::BagIt', "create new valid IE bagit (with slash)");
    ok($bag_ok2->verify_bag(), "check if bag is verified correctly (with slash)");
    _modify_bag("$bag_dir/$prefix-$alg.txt");
    # real tests
    my $bag_invalid1 = new_ok("Archive::BagIt::Fast" => [ bag_path => $bag_dir ]);
    throws_ok(
      sub {
        $bag_invalid1->verify_bag(
          { return_all_errors => 1 }
        )
      }, qr{bag verify for bagit version '1.0' failed with invalid files}, "check if bag fails verification of broken $prefix-$alg.txt (all errors, fast)");
    my $bag_invalid2 = new_ok("Archive::BagIt::Fast" => [ bag_path => $bag_dir ]);
    throws_ok(
      sub {
        $bag_invalid2->verify_bag()
      }, qr{digest \($alg\) calculated=.*, but expected=}, "check if bag fails verification of broken $prefix-$alg.txt (first error, fast)");
  }
}

1;

xt/author/eol.t  view on Meta::CPAN

    't/src/src_bag/tagmanifest-md5.txt',
    't/src/src_bag_deep/bag-info.txt',
    't/src/src_bag_deep/bagit.txt',
    't/src/src_bag_deep/data/3',
    't/src/src_bag_deep/data/subdir1/1',
    't/src/src_bag_deep/data/subdir2/subsubdir/2',
    't/src/src_bag_deep/manifest-md5.txt',
    't/src/src_bag_deep/tagmanifest-md5.txt',
    't/src/src_files/1',
    't/src/src_files/2',
    't/verify_bag.t'
);

eol_unix_ok($_, { trailing_whitespace => 1 }) foreach @files;
done_testing;

xt/author/no-tabs.t  view on Meta::CPAN

    't/src/src_bag/tagmanifest-md5.txt',
    't/src/src_bag_deep/bag-info.txt',
    't/src/src_bag_deep/bagit.txt',
    't/src/src_bag_deep/data/3',
    't/src/src_bag_deep/data/subdir1/1',
    't/src/src_bag_deep/data/subdir2/subsubdir/2',
    't/src/src_bag_deep/manifest-md5.txt',
    't/src/src_bag_deep/tagmanifest-md5.txt',
    't/src/src_files/1',
    't/src/src_files/2',
    't/verify_bag.t'
);

notabs_ok($_) foreach @files;
done_testing;



( run in 3.403 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )