? .directory ? drupal-818818-37-D7.patch ? drupal-818818-41-D7.patch Index: includes/file.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/file.inc,v retrieving revision 1.239 diff -u -p -r1.239 file.inc --- includes/file.inc 21 Oct 2010 12:09:41 -0000 1.239 +++ includes/file.inc 16 Nov 2010 03:22:01 -0000 @@ -881,8 +881,36 @@ function file_unmanaged_copy($source, $d } // Make sure the .htaccess files are present. file_ensure_htaccess(); + + // Perform the replace operation. Since there could be multiple processes + // writing to the same file, the best option is to create a temporary file in + // the same directory and then rename it to the destination. A temporary file + // is needed if the directory is mounted on a separate machine; thus ensuring + // the rename command stays local. + $result = FALSE; + if ($replace == FILE_EXISTS_REPLACE) { + // Get a temporary filename in the destination directory. + $temporary_file = drupal_tempnam(drupal_dirname($destination), 'file'); + // Place contents in the temporary file. + if ($temporary_file && @copy($source, $temporary_file)) { + if (!$result = @rename($temporary_file, $destination)) { + // Unlink and try again for windows. Rename on windows does not replace + // the file if it already exists. + @unlink($destination); + $result = @rename($temporary_file, $destination); + } + // Remove temporary_file if rename failed. + if (!$result) { + @unlink($temporary_file); + } + } + } + // Perform the copy operation. - if (!@copy($source, $destination)) { + else { + $result = @copy($source, $destination); + } + if ($result === FALSE) { watchdog('file', 'The specified file %file could not be copied to %destination.', array('%file' => $source, '%destination' => drupal_realpath($destination)), WATCHDOG_ERROR); return FALSE; }