--- fileshare.module	2007-02-12 11:29:32.000000000 -0800
+++ fileshare.module.new	2007-06-21 14:01:53.000000000 -0700
@@ -279,17 +279,16 @@ function fileshare_update($node) {
   if ($node->revision) {
     fileshare_insert($node);
   } else {
-    // convert and sanitize node title as directory name
-    $rename = '/'._sanitize_filename($node->title).$node->nid;
+    $orig = node_load($node->nid);
     if ($node->_filepath != $rename) {
-      if (!rename($node->_basepath.$node->_filepath, $node->_basepath.$rename)) {
-        die('RENAMING ERROR - from "'.$node->_basepath.$node->_filepath.'" to "'.$node->_basepath.$rename.'".');
+      if (!@rename($orig->_basepath.$orig->_filepath, $node->_basepath.$node->_filepath)) {
+        return false;
       }
     }
-  $node->_filepath = $rename;
   db_query("UPDATE {node_fileshare} SET _filepath = '%s',  _basepath = '%s', _whitelist = '%s', _method = %b, _modify = %b, _thumbs = %b, _private = %b WHERE vid = %d", 
     $node->_filepath, $node->_basepath, $node->_whitelist, $node->_method, $node->_modify, $node->_thumbs, $node->_private, $node->vid);
   }
+  return true;
 }
 
 /**
@@ -421,6 +420,25 @@ function _uploadform($node) {
   $form['file']['create'] = array('#type' => 'submit', '#value' => t('New folder'));
   $form['file']['root'] = array('#type' => 'hidden', '#value' => $node->_basepath.$node->_filepath);
   $form['file']['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
+  
+  if(user_access('set file path')) {
+     $form['node_modify'] = array(
+      '#type'   => 'fieldset',
+      '#title'  => t('Node base path'),
+      '#collapsible' => true,
+      '#collapsed'   => true,
+     );  
+ 
+     $form['node_modify']['_filepath'] = array(
+       '#type'          => 'textfield',
+       '#title'         => t('Node file path'),
+       '#default_value' => $node->_filepath,
+       '#maxlength'     => 255,
+     );
+     
+     $form['node_modify']['change_path'] = array('#type' => 'submit', '#value' => t('Change node base path'));
+   }
+  
   return $form;
 }
 
@@ -464,6 +482,12 @@ function _uploadform_validate($form_id, 
         form_set_error('dirname',t('You must first enter a folder name.'));
       }
       break;
+      
+      case t('Change node base path'):
+       if(empty($form_values['_filepath']) && user_access('set file path')) {
+         form_set_error('_filepath', t('Base path is required'));
+       }
+       break;
   }
 }
 
@@ -494,6 +518,18 @@ function _uploadform_submit($form_id, $f
         drupal_set_message('There was a problem creating: <strong>"'.$targetdir.'"</strong>.','error');
       }
       break;
+      
+      case t('Change node base path'):
+       $node = node_load($form_values['nid']);
+       $node->_filepath = $form_values['_filepath'];
+       if (fileshare_update($node)) {
+         watchdog('fileshare', check_plain('node '.$node->nid.' files moved to '.$form_values['_filepath']), WATCHDOG_NOTICE, l(t('view'), 'node/'.$node->nid));
+         drupal_set_message('Directory move completed successfully.');
+       } else {
+         drupal_set_message('Directory move failed.', 'error');
+         watchdog('fileshare', check_plain('node '.$node->nid.' failed to move to '.$form_values['_filepath']), WATCHDOG_NOTICE, l(t('view'), 'node/'.$node->nid));
+       }
+       break;
   }
 } 
 
