Index: /trunk/Nebulous-Server/scripts/dirize.pl
===================================================================
--- /trunk/Nebulous-Server/scripts/dirize.pl	(revision 24460)
+++ /trunk/Nebulous-Server/scripts/dirize.pl	(revision 24461)
@@ -37,13 +37,22 @@
 
 # initial directory fill in
-my $query = $db->prepare_cached("SELECT so_id, ext_id, dir_id FROM storage_object AS so WHERE so.dir_id = 0 LIMIT 100000");
+my $work_query = $db->prepare_cached("SELECT so_id, ext_id, dir_id FROM storage_object AS so WHERE so.dir_id = 0 LIMIT 10000");
 
+my $update_query = $db->prepare_cached("UPDATE storage_object SET ext_id_basename = ?, dir_id = ? WHERE so_id = ?");
+
+# turn of fkeys, otherwise we can change storage_object.dir_id to a
+# non-existant value
 $db->do("SET FOREIGN_KEY_CHECKS=0");
-#$db->do("UPDATE storage_object SET dir_id = 0");
-#$db->do("DELETE FROM directory");
+$db->do("UPDATE storage_object SET dir_id = 0");
+
+# completely reset the directory table
+$db->do("DELETE FROM directory");
+$db->do("ALTER TABLE directiry AUTO_INCREMENT = 1");
+# seed the root ('/') directory
+$db->do("INSERT INTO directory VALUES(1, '/', 1");
 
 my $i = 0;
-while ($query->execute and $query->rows) {
-    while (my $row = $query->fetchrow_hashref) {
+while ($work_query->execute and $work_query->rows) {
+    while (my $row = $work_query->fetchrow_hashref) {
         $i++;
         my $key = parse_neb_key($row->{'ext_id'});
@@ -53,6 +62,5 @@
 #        printf("$i dirizing %s\n", $key->path);
 
-        my $q = $db->prepare_cached("UPDATE storage_object SET ext_id_basename = ?, dir_id = ? WHERE so_id = ?");
-        $q->execute(basename($row->{'ext_id'}), $parent_id, $row->{'so_id'});
+        $update_query->execute(basename($row->{'ext_id'}), $parent_id, $row->{'so_id'});
     }
     $db->commit;
@@ -63,6 +71,3 @@
 
 $db->do("SET FOREIGN_KEY_CHECKS=1");
-
-# remove unused dirs
-#$db-do("");
-#$db->commit;
+$db->commit;
