Data-RecordStore
view release on metacpan or search on metacpan
Adding last modified timestamp to index.
Now have a standard way to do database upgrades, for this
and for Data::ObjectStore. Hopefully this surprises people
the least.
3 directories : source, destination, working
Added Data::RecordStore->detect_version function.
4.06 - updating tests for windows. Windows tests seem to be
failing because chmod is having no effect.
4.05 - allow silos to be opened read only
4.04 - update the convert program to call a module rather than have the logic
just in the program.
4.03 - fix too agressive db format upgrading.
4.02 - Setup upgrade test in temporary directory rather than test directory. (duh)
t/recordstore.t view on Meta::CPAN
);
is( $rs->[Data::RecordStore->MIN_SILO_ID], 10, 'min silo id is 10' );
is( $rs->[Data::RecordStore->MAX_SILO_ID], 31, 'max silo id is 31' );
$silos = $rs->silos;
is( $#$silos - $rs->[Data::RecordStore->MIN_SILO_ID], 31 - 10, '21 silos' );
ok( $rs, 'inited store' );
if( ! $is_root ) {
$dir = tempdir( CLEANUP => 1 );
chmod 0444, $dir;
failnice( sub { Data::RecordStore->open_store(
BASE_PATH => "$dir/cant",
MAX_FILE_SIZE => 2 ** 12,
) },
'permission denied',
'made a directory that it could not' );
$dir = tempdir( CLEANUP => 1 );
my $lockfile = "$dir/LOCK";
open my $out, '>', $lockfile;
print $out '';
close $out;
chmod 0444, $lockfile;
failnice( sub {
Data::RecordStore->open_store( BASE_PATH => $dir ) },
"permission denied",
"was able to init store with unwritable lock file" );
$dir = tempdir( CLEANUP => 1 );
Data::RecordStore->open_store( $dir );
chmod 0000, "$dir/LOCK";
failnice( sub { Data::RecordStore->reopen_store( $dir ) },
'permission denied',
'was able to reopen store with unwritable lock file' );
$dir = tempdir( CLEANUP => 1 );
chmod 0444, "$dir";
failnice( sub { Data::RecordStore->open_store( $dir ) },
'permission denied',
'was not able to open store in unwritable directory' );
$dir = tempdir( CLEANUP => 1 );
open $out, ">", "$dir/VERSION";
print $out "666\n";
close $out;
failnice( sub { Data::RecordStore->open_store( $dir ) },
'Aborting open',
t/recordstore.t view on Meta::CPAN
my $trans_dir = "$dir/transactions";
remove_tree( $trans_dir );
failnice( sub { Data::RecordStore->reopen_store( $dir ) },
'transaction directory not found',
'able to open store without transactions dir' );
$dir = tempdir( CLEANUP => 1 );
$rs = Data::RecordStore->open_store( BASE_PATH => $dir,
MAX_FILE_SIZE => 2 ** 12 );
my $trans_silo_dir = "$dir/transactions";
chmod 0444, $trans_silo_dir;
failnice( sub { $rs->use_transaction },
'permission denied',
'able to use transaction with unwritable stack silo dir' );
}
} #test_init
sub test_locks {
my $use_single = shift;
my $dir = tempdir( CLEANUP => 1 );
t/recordstore.t view on Meta::CPAN
$store->unlock;
$store->lock( "SOMETHING" );
pass( "Store was able to lock after unlocking" );
$store->unlock;
$store->lock( "SOMETHING", "ZOMETHING" );
pass( "Store was able to lock same label after unlocking" );
$store->unlock;
unless( $is_root ) {
chmod 0444, "$dir/user_locks/SOMETHING";
eval {
$store->lock( "SOMETHING" );
fail( "Store was able to lock unwritable lock file" );
};
like( $@, qr/lock failed/, 'lock failed when unwritable' );
undef $@;
chmod 0744, "$dir/user_locks/SOMETHING";
chmod 0444, "$dir/user_locks/ZOMETHING";
eval {
$store->lock( "BUMTHING", "ZOMETHING" );
fail( "Store was able to lock unwritable lock file" );
};
like( $@, qr/lock failed/, 'lock failed when unwritable' );
undef $@;
chmod 0744, "$dir/user_locks/ZOMETHING";
$store->lock( "BUMTHING", "ZOMETHING" );
pass( 'store able to lock with permissions restored' );
$store->unlock;
$dir = tempdir( CLEANUP => 1 );
eval {
$store = Data::RecordStore->open_store( BASE_PATH => $dir );
pass( "Was able to open store" );
chmod 0444, "$dir/user_locks";
$store->lock( "FOO" );
fail( "Data::RecordStore->lock didnt die trying to lock to unwriteable directory" );
};
like( $@, qr/lock failed/, "unable to lock because of unwriteable lock directory" );
$dir = tempdir( CLEANUP => 1 );
eval {
$store = Data::RecordStore->open_store( BASE_PATH => $dir );
open my $out, '>', "$dir/user_locks/BAR";
print $out '';
close $out;
chmod 0444, "$dir/user_locks/BAR";
pass( "Was able to open store" );
$store->lock( "FOO", "BAR", "BAZ" );
fail( "Data::RecordStore->lock didnt die trying to lock unwriteable lock file" );
};
like( $@, qr/lock failed/, "unable to lock because of unwriteable lock file" );
}
} #test_locks
sub test_use {
t/recordstore.t view on Meta::CPAN
is( $rs->fetch( $nextid ), undef, "trans cant see deleted item after commit" );
is( $copy->fetch( $nextid ), undef, "copy sees deleted own stow after commit" );
is( $copy->fetch( $nextid + 1 ), "X" x 10_000, 'big thing saved' );
if( ! $is_root ) {
$dir = tempdir( CLEANUP => 1 );
my $stacks = "$dir/transactions/1";
make_path( $stacks );
chmod 0444, $stacks;
$rs = Data::RecordStore->open_store(
BASE_PATH => $dir,
);
eval {
$rs->use_transaction;
fail( 'was able to use transaction with unwritable dir' );
};
like( $@, qr/permission denied/i, 'err msg for trans with unwrite dir' );
}
$silo = Data::RecordStore::Silo->reopen_silo( $dir );
is( $silo->template, 'LLL', 'given template matches for reopened silo' );
is( $silo->max_file_size, 2_000_000_000, "silo is default max size" );
is( $silo->record_size, 12, "silo has 32 bytes per record" );
is( $silo->records_per_subsilo, 166_666_666, "166,666,666 records per file" );
if( ! $is_root ) {
$dir = tempdir( CLEANUP => 1 );
chmod 0444, $dir;
my $cantdir = "$dir/cant";
failnice( sub { Data::RecordStore::Silo->open_silo( $cantdir, 'LL' ) },
"Permission denied",
'was able to init a silo in an unwritable directory' );
}
$Data::RecordStore::Silo::DEFAULT_MAX_FILE_SIZE = 2_000_000_000;
} #test_init
sub test_use {
my $dir = tempdir( CLEANUP => 1 );
like( $@, qr/out of bounds/, 'error message for wrong index' );
eval {
$silo->put_record( 5, "WRONG".('x'x$size) );
fail( 'was able to put record too big' );
};
like( $@, qr/too large/, 'error message for too big data' );
unless( $is_root ) {
$silo = Data::RecordStore::Silo->open_silo( $dir, 'Z*', $size, $size * 10 );
chmod 0000, "$dir";
eval {
$silo->subsilos;
fail( "Was able to access subsilos despite dark directory" );
};
like( $@, qr/can't open/, 'error msg for dark dir' );
chmod 0777, "$dir";
is_deeply( [$silo->subsilos], [ 0, 1,2,3], "still four subsilos after reopen" );
chmod 0444, "$dir/3";
eval {
$silo->peek;
};
like( $@, qr/Unable to open|Permission denied/, 'error msg for readonly file' );
chmod 0777, "$dir/3";
$silo->put_record(40,'LAST');
is_deeply( $silo->peek, ['LAST'], 'last is last' );
$silo->put_record(1,'FIRST');
is_deeply( $silo->get_record(1), ['FIRST'], 'first is first' );
$silo->put_record(1,'FIR');
is_deeply( $silo->get_record(1), ['FIR'], 'fir is first' );
};
open $fh, '>', "$dir/2";
print $fh '';
close $fh;
eval {
$silo->ensure_entry_count( 40 );
fail( 'able to ensure count with wacky extra subsilos hanging out' );
};
$silo->empty_silo;
chmod 0444, "$dir/0";
eval {
$silo->ensure_entry_count( 3 );
fail( 'able to ensure count with unwriteable fi9rst' );
};
}
$silo->unlink_silo;
eval {
( run in 0.278 second using v1.01-cache-2.11-cpan-496ff517765 )