? imagecache.tempnam.patch
Index: imagecache.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v
retrieving revision 1.19.2.19
diff -u -p -r1.19.2.19 imagecache.module
--- imagecache.module	23 Feb 2007 19:07:02 -0000	1.19.2.19
+++ imagecache.module	12 Mar 2007 21:30:34 -0000
@@ -128,9 +128,9 @@ function imagecache_cache() {
 
   $destination = file_create_path() . '/imagecache/'. $preset .'/'. $path;
 
-  // prepend presetname to tmp file name to prevent namespace clashes when
-  // multiple presets for the same image are called in rapid succession.
-  $tmpdestination = file_directory_temp() . '/' . $preset . str_replace(dirname($path) . '/', '', $path);
+  // use php's tempnam function to get a unique file name in the drupal temp directory
+  // http://us2.php.net/tempnam
+  $tmpdestination = tempnam(file_directory_temp(), str_replace(dirname($path) . '/', '', $path));
 
   $dir = dirname($destination);
   //drupal_set_message('$tmpdestination: '. $tmpdestination);
@@ -157,10 +157,10 @@ function imagecache_cache() {
     return;
   }
 
-  //check if file exists to prevent multiple apache children from trying to generate.
-  if (!is_file($tmpdestination)) {
+  // check if the finished file has been written to disk since the webserver looked for it
+  if (!is_file($destination)) {
     $generated = TRUE;
-    file_copy($source, $tmpdestination);
+    file_copy($source, $tmpdestination, FILE_EXISTS_REPLACE);
 
     foreach($actions as $action) {
       $size = getimagesize($tmpdestination);
@@ -200,6 +200,8 @@ function imagecache_cache() {
     }
     file_move($tmpdestination, $destination);
   } else {
+    // delete our tempfile - as it is no longer needed
+    file_delete($tmpdestination);
     $generated = TRUE;
   }
 
