Index: branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server.pm	(revision 23708)
+++ branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server.pm	(revision 23714)
@@ -15,4 +15,5 @@
 use DBI;
 use Digest::SHA1 qw( sha1_hex );
+use File::Basename qw( dirname );
 use File::ExtAttr qw( setfattr );
 use File::Path;
@@ -355,20 +356,20 @@
 
     my ($key1, $key2) = validate_pos(@_,
-				     {
-					 type        => SCALAR,
-					 callbacks   => {
-					     'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
-					 },
-				     },
-				     {
-					 type        => SCALAR,
-					 callbacks   => {
-					     'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
-					 },
-				     },
-	);
-
-    my $log  = $self->log;
-    my $sql  = $self->sql;
+        {
+            type        => SCALAR,
+            callbacks   => {
+                'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
+            },
+        },
+        {
+            type        => SCALAR,
+            callbacks   => {
+                'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
+            },
+        },
+    );
+
+    my $log = $self->log;
+    my $sql = $self->sql;
 
     my $dbidx1 = $self->db_index_for_key($key1);
@@ -391,58 +392,58 @@
     # key1.swap -> key2
 
-    my $dbh = $dbh1;
+    my $db = $dbh1;
   TRANS: while (1) {
-      eval {
-	  {
-	      # key1 -> key1.swap
-	      my $query = $db->prepare_cached($sql->rename_object); 
-	      # this SQL statment takes the new key name as the first param
-	      my $rows = $query->execute($key1->path . ".swap", $key1->path);
-
-	      # if we affected more then one row something very bad has happened.
-	      unless ($rows == 1) {
-		  $query->finish;
-		  $log->logdie("affected row count is $rows instead of 1");
-	      }
-	  }
-
-	  {
-	      # key2 -> key1
-	      my $query = $db->prepare_cached($sql->rename_object); 
-	      # this SQL statment takes the new key name as the first param
-	      my $rows = $query->execute($key1->path, $key2->path);
-
-	      # if we affected more then one row something very bad has happened.
-	      unless ($rows == 1) {
-		  $query->finish;
-		  $log->logdie("affected row count is $rows instead of 1");
-	      }
-	  }
-
-	  {
-	      # key1.swap -> key2
-	      my $query = $db->prepare_cached($sql->rename_object); 
-	      # this SQL statment takes the new key name as the first param
-	      my $rows = $query->execute($key2->path, $key1->path . ".swap");
-
-	      # if we affected more then one row something very bad has happened.
-	      unless ($rows == 1) {
-		  $query->finish;
-		  $log->logdie("affected row count is $rows instead of 1");
-	      }
-	  }
-
-	  $db->commit;
-	  $log->debug("commit");
-      };
-      if ($@) {
-	  $db->rollback;
-	  $log->debug("rollback");
-	  if ($@ =~ /Deadlock found/) {
-	      $log->warn("database deadlock retrying transaction: $@");
-	      redo TRANS;
-	  }
-	  $log->logdie("database error: $@");
-      }
+        eval {
+            {
+              # key1 -> key1.swap
+              my $query = $db->prepare_cached($sql->rename_object); 
+              # this SQL statment takes the new key name as the first param
+              my $rows = $query->execute($key1->path . ".swap", $key1->path);
+
+              # if we affected more then one row something very bad has happened.
+              unless ($rows == 1) {
+                  $query->finish;
+                  $log->logdie("affected row count is $rows instead of 1");
+              }
+          }
+
+          {
+              # key2 -> key1
+              my $query = $db->prepare_cached($sql->rename_object); 
+              # this SQL statment takes the new key name as the first param
+              my $rows = $query->execute($key1->path, $key2->path);
+
+              # if we affected more then one row something very bad has happened.
+              unless ($rows == 1) {
+                  $query->finish;
+                  $log->logdie("affected row count is $rows instead of 1");
+              }
+          }
+
+          {
+              # key1.swap -> key2
+              my $query = $db->prepare_cached($sql->rename_object); 
+              # this SQL statment takes the new key name as the first param
+              my $rows = $query->execute($key2->path, $key1->path . ".swap");
+
+              # if we affected more then one row something very bad has happened.
+              unless ($rows == 1) {
+                  $query->finish;
+                  $log->logdie("affected row count is $rows instead of 1");
+              }
+          }
+
+            $db->commit;
+            $log->debug("commit");
+        };
+        if ($@) {
+            $db->rollback;
+            $log->debug("rollback");
+            if ($@ =~ /Deadlock found/) {
+                $log->warn("database deadlock retrying transaction: $@");
+                redo TRANS;
+            }
+            $log->logdie("database error: $@");
+        }
       last;
   }
@@ -569,6 +570,6 @@
 
             # TODO add some stuff here to retry if unsucessful
-	    # XXX if this fails, it should try to generate the
-	    # instance on another volume (unless !$soft_volume) 
+            # XXX if this fails, it should try to generate the
+            # instance on another volume (unless !$soft_volume) 
             $uri = $self->_create_empty_instance_file($key->path, $so_id, $ins_id, $vol_path, $vol_xattr);
 
@@ -1090,9 +1091,8 @@
 
     my @keys = ();
-    my $n_dbs = $self->n_db();
+    my $n_dbs = $self->config->n_db();
     for (my $index = 0; $index < $n_dbs; $index ++) {
-	
-	my $newkeys = $self->find_objects_for_index($index, $pattern);
-	push @keys, @$newkeys;
+        my $newkeys = $self->find_objects_for_index($index, $pattern);
+        push @keys, @$newkeys;
     }
     $log->logdie("no keys found") unless ( scalar @keys );
@@ -1110,4 +1110,7 @@
     my $index = shift;
     my $pattern = shift;
+
+    my $log = $self->log;
+    my $sql = $self->sql;
     my $db  = $self->db_for_index($index);
 
@@ -1521,5 +1524,5 @@
     my $ext_id;
     eval {
-        my $query = $db->prepare_cached( $sql->get_object ); 
+        my $query = $db->prepare_cached( $sql->check_object_name ); 
         $query->execute($key->path);
         ($ext_id) = $query->fetchrow_array;
