Index: trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 10627)
+++ trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 12961)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.22 2006-12-12 00:02:53 jhoblitt Exp $
+# $Id: Server.pm,v 1.23 2007-04-23 20:45:08 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -13,10 +13,11 @@
 
 use DBI;
-use Nebulous::Util qw( :standard );
+use Log::Log4perl;
 use Nebulous::Server::Config;
 use Nebulous::Server::Log;
 use Nebulous::Server::SQL;
-use Log::Log4perl;
-use Params::Validate qw( validate_pos SCALAR );
+use Nebulous::Util qw( :standard );
+use Params::Validate qw( validate_pos SCALAR SCALARREF );
+use URI::file;
 
 __PACKAGE__->mk_accessors(qw( log sql config ));
@@ -159,9 +160,6 @@
     $log->debug( "entered - @_" );
 
-    # TODO do some intelligent volume allocated 
-    # add hooks to make this decision based on avaiable space
     $volume = $self->_get_storage_volume( $volume );
 
-    my $uri;
     my $object_id;
     my $ins_id;
@@ -210,13 +208,11 @@
     }
 
-    $uri = "$volume/$key.$ins_id";
+    my $uri = URI::file->new("$volume/$key.$ins_id");
 
     $log->debug( "generated uri $uri");
 
-    my $path = _get_file_path( $uri );
-
     # TODO add some stuff here to retry if unsucessful
     eval {
-        _create_empty_file( $path );
+        _create_empty_file($uri->file);
     };
     if ( $@ ) {
@@ -237,5 +233,5 @@
     $log->debug( "leaving" );
 
-    return $uri;
+    return "$uri";
 }
 
@@ -297,6 +293,6 @@
 
         {
-            $uri = "$volume/$key.$ins_id";
-            $log->debug( "generated uri $uri");
+            $uri = URI::file->new("$volume/$key.$ins_id");
+            $log->debug("generated uri $uri");
 
             my $query = $db->prepare_cached( $sql->update_instance_uri );
@@ -311,6 +307,5 @@
 
     eval {
-        $path = _get_file_path( $uri );
-        $path = _create_empty_file( $path );
+        _create_empty_file($uri->file);
     };
     if ( $@ ) {
@@ -323,5 +318,5 @@
     $log->debug( "leaving" );
 
-    return $uri;
+    return "$uri";
 }
 
@@ -620,5 +615,5 @@
     my ( $uri ) = validate_pos( @_,
         {
-            type => SCALAR,
+            type => SCALAR|SCALARREF,
         },
     );
@@ -731,4 +726,6 @@
 }
 
+#  select *, total - used as free, (used / total) * 100 as perused from mount;
+
 sub _get_storage_volume {
     my $self = shift;
@@ -751,8 +748,8 @@
         if ( $name ) {
             $query = $db->prepare_cached( $sql->get_storage_volume_byname );
-            $rows = $query->execute( $name );
+            $rows = $query->execute(0.95, $name);
         } else {
             $query = $db->prepare_cached( $sql->get_storage_volume );
-            $rows = $query->execute;
+            $rows = $query->execute(0.95);
         }
 
@@ -762,5 +759,5 @@
         }
 
-        $volume = $query->fetchrow_hashref->{ 'uri' };
+        $volume = $query->fetchrow_hashref->{ 'mountpoint' };
 
         $query->finish;
