? .directory ? drupal-818818-D6.patch ? drupal-818818-D6_0.patch Index: includes/file.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/file.inc,v retrieving revision 1.121.2.12 diff -u -p -r1.121.2.12 file.inc --- includes/file.inc 11 May 2010 09:49:58 -0000 1.121.2.12 +++ includes/file.inc 21 Jun 2010 22:55:40 -0000 @@ -263,7 +263,33 @@ function file_copy(&$source, $dest = 0, return FALSE; } - if (!@copy($source, $dest)) { + // Perform the replace operation. copy() is not atomic but rename() is. + // Since there could be mutiple processes writing to the same file the best + // option is to create a temp file in the same directory and then rename it + // to the final filename. + $result = FALSE; + if ($replace == FILE_EXISTS_REPLACE) { + // Get temp filename + $temp_name = tempnam(realpath(dirname($dest)), 'file'); + // Place new contents in temp file + if ($temp_file && @copy($source, $temp_name)) { + // Try the rename opperation + if (!$result = @rename($temp_name, $dest)) { + // Unlink and try again for windows since rename on windows does not + // replace the file if it already exists. + @unlink($dest); + $result = @rename($temp_name, $dest); + } + } + else { + $result = FALSE; + } + } + // Perform the copy operation. + else { + $result = @copy($source, $dest); + } + if ($result === FALSE) { drupal_set_message(t('The selected file %file could not be copied.', array('%file' => $source)), 'error'); return 0; }