httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject svn commit: r232334 - /httpd/httpd/trunk/modules/cache/mod_disk_cache.c
Date Fri, 12 Aug 2005 16:52:29 GMT
Author: jerenkrantz
Date: Fri Aug 12 09:52:28 2005
New Revision: 232334

URL: http://svn.apache.org/viewcvs?rev=232334&view=rev
Log:
mod_disk_cache: Remove the directory path of the cached file as far as possible
(up to the cache root) to get rid of unused empty directories.

* cache/mod_disk_cache.c
  (remove_url): Try to delete directories; also change two APR_ENOENT to
  APR_STATUS_IS_ENOENT.

Modified:
    httpd/httpd/trunk/modules/cache/mod_disk_cache.c

Modified: httpd/httpd/trunk/modules/cache/mod_disk_cache.c
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/modules/cache/mod_disk_cache.c?rev=232334&r1=232333&r2=232334&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_disk_cache.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_disk_cache.c Fri Aug 12 09:52:28 2005
@@ -75,6 +75,7 @@
  */
 typedef struct disk_cache_object {
     const char *root;        /* the location of the cache directory */
+    apr_size_t root_len;
     char *tempfile;    /* temp file tohold the content */
     const char *prefix;
     const char *datafile;    /* name of file where the data will go */
@@ -397,6 +398,9 @@
 
     dobj->name = obj->key;
     dobj->prefix = NULL;
+    /* Save the cache root */
+    dobj->root = apr_pstrndup(r->pool, conf->cache_root, conf->cache_root_len);
+    dobj->root_len = conf->cache_root_len;
     dobj->datafile = data_file(r->pool, conf, dobj, key);
     dobj->hdrsfile = header_file(r->pool, conf, dobj, key);
     dobj->tempfile = apr_pstrcat(r->pool, conf->cache_root, AP_TEMPFILE, NULL);
@@ -440,6 +444,10 @@
     /* Open the headers file */
     dobj->prefix = NULL;
 
+    /* Save the cache root */
+    dobj->root = apr_pstrndup(r->pool, conf->cache_root, conf->cache_root_len);
+    dobj->root_len = conf->cache_root_len;
+
     dobj->hdrsfile = header_file(r->pool, conf, dobj, key);
     flags = APR_READ|APR_BINARY|APR_BUFFERED;
     rc = apr_file_open(&dobj->hfd, dobj->hdrsfile, flags, 0, r->pool);
@@ -558,7 +566,7 @@
                      "disk_cache: Deleting %s from cache.", dobj->hdrsfile);
 
         rc = apr_file_remove(dobj->hdrsfile, p);
-        if ((rc != APR_SUCCESS) && (rc != APR_ENOENT)) {
+        if ((rc != APR_SUCCESS) && !APR_STATUS_IS_ENOENT(rc)) {
             /* Will only result in an output if httpd is started with -e debug.
              * For reason see log_error_core for the case s == NULL.
              */
@@ -575,7 +583,7 @@
                      "disk_cache: Deleting %s from cache.", dobj->datafile);
 
         rc = apr_file_remove(dobj->datafile, p);
-        if ((rc != APR_SUCCESS) && (rc != APR_ENOENT)) {
+        if ((rc != APR_SUCCESS) && !APR_STATUS_IS_ENOENT(rc)) {
             /* Will only result in an output if httpd is started with -e debug.
              * For reason see log_error_core for the case s == NULL.
              */
@@ -583,6 +591,45 @@
                       "disk_cache: Failed to delete data file %s from cache.",
                          dobj->datafile);
             return DECLINED;
+        }
+    }
+
+    /* now delete directories as far as possible up to our cache root */
+    if (dobj->root) {
+        const char *str_to_copy;
+
+        str_to_copy = dobj->hdrsfile ? dobj->hdrsfile : dobj->datafile;
+        if (str_to_copy) {
+            char *dir, *slash, *q;
+
+            dir = apr_pstrdup(p, str_to_copy);
+
+            /* remove filename */
+            slash = strrchr(dir, '/');
+            *slash = '\0';
+
+            /*
+             * now walk our way back to the cache root, delete everything
+             * in the way as far as possible
+             *
+             * Note: due to the way we constructed the file names in
+             * header_file and data_file, we are guaranteed that the
+             * cache_root is suffixed by at least one '/' which will be
+             * turned into a terminating null by this loop.  Therefore,
+             * we won't either delete or go above our cache root.
+             */
+            for (q = dir + dobj->root_len; *q ; ) {
+                 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
+                              "disk_cache: Deleting directory %s from cache",
+                              dir);
+
+                 rc = apr_dir_remove(dir, p);
+                 if (rc != APR_SUCCESS && !APR_STATUS_IS_ENOENT(rc)) {
+                    break;
+                 }
+                 slash = strrchr(q, '/');
+                 *slash = '\0';
+            }
         }
     }
 



Mime
View raw message