Index: filedepot/filedepot.class.php
===================================================================
--- filedepot.orig/filedepot.class.php
+++ filedepot/filedepot.class.php
@@ -672,11 +672,11 @@ class filedepot {
           /* Need to move the file */
           $query2 = db_query("SELECT fname FROM {filedepot_fileversions} WHERE fid=%d", $fid);
           while ($A = db_fetch_array($query2)) {
-            $vname = stripslashes($A['vname']);
-            $sourcefile = $this->root_storage_path . "{$orginalCid}/{$vname}";
-            if ( file_exists($sourcefile) )  {
+            $fname = stripslashes($A['fname']);
+            $sourcefile = $this->root_storage_path . "{$orginalCid}/{$fname}";
+            if (!is_dir($sourcefile) AND file_exists($sourcefile) )  {
               watchdog('filedepot', 'Checking if file @file exists - TRUE', array('@file' => $sourcefile));
-              $targetfile = $this->root_storage_path . "{$newcid}/{$vname}";
+              $targetfile = $this->root_storage_path . "{$newcid}/{$fname}";
               // If there is more then 1 reference to this file in this category
               if ($dupfile_inuse) {
                 @copy($sourcefile, $targetfile);
@@ -689,10 +689,12 @@ class filedepot {
                   @rename($sourcefile, $targetfile);
                 }
               }
+              // FIXME: need to find a way of adding .htaccess in directory where $targetfile is?
+	      db_query("UPDATE {files} SET filepath='%s' WHERE fid IN (SELECT cckfid FROM {filedepot_files} WHERE fid=%d)", $targetfile, $fid);
               $filemoved = TRUE;
             } 
             else {
-              watchdog('filedepot', 'Checking if file @file exists - FALSE', array('@file' => $sourcefile));
+              watchdog('filedepot', 'Checking if file @file exists - FALSE', array('@file' => $sourcefile), WATCHDOG_ERROR);
             }
           }
           if ($filemoved) {    // At least one file moved - so now update record
