? .cache
? .project
? .projectOptions
? drupalhead_33482_0.patch
? files
? form.inc_121620_1.patch
? includes/Copy (2) of file.inc
? includes/Copy of file.inc
? misc/Thumbs.db
? misc/farbtastic/Thumbs.db
? sites/all/modules
? sites/default/settings.php
Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.99
diff -u -r1.99 file.inc
--- includes/file.inc	30 May 2007 08:08:57 -0000	1.99
+++ includes/file.inc	30 May 2007 22:22:04 -0000
@@ -194,6 +194,42 @@
   return $source;
 }
 
+
+/**
+ * Copies a file to a new location. This is a powerful function that in many ways
+ * performs like an advanced version of copy().
+ * - Checks if $source and $dest are valid and readable/writable.
+ * - Performs a file copy if $source is not equal to $dest.
+ * - If file already exists in $dest either the call will error out, replace the
+ *   file or rename the file based on the $replace parameter.
+ *
+ * @param $source A file object location of the original file.
+ * @param $dest A string containing the directory $source should be copied to.
+ *   If this value is omitted, Drupal's 'files' directory will be used.
+ * @param $replace Replace behavior when the destination file already exists.
+ *   - FILE_EXISTS_REPLACE - Replace the existing file
+ *   - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
+ *   - FILE_EXISTS_ERROR - Do nothing and return FALSE.
+ * @return File object if the copy is successful, FALSE for failure.
+ */
+function file_copy($source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
+  if ($result = _file_copy($source, $dest, $replace)) {
+    $file = new stdClass();
+    $file->uid       = $source->uid;
+    $file->filename  = basename($result);
+    $file->filepath  = $result;
+    $file->filemime  = $source->filemime;
+    $file->filesize  = filesize($result);
+    $file->status    = $source->status;
+    $file = file_save($file);
+    
+    module_invoke_all('file', 'copy', $file, $source);
+    
+    return $file;
+  }
+  return FALSE; 
+}
+
 /**
  * Copies a file to a new location. This is a powerful function that in many ways
  * performs like an advanced version of copy().
@@ -203,17 +239,15 @@
  *   file or rename the file based on the $replace parameter.
  *
  * @param $source A string specifying the file location of the original file.
- *   This parameter will contain the resulting destination filename in case of
- *   success.
  * @param $dest A string containing the directory $source should be copied to.
  *   If this value is omitted, Drupal's 'files' directory will be used.
  * @param $replace Replace behavior when the destination file already exists.
  *   - FILE_EXISTS_REPLACE - Replace the existing file
  *   - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
  *   - FILE_EXISTS_ERROR - Do nothing and return FALSE.
- * @return True for success, FALSE for failure.
+ * @return The name of the new file, or FALSE for failure.
  */
-function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
+function _file_copy($source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
   $dest = file_create_path($dest);
 
   $directory = $dest;
@@ -221,25 +255,16 @@
 
   // Make sure we at least have a valid directory.
   if ($basename === FALSE) {
-    $source = is_object($source) ? $source->filepath : $source;
+    // TODO this error message makes no sense. this isn't used on uploads any longer.
     drupal_set_message(t('The selected file %file could not be uploaded, because the destination %directory is not properly configured.', array('%file' => $source, '%directory' => $dest)), 'error');
     watchdog('file system', 'The selected file %file could not be uploaded, because the destination %directory could not be found, or because its permissions do not allow the file to be written.', array('%file' => $source, '%directory' => $dest), WATCHDOG_ERROR);
-    return 0;
-  }
-
-  // Process a file upload object.
-  if (is_object($source)) {
-    $file = $source;
-    $source = $file->filepath;
-    if (!$basename) {
-      $basename = $file->filename;
-    }
+    return FALSE;
   }
 
   $source = realpath($source);
   if (!file_exists($source)) {
     drupal_set_message(t('The selected file %file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.', array('%file' => $source)), 'error');
-    return 0;
+    return FALSE;
   }
 
   // If the destination file is not specified then use the filename of the source file.
@@ -257,7 +282,7 @@
 
     if (!@copy($source, $dest)) {
       drupal_set_message(t('The selected file %file could not be copied.', array('%file' => $source)), 'error');
-      return 0;
+      return FALSE;
     }
 
     // Give everyone read access so that FTP'd users or
@@ -267,16 +292,7 @@
     @chmod($dest, 0664);
   }
 
-  if (isset($file) && is_object($file)) {
-    $file->filename = $basename;
-    $file->filepath = $dest;
-    $source = $file;
-  }
-  else {
-    $source = $dest;
-  }
-
-  return 1; // Everything went ok.
+  return $dest;
 }
 
 /**
@@ -316,29 +332,30 @@
  * - If file already exists in $dest either the call will error out, replace the
  *   file or rename the file based on the $replace parameter.
  *
- * @param $source A string specifying the file location of the original file.
- *   This parameter will contain the resulting destination filename in case of
- *   success.
+ * @param $source A file object for the original file.
  * @param $dest A string containing the directory $source should be copied to.
  *   If this value is omitted, Drupal's 'files' directory will be used.
  * @param $replace Replace behavior when the destination file already exists.
  *   - FILE_EXISTS_REPLACE - Replace the existing file
  *   - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
  *   - FILE_EXISTS_ERROR - Do nothing and return FALSE.
- * @return True for success, FALSE for failure.
+ * @return Resulting file object for success, FALSE for failure.
  */
-function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
-  $path_original = is_object($source) ? $source->filepath : $source;
-
-  if (file_copy($source, $dest, $replace)) {
-    $path_current = is_object($source) ? $source->filepath : $source;
-
-    if ($path_original == $path_current || file_delete($path_original)) {
-      return 1;
+function file_move($source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
+  if ($result = _file_copy($source->filepath, $dest, $replace)) {
+    if ($source->filepath == $result || _file_delete($source->filepath)) {
+      $file = drupal_clone($source);
+      $file->filename = basename($result);
+      $file->filepath = $result;
+      $file = file_save($file);
+      
+      module_invoke_all('file', 'move', $file, $source);
+      
+      return $file;
     }
-    drupal_set_message(t('The removal of the original file %file has failed.', array('%file' => $path_original)), 'error');
+    drupal_set_message(t('The removal of the original file %file has failed.', array('%file' => $source->filepath)), 'error');
   }
-  return 0;
+  return FALSE;
 }
 
 /**
@@ -425,12 +442,29 @@
 }
 
 /**
+ * Delete a file and its database record.
+ *
+ * @param $path A file object.
+ * @return TRUE for success, FALSE for failure.
+ */
+function file_delete($file) {
+  if (_file_delete($file->filepath)) {
+    // TODO: delete the database record
+    
+    module_invoke_all('file', 'delete', $file);
+    return TRUE;
+  }
+  
+  return FALSE;
+}
+
+/**
  * Delete a file.
  *
  * @param $path A string containing a file path.
  * @return TRUE for success, FALSE for failure.
  */
-function file_delete($path) {
+function _file_delete($path) {
   if (is_file($path)) {
     return unlink($path);
   }
