? boost-223610.patch
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.43
diff -u -p -r1.3.2.2.2.5.2.43 boost.module
--- boost.module	2 Jun 2009 20:08:47 -0000	1.3.2.2.2.5.2.43
+++ boost.module	3 Jun 2009 21:14:00 -0000
@@ -576,28 +576,11 @@ function boost_cache_set($path, $data = 
   }
   db_set_active();
 
-  // Create or update the static file as needed
+  // Create or update the static files as needed
   if (($filename = boost_file_path($path))) {
-    _boost_mkdir_p(dirname($filename));
-    if (!file_exists($filename) || boost_file_is_expired($filename)) {
-      if (is_link($filename)) {
-        @unlink($filename); //if file is a symlink, del before trying to write.
-      }
-      if (file_put_contents($filename, $data) === FALSE) {
-        watchdog('boost', 'Unable to write file: %file', array('%file' => $filename), array(), WATCHDOG_WARNING);
-      }
-    }
+    boost_cache_write($filename, $data);
     if (BOOST_GZIP) {
-      $gz_filename = str_replace(BOOST_FILE_PATH, BOOST_GZIP_FILE_PATH, $filename). '.gz';
-      _boost_mkdir_p(dirname($gz_filename));
-      if (!file_exists($gz_filename) || boost_file_is_expired($gz_filename)) {
-        if (is_link($gz_filename)) {
-          @unlink($gz_filename); //if file is a symlink, del before trying to write.
-        }
-        if (file_put_contents($gz_filename, gzencode($data,9)) === FALSE) {
-          watchdog('boost', 'Unable to write file: %file', array('%file' => $gz_filename), array(), WATCHDOG_WARNING);
-        }
-      }
+      boost_cache_write(str_replace(BOOST_FILE_PATH, BOOST_GZIP_FILE_PATH, $filename). '.gz', gzencode($data,9));
     }
   }
 
@@ -605,6 +588,30 @@ function boost_cache_set($path, $data = 
 }
 
 /**
+ * Writes data to filename in an atomic operation thats compatible with older
+ * versions of php (php < 5.2.4 file_put_contents() doesn't lock correctly).
+ */
+function boost_cache_write($filename, $data = '') {
+  _boost_mkdir_p(dirname($filename));
+  if (!file_exists($filename) || boost_file_is_expired($filename)) {
+    $tempfile = $filename . getmypid();
+    if (file_put_contents($tempfile, $data) === FALSE) {
+      watchdog('boost', 'Unable to write file: %file<br> Group ID: %gid<br> User ID: %uid<br> Current script owner: %user<br>', array('%file' => $tempfile, '%gid' => getmygid(), '%uid' => getmyuid(), '%user' => get_current_user()), WATCHDOG_WARNING);
+      return FALSE;
+    }
+    else {
+      // put the temp file in its final location
+      if (rename($tempfile,$filename) === FALSE) {
+        watchdog('boost', t('Unable to rename file: %temp to %file<br> Group ID: %gid<br> User ID: %uid<br> Current script owner: %user<br>', array('%temp' => $tempfile, '%file' => $filename, '%gid' => getmygid(), '%uid' => getmyuid(), '%user' => get_current_user())), WATCHDOG_WARNING);
+        return FALSE;
+      }
+    }
+    return TRUE;
+  }
+  return FALSE;
+}
+
+/**
  * Returns the full directory path to the static file cache directory.
  */
 function boost_cache_directory($host = NULL, $absolute = TRUE) {
