? boost-477848.patch
Index: boost.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.admin.inc,v
retrieving revision 1.1.2.1.2.3.2.22
diff -u -p -r1.1.2.1.2.3.2.22 boost.admin.inc
--- boost.admin.inc	6 Jun 2009 07:50:23 -0000	1.1.2.1.2.3.2.22
+++ boost.admin.inc	6 Jun 2009 09:15:00 -0000
@@ -133,6 +133,12 @@ function boost_admin_settings($form = ar
     '#default_value' => BOOST_CLEAR_CACHE_OFFLINE,
     '#description'   => t('Under site maintenance when the status is set to offline, boost clears its cache. If you do not want this to happen, clear this checkbox. Pages that are not cached will still send out a Site off-line message, so be smart if turning this off.'),
   );
+  $form['advanced']['boost_flush_dir'] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Flush directories from cache if they are empty'),
+    '#default_value' => BOOST_FLUSH_DIR,
+    '#description'   => t('Disable this if you have to set settings for each dir/subdir, due to the way your server opperates (permissions, etc...).'),
+  );
   $form['advanced']['boost_halt_on_errors'] = array(
     '#type'          => 'checkbox',
     '#title'         => t('Do not cache if error on page'),
Index: boost.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.install,v
retrieving revision 1.2.2.1.2.3.2.9
diff -u -p -r1.2.2.1.2.3.2.9 boost.install
--- boost.install	2 Jun 2009 20:02:37 -0000	1.2.2.1.2.3.2.9
+++ boost.install	6 Jun 2009 09:15:00 -0000
@@ -57,21 +57,22 @@ function boost_requirements($phase) {
     case 'runtime':
       $cache_directory = variable_get('boost_file_path', boost_cache_directory(NULL, FALSE));
       $htaccess = file_get_contents('.htaccess');
+      $root_file = file_put_contents($cache_directory . '/' . variable_get('boost_root_file', '.boost'), $cache_directory);
 
       if ($cache_directory != boost_cache_directory(NULL, FALSE)) {
         $requirements['boost'] = array(
           'title'       => $t('Boost'),
           'description' => $t('!url: is not set to the default(!default). ', array('!url' => l('Cache file path', 'admin/settings/performance'), '!default'    => boost_cache_directory(NULL, FALSE))),
           'severity'    => REQUIREMENT_WARNING,
-          'value'       => $t('Cache file path'),
+          'value'       => $t('Cache path'),
         );
       }
-      else if (!is_dir($cache_directory) || !is_writable($cache_directory)) {
+      else if (!is_dir($cache_directory)) {
         $requirements['boost'] = array(
           'title'       => $t('Boost'),
-          'description' => $t('!cache_dir: does not exist, or is not writable', array('!cache_dir' => $cache_directory)),
+          'description' => $t('!cache_dir: does not exist.', array('!cache_dir' => $cache_directory)),
           'severity'    => REQUIREMENT_ERROR,
-          'value'       => $t('Cache file path'),
+          'value'       => $t('Cache path'),
         );
       }
       else if ($htaccess && count(explode("%{REQUEST_URI}_%{QUERY_STRING}.html",$htaccess)) < 5) {
@@ -82,6 +83,14 @@ function boost_requirements($phase) {
           'value'       => $t('.htaccess file'),
         );
       }
+      else if (!$root_file || !is_writable($cache_directory)) {
+        $requirements['boost'] = array(
+          'title'       => $t('Boost'),
+          'description' => $t('Directory %dir credentials - Permissions: %fp. Owner %fo. Group %fg.<br> Your credentials - Group ID: %gid. User ID: %uid. Current script owner: %user.', array('%dir' => getcwd() . '/' . $cache_directory, '%gid' => getmygid(), '%uid' => getmyuid(), '%user' => get_current_user(), '%fp' => substr(sprintf('%o', fileperms($cache_directory)), -4), '%fo' => fileowner($cache_directory), '%fg' => filegroup($cache_directory) )),
+          'severity'    => REQUIREMENT_ERROR,
+          'value'       => $t('Can not write to filesystem'),
+        );
+      }
       else {
         $requirements['boost'] = array(
           'title'       => $t('Boost'),
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.48
diff -u -p -r1.3.2.2.2.5.2.48 boost.module
--- boost.module	6 Jun 2009 07:50:23 -0000	1.3.2.2.2.5.2.48
+++ boost.module	6 Jun 2009 09:15:00 -0000
@@ -27,6 +27,8 @@ define('BOOST_GZIP',                 var
 define('BOOST_GZIP_FILE_PATH',       str_replace(BOOST_ROOT_CACHE_PATH . '/', BOOST_ROOT_CACHE_PATH . '/gz/', BOOST_FILE_PATH));
 define('BOOST_CLEAR_CACHE_OFFLINE',  variable_get('boost_clear_cache_offline', TRUE));
 define('BOOST_HALT_ON_ERRORS',       variable_get('boost_halt_on_errors', FALSE));
+define('BOOST_ROOT_FILE',            variable_get('boost_root_file', '.boost'));
+define('BOOST_FLUSH_DIR',            variable_get('boost_flush_dir', TRUE));
 
 // This cookie is set for all authenticated users, so that they can be
 // excluded from caching (or in the future get a user-specific cached page):
@@ -486,19 +488,10 @@ function boost_is_cached($path) {
 }
 
 /**
- * Deletes all static files currently in the cache.
+ * Deletes all files currently in the cache.
  */
 function boost_cache_clear_all() {
-  clearstatcache();
-  if (file_exists(BOOST_FILE_PATH)) {
-    _boost_rmdir_rf(BOOST_FILE_PATH, TRUE);
-  }
-  if (file_exists(BOOST_GZIP_FILE_PATH)) {
-    _boost_rmdir_rf(BOOST_GZIP_FILE_PATH, TRUE);
-  }
-  //recreate dirs
-  _boost_mkdir_p(BOOST_FILE_PATH);
-  _boost_mkdir_p(BOOST_GZIP_FILE_PATH);
+  boost_cache_delete(TRUE);
   watchdog('boost', 'Flushed ALL files from static page cache.', array(), WATCHDOG_NOTICE);
 }
 
@@ -506,18 +499,37 @@ function boost_cache_clear_all() {
  * Deletes all expired static files currently in the cache.
  */
 function boost_cache_expire_all() {
+  boost_cache_delete(FALSE);
+  return TRUE;
+}
+
+/**
+ * Deletes files in the cache.
+ */
+function boost_cache_delete($flush = FALSE) {
   clearstatcache();
+
+  //recreate dirs
+  _boost_mkdir_p(BOOST_FILE_PATH);
+  _boost_mkdir_p(BOOST_GZIP_FILE_PATH);
+  //add in .boost root id file
+  file_put_contents(BOOST_FILE_PATH . '/' . BOOST_ROOT_FILE, BOOST_FILE_PATH);
+  file_put_contents(BOOST_GZIP_FILE_PATH . '/' . BOOST_ROOT_FILE, BOOST_GZIP_FILE_PATH);
+
+  //Flush Cache
   if (file_exists(BOOST_FILE_PATH)) {
-    _boost_rmdir_rf(BOOST_FILE_PATH, FALSE);
+    _boost_rmdir_rf(BOOST_FILE_PATH, $flush, TRUE);
   }
   if (file_exists(BOOST_GZIP_FILE_PATH)) {
-    _boost_rmdir_rf(BOOST_GZIP_FILE_PATH, FALSE);
+    _boost_rmdir_rf(BOOST_GZIP_FILE_PATH, $flush, TRUE);
   }
+
   //recreate dirs
   _boost_mkdir_p(BOOST_FILE_PATH);
   _boost_mkdir_p(BOOST_GZIP_FILE_PATH);
-
-  return TRUE;
+  //add in .boost root id file
+  file_put_contents(BOOST_FILE_PATH . '/' . BOOST_ROOT_FILE, BOOST_FILE_PATH);
+  file_put_contents(BOOST_GZIP_FILE_PATH . '/' . BOOST_ROOT_FILE, BOOST_GZIP_FILE_PATH);
 }
 
 /**
@@ -791,35 +803,44 @@ function _boost_mkdir_p($pathname, $mode
  *   the top-level directory that will be recursively removed
  * @param $flush
  *   optional nuke it all if true, otherwise kill only expired files
+ * @param $first
+ *   id first call to this function
  */
-function _boost_rmdir_rf($dirname, $flush = TRUE) {
+function _boost_rmdir_rf($dirname, $flush = TRUE, $first = TRUE) {
   $empty = TRUE; // Start with an optimistic mindset
 
-  $files = glob($dirname . '/*', GLOB_NOSORT);
-  if ($files) {
-    foreach ($files as $file) {
-      if (is_dir($file)) {
-        if (!_boost_rmdir_rf($file, $flush)) {
-          $empty = FALSE;
+  if ($first || (!$first && !file_exists($dirname . '/' . BOOST_ROOT_FILE))) {
+    $files = glob($dirname . '/*', GLOB_NOSORT);
+    if ($files) {
+      foreach ($files as $file) {
+        if (is_dir($file)) {
+          if (!_boost_rmdir_rf($file, $flush, FALSE)) {
+            $empty = FALSE;
+          }
         }
-      }
-      else if (is_file($file) || is_link($file)) {
-        if (!$flush && !boost_file_is_expired($file)) {
-          $empty = FALSE;
-          continue;
+        else if (is_file($file) || is_link($file)) {
+          if (!$flush && !boost_file_is_expired($file)) {
+            $empty = FALSE;
+            continue;
+          }
+          @unlink($file);
+        }
+        else {
+          $empty = FALSE; // it's something else, don't del to be safe.
         }
-        @unlink($file);
-      }
-      else {
-        $empty = FALSE; // it's something else, don't del to be safe.
       }
     }
   }
 
+  //do not delete the root dir
+  if (file_exists($dirname . '/' . BOOST_ROOT_FILE)) {
+    return($empty);
+  }
+
   // The reason for this elaborate safeguard is that Drupal will log even
   // warnings that should have been suppressed with the @ sign. Otherwise,
   // we'd just rely on the FALSE return value from rmdir().
-  return ($empty && @rmdir($dirname));
+  return ($empty && BOOST_FLUSH_DIR && @rmdir($dirname));
 }
 
 //////////////////////////////////////////////////////////////////////////////
