Index: trunk/Nebulous-Server/Changes
===================================================================
--- trunk/Nebulous-Server/Changes	(revision 24548)
+++ trunk/Nebulous-Server/Changes	(revision 24558)
@@ -29,4 +29,6 @@
     - infinitely try to get a db handle if the connection fails
     - add --mountpoint param to neb-voladd
+    - change Nebulous::Server->find_objects() to return dirs and to sort it's
+      output 
       
 0.16
Index: trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 24548)
+++ trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 24558)
@@ -1449,6 +1449,27 @@
     }
 
-    eval {
-        $log->debug("trying for a directory match under dir: $dir_id");
+    # find dirs under dir
+    my @dir_keys;
+    eval {
+        $log->debug("looking for directories under dir: $dir_id");
+        my $query = $db->prepare_cached( $sql->find_dir_by_parent_id);
+        $query->execute( $dir_id );
+
+        while ( my $row = $query->fetchrow_hashref ) {
+            next if $row->{'dir_id'} == 1;
+            my $dir = $row->{'dirname'};
+            if ($dir_id == 1) {
+                push @keys, $dir . '/' if $dir;
+            } else {
+                push @keys, $key->path . '/' . $dir . '/' if $dir;
+            }
+            $log->debug( "matched $dir" ) if $dir;
+        }
+    };
+    $log->logdie("database error: $@") if $@;
+
+    # find files under dir
+    eval {
+        $log->debug("looking for objects under dir: $dir_id");
         my $query = $db->prepare_cached( $sql->find_object_by_dir_id );
         $query->execute( $dir_id );
@@ -1463,6 +1484,6 @@
 
     $log->debug( "leaving" );
-
-    return \@keys;
+    
+    return [sort(@dir_keys), sort(@keys)];
 }
 
Index: trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 24548)
+++ trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 24558)
@@ -317,4 +317,9 @@
         FROM storage_object
         WHERE dir_id = ?
+    },
+    find_dir_by_parent_id => qq{
+        SELECT dir_id, dirname
+        FROM directory
+        WHERE parent_id = ?
     },
     rename_object => qq{
Index: trunk/Nebulous-Server/t/13_server_find_objects.t
===================================================================
--- trunk/Nebulous-Server/t/13_server_find_objects.t	(revision 24548)
+++ trunk/Nebulous-Server/t/13_server_find_objects.t	(revision 24558)
@@ -8,5 +8,5 @@
 use warnings FATAL => qw( all );
 
-use Test::More tests => 28;
+use Test::More tests => 36;
 
 use lib qw( ./t ./lib );
@@ -100,6 +100,7 @@
     my $keys = $neb->find_objects("a");
 
-    is(scalar @$keys, 1, 'number of keys found');
-    is($keys->[0], "a/foo", "key name");
+    is(scalar @$keys, 2, 'number of keys found');
+    is($keys->[0], "a/b/", "key name");
+    is($keys->[1], "a/foo", "key name");
 }
 
@@ -113,6 +114,6 @@
 
     is(scalar @$keys, 2, 'number of keys found');
-    is($keys->[0], "a/foo", "key name");
-    is($keys->[1], "a/bar", "key name");
+    is($keys->[0], "a/bar", "key name");
+    is($keys->[1], "a/foo", "key name");
 }
 
@@ -138,7 +139,8 @@
     my $keys = $neb->find_objects("/");
 
-    is(scalar @$keys, 2, 'number of keys found');
-    is($keys->[0], "foo", "key name");
+    is(scalar @$keys, 3, 'number of keys found');
+    is($keys->[0], "a/", "key name");
     is($keys->[1], "bar", "key name");
+    is($keys->[2], "foo", "key name");
 }
 
@@ -152,7 +154,8 @@
     my $keys = $neb->find_objects(".");
 
-    is(scalar @$keys, 2, 'number of keys found');
-    is($keys->[0], "foo", "key name");
+    is(scalar @$keys, 3, 'number of keys found');
+    is($keys->[0], "a/", "key name");
     is($keys->[1], "bar", "key name");
+    is($keys->[2], "foo", "key name");
 }
 
@@ -166,7 +169,23 @@
     my $keys = $neb->find_objects("..");
 
-    is(scalar @$keys, 2, 'number of keys found');
-    is($keys->[0], "foo", "key name");
+    is(scalar @$keys, 3, 'number of keys found');
+    is($keys->[0], "a/", "key name");
     is($keys->[1], "bar", "key name");
+    is($keys->[2], "foo", "key name");
+}
+
+Test::Nebulous->setup;
+
+{
+    $neb->create_object("a/bar");
+    $neb->create_object("b/foo");
+    $neb->create_object("foo");
+
+    my $keys = $neb->find_objects("/");
+
+    is(scalar @$keys, 3, 'number of keys found');
+    is($keys->[0], "a/", "key name");
+    is($keys->[1], "b/", "key name");
+    is($keys->[2], "foo", "key name");
 }
 
