diff -urp uploadpath/uploadpath.info uploadpath_6x/uploadpath.info
--- uploadpath/uploadpath.info	Fri Jun 15 18:14:45 2007
+++ uploadpath_6x/uploadpath.info	Wed Apr  9 14:01:21 2008
@@ -1,10 +1,6 @@
-; $Id: uploadpath.info,v 1.1.2.1 2007/06/15 22:44:39 crell Exp $
+; $Id: $
 name = Upload path
 description = Organize uploaded files according to admin-specified rules.
-dependencies = upload token
-
-; Information added by drupal.org packaging script on 2007-06-16
-version = "5.x-1.x-dev"
-project = "uploadpath"
-datestamp = "1181952885"
-
+core = 6.x
+dependencies[] = upload
+dependencies[] = token
diff -urp uploadpath/uploadpath.module uploadpath_6x/uploadpath.module
--- uploadpath/uploadpath.module	Fri Jun 15 16:44:39 2007
+++ uploadpath_6x/uploadpath.module	Wed Apr  9 13:51:03 2008
@@ -9,20 +9,17 @@
 /**
  * Implementation of hook_menu().
  */
-function uploadpath_menu($may_cache) {
+function uploadpath_menu() {
   $items = array();
 
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/uploadpath',
-      'title' => t('File upload paths'),
-      'description' => t('Configure a prefix to apply to the path of uploaded files.'),
-      'access' => user_access('administer site configuration'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('uploadpath_admin_settings'),
-      'type' => MENU_NORMAL_ITEM,
-    );
-  }
+  $items['admin/settings/uploadpath'] = array(
+    'title' => 'File upload paths',
+    'description' => 'Configure a prefix to apply to the path of uploaded files.',
+    'access arguments' => array('administer site configuration'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('uploadpath_admin_settings'),
+    'type' => MENU_NORMAL_ITEM,
+  );
 
   return $items;
 }
@@ -59,25 +56,41 @@ function uploadpath_admin_settings() {
  */
 function uploadpath_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   switch ($op) {
-    case 'submit':
-      if (isset($node->files)) {
-        foreach ($node->files as $key => $file) {
-          if (0 === strpos($key, 'upload_')) {  // Only rewrite the name when adding the file, not when updating it
+    case 'insert':
+    case 'update':
+      if (user_access('upload files')) {
+        if (isset($node->files)) {
+          foreach ($node->files as $key => $file) {
+            if($file['remove']){
+              // file is slated to be deleted
+              continue;
+            }
             // Get the new, prefixed file name
-            $file_name = str_replace(array(' ', "\n", "\t"), '_', token_replace(variable_get('uploadpath_prefix', '') . '/', 'node', $node)) . $node->files[$key]['filename'];
-
-            // Create the directory if it doesn't exist yet.
-            $dirs = explode('/', dirname($file_name));
-            $directory = file_directory_path();
-            while (count($dirs)) {
-              $directory .= '/' . array_shift($dirs);
-              file_check_directory($directory, FILE_CREATE_DIRECTORY);
+            $tokenized = token_replace(variable_get('uploadpath_prefix', '') . '/', 'node', $node);
+            $tokenized = str_replace(array(' ', "\n", "\t"), '_', $tokenized);
+            $dest =  $tokenized . $file['filename'];
+            
+            // see if we need to move it, or if it's already ok
+            if($file['filepath'] != file_directory_path() . '/' . $dest){
+              // Create the directory if it doesn't exist yet.
+              $dirs = explode('/', dirname($dest));
+              $directory = file_directory_path();
+              while (count($dirs)) {
+                $directory .= '/' . array_shift($dirs);
+                file_check_directory($directory, FILE_CREATE_DIRECTORY);
+              }
+              
+              // move file on filesystem
+              if (file_move($file['filepath'], $dest, FILE_EXISTS_RENAME)) {
+                $node->files[$key] = $file;
+                // update existing file in database
+                db_query("UPDATE {files} SET filepath = '%s' WHERE fid = %d", $file['filepath'], $file['fid']);
+              }
             }
-            // Change where the file will be saved to the specified directory.
-            $node->files[$key]['filename'] = $file_name;
           }
         }
       }
       break;
   }
 }
+
