? boost-6.patch
? boost-632746.patch
? boost-632908.patch
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.249
diff -u -p -r1.3.2.2.2.5.2.249 boost.module
--- boost.module	14 Nov 2009 20:41:19 -0000	1.3.2.2.2.5.2.249
+++ boost.module	15 Nov 2009 01:10:37 -0000
@@ -1952,15 +1952,18 @@ function boost_cache_kill($files, $force
       }
     }
     // Kill Files from filesystem
-    foreach ($files as $file) {
-      if ($force_flush || !BOOST_EXPIRE_NO_FLUSH) {
-        if (file_exists($file['filename'])) {
-          @unlink($file['filename']);
-          $count++;
-        }
-        $gz_filename = str_replace($file['base_dir'], BOOST_GZIP_FILE_PATH, $file['filename']) . BOOST_GZIP_EXTENSION;
-        if (file_exists($gz_filename)) {
-          @unlink($gz_filename);
+    if ($force_flush || !BOOST_EXPIRE_NO_FLUSH) {
+      foreach ($files as $file) {
+        $filenames = boost_get_all_filenames($file['filename'], $file['base_dir']);
+        foreach ($filenames as $key => $values) {
+          foreach ($values as $num => $filename) {
+            if (file_exists($filename)) {
+              @unlink($filename);
+              if ($key == 'normal' && $num == 0) {
+                $count++;
+              }
+            }
+          }
         }
       }
     }
@@ -2038,6 +2041,46 @@ function boost_cache_get($path) {
 }
 
 /**
+ * Returns all possible filenames given the input and current settings
+ *
+ * @param $filename
+ *   Name of file
+ * @param $base_dir
+ *   Value from base_dir column in database
+ * @return
+ *   returns a 2 dimensional array
+ *    1st dimension key is either gzip or normal
+ *    2nd dimension contains all the filenames
+ */
+function boost_get_all_filenames($filename, $base_dir = NULL) {
+  $names = array();
+  $filenames = array();
+  $names[] = $filename;
+  $paths = explode('/', $filename);
+  $end = array_pop($paths);
+  $base_dir = is_null($base_dir) ? BOOST_FILE_PATH : $base_dir;
+
+  // Generate urlencoded filename, if name contains decoded characters
+  $chars = '*:<>|?#,';
+  if (preg_match("/[" . $chars . "]/", $end)) {
+    $end = urlencode($end);
+    $paths[] = $end;
+    $names[] = implode('/', $paths);
+  }
+
+  // Generate gzip filenames
+  foreach ($names as $name) {
+    $filenames['normal'][] = $name;
+    if (BOOST_GZIP) {
+      // Replace the correct dir with the gzip version for the given base dir.
+      $gzip_base_path = implode('/', array_filter(explode('/', str_replace(BOOST_ROOT_CACHE_DIR . '/' . BOOST_NORMAL_DIR, BOOST_ROOT_CACHE_DIR . '/' . BOOST_GZIP_DIR . '/', $base_dir))));
+      $filenames['gzip'][] = str_replace($base_dir, $gzip_base_path, $name) . BOOST_GZIP_EXTENSION;
+    }
+  }
+  return $filenames;
+}
+
+/**
  * Edit document before it is put into the boost cache.
  *
  * This hook is run at right before the page is cached by boost.
@@ -2135,13 +2178,10 @@ function boost_cache_set($path, $data, $
     // Special handling of the front page for aggressive gzip test
     if ($path == '' && BOOST_AGGRESSIVE_GZIP && $extension == BOOST_FILE_EXTENSION) {
       _boost_generate_gzip_test_file();
-      boost_cache_write($filename, _boost_inject_code($data, '<iframe src="/boost-gzip-cookie-test.html" style="width:0px; height:0px; border:0px; position:absolute; top:-1000px; z-index:10;"></iframe>' . "\n"), FALSE);
+      boost_cache_write($filename, _boost_inject_code($data, '<iframe src="/boost-gzip-cookie-test.html" style="width:0px; height:0px; border:0px; position:absolute; top:-1000px; z-index:10;"></iframe>' . "\n"));
     }
     else {
-      boost_cache_write($filename, $data, FALSE);
-    }
-    if (BOOST_GZIP) {
-      boost_cache_write(str_replace(BOOST_FILE_PATH, BOOST_GZIP_FILE_PATH, $filename) . BOOST_GZIP_EXTENSION, $data, TRUE);
+      boost_cache_write($filename, $data);
     }
     if (!BOOST_NO_DATABASE) {
       boost_db_prep($filename, $extension, BOOST_TIME + $expire);
@@ -2613,42 +2653,49 @@ function boost_get_time($table, $column)
  *
  * @param $filename
  *   Name of file to be written
- * @param $data
+ * @param $buffer
  *   Contents of file
- * @param $gzip
- *   Should the contents be gzipped?
  */
-function boost_cache_write($filename, $data, $gzip) {
-  if ($gzip) {
-    $data = gzencode($data, 9);
-  }
-  if (!_boost_mkdir_p(dirname($filename))) {
-    if (BOOST_VERBOSE >= 3) {
-      watchdog('boost', 'Unable to create directory: %dir<br /> Group ID: %gid<br /> User ID: %uid<br /> Current script owner: %user<br />', array('%dir' => dirname($filename), '%gid' => getmygid(), '%uid' => getmyuid(), '%user' => get_current_user()), WATCHDOG_WARNING);
-    }
-  }
-  $tempfile = $filename . getmypid();
-  if (@file_put_contents($tempfile, $data) === FALSE) {
-    if (BOOST_VERBOSE >= 3) {
-      watchdog('boost', 'Unable to write temp 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 {
-    if (is_numeric(BOOST_PERMISSIONS_FILE)) {
-      @chmod($tempfile, octdec(BOOST_PERMISSIONS_FILE));
+function boost_cache_write($filename, $buffer) {
+  $filenames = boost_get_all_filenames($filename);
+  $compressed_buffer = gzencode($buffer, 9);
+  foreach ($filenames as $key => $values) {
+    if ($key == 'gzip') {
+      $data = $compressed_buffer;
     }
-    // Erase old file
-    if (BOOST_OVERWRITE_FILE) {
-      @unlink($filename);
+    else {
+      $data = $buffer;
     }
-    // Put temp file in its final location
-    if (@rename($tempfile, $filename) === FALSE) {
-      if (BOOST_VERBOSE >= 5) {
-        watchdog('boost', '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);
+    foreach ($values as $filename) {
+      if (!_boost_mkdir_p(dirname($filename))) {
+        if (BOOST_VERBOSE >= 3) {
+          watchdog('boost', 'Unable to create directory: %dir<br /> Group ID: %gid<br /> User ID: %uid<br /> Current script owner: %user<br />', array('%dir' => dirname($filename), '%gid' => getmygid(), '%uid' => getmyuid(), '%user' => get_current_user()), WATCHDOG_WARNING);
+        }
+      }
+      $tempfile = $filename . getmypid();
+      if (@file_put_contents($tempfile, $data) === FALSE) {
+        if (BOOST_VERBOSE >= 3) {
+          watchdog('boost', 'Unable to write temp 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 {
+        if (is_numeric(BOOST_PERMISSIONS_FILE)) {
+          @chmod($tempfile, octdec(BOOST_PERMISSIONS_FILE));
+        }
+        // Erase old file
+        if (BOOST_OVERWRITE_FILE) {
+          @unlink($filename);
+        }
+        // Put temp file in its final location
+        if (@rename($tempfile, $filename) === FALSE) {
+          if (BOOST_VERBOSE >= 5) {
+            watchdog('boost', '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);
+          }
+          @unlink($tempfile);
+          return FALSE;
+        }
       }
-      @unlink($tempfile);
-      return FALSE;
     }
   }
   return TRUE;
@@ -2990,7 +3037,7 @@ function _boost_change_extension($old, $
   // make sure we are in the webroot
   chdir(dirname($_SERVER['SCRIPT_FILENAME']));
 
-  $result = db_query("SELECT filename, hash FROM {boost_cache} WHERE extension = '%s'", $old);
+  $result = db_query("SELECT base_dir, filename, hash FROM {boost_cache} WHERE extension = '%s'", $old);
   while ($filename = db_fetch_array($result)) {
     // change extension
     $new_filename = _boost_kill_file_extension($filename['filename']) . $new;
@@ -2999,13 +3046,14 @@ function _boost_change_extension($old, $
     db_query("UPDATE {boost_cache} SET filename = '%s', extension = '%s', hash = '%s' WHERE hash = '%s'", $new_filename, $new, $hash, $filename['hash']);
 
     // update files, normal & gzip
-    if (file_exists($filename)) {
-      rename($filename, $new_filename);
-    }
-    $gz_filename = str_replace(BOOST_FILE_PATH, BOOST_GZIP_FILE_PATH, $filename) . BOOST_GZIP_EXTENSION;
-    $gz_new_filename = str_replace(BOOST_FILE_PATH, BOOST_GZIP_FILE_PATH, $new_filename) . BOOST_GZIP_EXTENSION;
-    if (file_exists($gz_filename)) {
-      rename($gz_filename, $gz_new_filename);
+    $filenames = boost_get_all_filenames($filename['filename'], $filename['base_dir']);
+    $new_filenames = boost_get_all_filenames($new_filename, $filename['base_dir']);
+    foreach ($filenames as $key => $values) {
+      foreach ($values as $num => $filename) {
+        if (file_exists($filename)) {
+          rename($filename, $new_filenames[$key][$num]);
+        }
+      }
     }
   }
 }
@@ -3467,7 +3515,7 @@ function _boost_set_time_limit($time_lim
  *    array($field_1_value_A, $field_2_value_A, $field_3_value_A,
  *           $field_1_value_B, $field_2_value_B, $field_3_value_B);
  * @param $suppress
- *   bool. TRUE to supress db_query errors
+ *   bool. TRUE to suppress db_query errors
  * @return
  *   returns db_query() result.
  */
