IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24558


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

change Nebulous::Server->find_objects() to return dirs and to sort it's output

Location:
trunk/Nebulous-Server
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Changes

    r24545 r24558  
    2929    - infinitely try to get a db handle if the connection fails
    3030    - add --mountpoint param to neb-voladd
     31    - change Nebulous::Server->find_objects() to return dirs and to sort it's
     32      output
    3133     
    32340.16
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r24548 r24558  
    14491449    }
    14501450
    1451     eval {
    1452         $log->debug("trying for a directory match under dir: $dir_id");
     1451    # find dirs under dir
     1452    my @dir_keys;
     1453    eval {
     1454        $log->debug("looking for directories under dir: $dir_id");
     1455        my $query = $db->prepare_cached( $sql->find_dir_by_parent_id);
     1456        $query->execute( $dir_id );
     1457
     1458        while ( my $row = $query->fetchrow_hashref ) {
     1459            next if $row->{'dir_id'} == 1;
     1460            my $dir = $row->{'dirname'};
     1461            if ($dir_id == 1) {
     1462                push @keys, $dir . '/' if $dir;
     1463            } else {
     1464                push @keys, $key->path . '/' . $dir . '/' if $dir;
     1465            }
     1466            $log->debug( "matched $dir" ) if $dir;
     1467        }
     1468    };
     1469    $log->logdie("database error: $@") if $@;
     1470
     1471    # find files under dir
     1472    eval {
     1473        $log->debug("looking for objects under dir: $dir_id");
    14531474        my $query = $db->prepare_cached( $sql->find_object_by_dir_id );
    14541475        $query->execute( $dir_id );
     
    14631484
    14641485    $log->debug( "leaving" );
    1465 
    1466     return \@keys;
     1486   
     1487    return [sort(@dir_keys), sort(@keys)];
    14671488}
    14681489
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r24545 r24558  
    317317        FROM storage_object
    318318        WHERE dir_id = ?
     319    },
     320    find_dir_by_parent_id => qq{
     321        SELECT dir_id, dirname
     322        FROM directory
     323        WHERE parent_id = ?
    319324    },
    320325    rename_object => qq{
  • trunk/Nebulous-Server/t/13_server_find_objects.t

    r24356 r24558  
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 28;
     10use Test::More tests => 36;
    1111
    1212use lib qw( ./t ./lib );
     
    100100    my $keys = $neb->find_objects("a");
    101101
    102     is(scalar @$keys, 1, 'number of keys found');
    103     is($keys->[0], "a/foo", "key name");
     102    is(scalar @$keys, 2, 'number of keys found');
     103    is($keys->[0], "a/b/", "key name");
     104    is($keys->[1], "a/foo", "key name");
    104105}
    105106
     
    113114
    114115    is(scalar @$keys, 2, 'number of keys found');
    115     is($keys->[0], "a/foo", "key name");
    116     is($keys->[1], "a/bar", "key name");
     116    is($keys->[0], "a/bar", "key name");
     117    is($keys->[1], "a/foo", "key name");
    117118}
    118119
     
    138139    my $keys = $neb->find_objects("/");
    139140
    140     is(scalar @$keys, 2, 'number of keys found');
    141     is($keys->[0], "foo", "key name");
     141    is(scalar @$keys, 3, 'number of keys found');
     142    is($keys->[0], "a/", "key name");
    142143    is($keys->[1], "bar", "key name");
     144    is($keys->[2], "foo", "key name");
    143145}
    144146
     
    152154    my $keys = $neb->find_objects(".");
    153155
    154     is(scalar @$keys, 2, 'number of keys found');
    155     is($keys->[0], "foo", "key name");
     156    is(scalar @$keys, 3, 'number of keys found');
     157    is($keys->[0], "a/", "key name");
    156158    is($keys->[1], "bar", "key name");
     159    is($keys->[2], "foo", "key name");
    157160}
    158161
     
    166169    my $keys = $neb->find_objects("..");
    167170
    168     is(scalar @$keys, 2, 'number of keys found');
    169     is($keys->[0], "foo", "key name");
     171    is(scalar @$keys, 3, 'number of keys found');
     172    is($keys->[0], "a/", "key name");
    170173    is($keys->[1], "bar", "key name");
     174    is($keys->[2], "foo", "key name");
     175}
     176
     177Test::Nebulous->setup;
     178
     179{
     180    $neb->create_object("a/bar");
     181    $neb->create_object("b/foo");
     182    $neb->create_object("foo");
     183
     184    my $keys = $neb->find_objects("/");
     185
     186    is(scalar @$keys, 3, 'number of keys found');
     187    is($keys->[0], "a/", "key name");
     188    is($keys->[1], "b/", "key name");
     189    is($keys->[2], "foo", "key name");
    171190}
    172191
Note: See TracChangeset for help on using the changeset viewer.