--- boost.api.inc	2008-10-24 16:03:53.000000000 -0700
+++ boost.api.inc	2008-12-03 23:44:37.000000000 -0800
@@ -134,8 +134,14 @@
   if (($filename = boost_file_path($path))) {
     _boost_mkdir_p(dirname($filename));
     if (!file_exists($filename) || boost_file_is_expired($filename)) {
-      if (file_put_contents($filename, $data) === FALSE) {
-        watchdog('boost', t('Unable to write file: %file', array('%file' => $filename)), WATCHDOG_WARNING);
+      $tempfile = $filename . getmypid();
+      if (file_put_contents($tempfile, $data) === FALSE) {
+        watchdog('boost', t('Unable to write file: %file', array('%file' => $tempfile)), WATCHDOG_WARNING);
+      } else {
+        // put the temp file in its final location
+        if (rename($tempfile,$filename) === FALSE) {
+          watchdog('boost', t('Unable to rename file: %file', array('%file' => $tempfile)), WATCHDOG_WARNING);
+        }
       }
     }
 
