IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24440


Ignore:
Timestamp:
Jun 16, 2009, 2:33:25 PM (17 years ago)
Author:
jhoblitt
Message:

add neb-rm --force flag

Location:
trunk/Nebulous
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/Changes

    r24346 r24440  
    44    - add chmod() API
    55    - change neb-ls to always output in --long format
     6    - add neb-rm --force flag
    67
    780.10
  • trunk/Nebulous/bin/neb-rm

    r24264 r24440  
    1616use Pod::Usage qw( pod2usage );
    1717
    18 my ($server, $move);
     18my (
     19    $force,
     20    $move,
     21    $server,
     22);
    1923
    2024$server = $ENV{'NEB_SERVER'} unless $server;
    2125
    2226GetOptions(
     27    'force|f'       => \$force,
     28    'move|m'        => \$move,
    2329    'server|s=s'    => \$server,
    24     'move|m'        => \$move,
    2530) || pod2usage( 2 );
    2631
     
    6368
    6469=over 4
     70
     71=item * --force|-f
     72
     73When set, C<<key>> will be removed from the nebulous database even if the on
     74disk file(s) are missing.
     75
     76Optional.
    6577
    6678=item * --move|-m
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r24281 r24440  
    1616use Nebulous::Client::Log;
    1717use Nebulous::Util qw( :standard );
    18 use Params::Validate qw( validate validate_pos SCALAR UNDEF );
     18use Params::Validate qw( validate validate_pos SCALAR UNDEF BOOLEAN );
    1919#use SOAP::Lite +trace => [qw( debug )];
    2020use SOAP::Lite;
     
    329329    my $uri = $self->delete_instance($key, @$locations[0]);
    330330
     331    eval {
     332        _nuke_file(_get_file_path(@$locations[0]));
     333    };
     334    if ($@) {
     335        $log->logdie($@);
     336    }
     337
    331338    $log->debug("leaving");
    332339
     
    803810    my $self = shift;
    804811
    805     my ( $key ) = validate_pos( @_,
    806         {
    807             type => SCALAR,
     812    my ($key, $force) = validate_pos( @_,
     813        {
     814            type        => SCALAR,
     815        },
     816        {
     817            type        => BOOLEAN,
     818            optional    => 1,
     819            default     => undef,
     820            callbacks   => {
     821                'is boolean' => sub {
     822                    $_[0] == 0 or $_[0] == 1 or $_[0] == undef;
     823                },
     824            },
    808825        },
    809826    );
     
    817834    # a lock is implicitly removed when the last storage object is deleted
    818835    foreach my $uri ( @$locations ) {
     836        # it is being assumed here that it is better to have files on disk and
     837        # not in the database then the inverse.
     838        my $path;
     839        eval {
     840            $path = _get_file_path( $uri );
     841        };
     842        if ($@) {
     843            if ($force) {
     844                $log->warn($@);
     845                $log->warn("exception ignored because force is in effect");
     846            } else {
     847                $log->logdie($@);
     848            }
     849        }
     850
    819851        $self->delete_instance($key, $uri) or return undef;
     852
     853        eval {
     854            _nuke_file( $path );
     855        };
     856        if ($@) {
     857            if ($force) {
     858                $log->warn($@);
     859                $log->warn("exception ignored because force is in effect");
     860            } else {
     861                $log->logdie($@);
     862            }
     863        }
    820864    }
    821865
     
    9591003    $log->debug( "entered - @_" );
    9601004
    961     # it is being assumed here that it is better to have files on disk and not in
    962     # the database then the inverse.
    963 
    964     my $path;
    965     eval {
    966         $path = _get_file_path( $uri );
    967     };
    968     $log->logdie( $@ ) if $@;
    969 
    9701005    my $response = $self->{ 'server' }->delete_instance($key, $uri);
    9711006    if ( $response->fault ) {
     
    9811016
    9821017    $log->debug( "server deleted instance" );
    983 
    984     eval {
    985         _nuke_file( $path );
    986     };
    987     $log->logdie( $@ ) if $@;
    9881018
    9891019    $log->debug( "leaving" );
  • trunk/Nebulous/t/59_client_delete.t

    r18858 r24440  
    1010use Apache::Test qw( -withtestmore );
    1111
    12 plan tests => 9;
     12plan tests => 13;
    1313
    1414use lib qw( ./t ./lib );
     
    2626        proxy => "http://$hostport/nebulous",
    2727    );
    28     $neb->create( "foo" );
     28    my $uri = $neb->create( "foo" );
    2929
    3030    ok( $neb->delete( "foo" ), "delete object" );
     31
     32    ok( ! -e _get_file_path($uri), "deleted file" );
    3133
    3234    my $locations = $neb->find_instances( "foo" );
     
    7678}
    7779
     80# force flag
     81Test::Nebulous->setup;
     82
     83{
     84    my $neb = Nebulous::Client->new(
     85        proxy => "http://$hostport/nebulous",
     86    );
     87    $neb->create( "foo" );
     88
     89    is( $neb->delete("foo", undef), 1, "force flag false" );
     90}
     91
     92Test::Nebulous->setup;
     93
     94{
     95    my $neb = Nebulous::Client->new(
     96        proxy => "http://$hostport/nebulous",
     97    );
     98    $neb->create( "foo" );
     99
     100    is( $neb->delete("foo", 1), 1, "force flag false" );
     101}
     102
    78103Test::Nebulous->setup;
    79104
     
    84109    $neb->delete();
    85110};
    86 like( $@, qr/1 was expected/, "no params" );
     111like( $@, qr/1 - 2 were expected/, "no params" );
    87112
    88113Test::Nebulous->setup;
     
    92117        proxy => "http://$hostport/nebulous",
    93118    );
    94     $neb->delete( "foo", 2 );
     119    $neb->delete( "foo", 3);
    95120};
    96 like( $@, qr/1 was expected/, "too many params" );
     121like( $@, qr/is boolean/, "force flag not boolean" );
     122
     123Test::Nebulous->setup;
     124
     125eval {
     126    my $neb = Nebulous::Client->new(
     127        proxy => "http://$hostport/nebulous",
     128    );
     129    $neb->delete( "foo", 0, 2 );
     130};
     131like( $@, qr/1 - 2 were expected/, "too many params" );
    97132
    98133Test::Nebulous->cleanup;
  • trunk/Nebulous/t/62_client_delete_instance.t

    r23934 r24440  
    1010use Apache::Test qw( -withtestmore );
    1111
    12 plan tests => 11;
     12plan tests => 10;
    1313
    1414use lib qw( ./t ./lib );
     
    3535
    3636    is( $uri, @$locations[0], "delete instance" );
    37 
    38     ok( ! -e _get_file_path( @$locations[0] ), "deleted file" );
    3937}
    4038
Note: See TracChangeset for help on using the changeset viewer.