Colm MacCarthaigh wrote:
> On Mon, Aug 08, 2005 at 10:33:47AM +0200, [EMAIL PROTECTED] wrote:
>
[..cut..]
>
> O.k., I've merged our two patches, but I've changed a few things, tell
> me if there's anothing you think is wrong;
>
I attached two further patches to your merged patch:
log_correction.diff:
This moves the debuging log message about the removal of a url from
cache_remove_url_filter
to cache_remove_url.
Reason: It is not a good idea to use f->r->unparsed_uri for the log message as
this
will display not the url that gets removed from the cache, but the url of the
error document
(at least in some case) and thus is misleading.
Therefore I moved it to cache_remove_url and take h->cache_obj->key instead for
the debug message.
dir_removal_patch.diff:
This patch will remove the directory path of the cached file as far as possible
to get rid
of unused empty directories. And yes, I trust apr_dir_remove :-).
[..cut..]
Regards
Rüdiger
diff -Nrup httpd-trunk.patched/modules/cache/mod_disk_cache.c
httpd-trunk/modules/cache/mod_disk_cache.c
--- httpd-trunk.patched/modules/cache/mod_disk_cache.c 2005-08-08
16:53:08.000000000 +0200
+++ httpd-trunk/modules/cache/mod_disk_cache.c 2005-08-08 20:36:31.000000000
+0200
@@ -370,6 +370,8 @@ static int create_entity(cache_handle_t
dobj->name = obj->key;
dobj->prefix = NULL;
+ /* Save the cache root */
+ dobj->root = apr_pstrdup(r->pool, conf->cache_root);
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);
@@ -413,6 +415,9 @@ static int open_entity(cache_handle_t *h
/* Open the headers file */
dobj->prefix = NULL;
+ /* Save the cache root */
+ dobj->root = apr_pstrdup(r->pool, conf->cache_root);
+
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);
@@ -518,6 +523,10 @@ static int remove_url(cache_handle_t *h,
{
apr_status_t rc;
disk_cache_object_t *dobj;
+ const char *str_to_copy;
+ char *dir;
+ char *slash;
+ char *q;
/* Get disk cache object from cache handle */
dobj = (disk_cache_object_t *) h->cache_obj->vobj;
@@ -559,6 +568,33 @@ static int remove_url(cache_handle_t *h,
}
}
+ /* now delete directories as far as possible */
+ if (dobj->root) {
+
+ str_to_copy = dobj->hdrsfile ? dobj->hdrsfile : dobj->datafile;
+ if (str_to_copy) {
+ 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
+ */
+ for (q = dir + strlen(dobj->root); *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';
+ }
+ }
+ }
+
return OK;
}
diff -Nrup httpd-trunk.patched/modules/cache/cache_storage.c
httpd-trunk/modules/cache/cache_storage.c
--- httpd-trunk.patched/modules/cache/cache_storage.c 2005-08-08
16:53:08.000000000 +0200
+++ httpd-trunk/modules/cache/cache_storage.c 2005-08-08 20:35:07.000000000
+0200
@@ -46,7 +46,8 @@ int cache_remove_url(cache_request_rec *
if (!h) {
return OK;
}
-
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
+ "cache: Removing url %s from the cache",
h->cache_obj->key);
/* for each specified cache type, delete the URL */
while(list) {
list->provider->remove_url(h, p);
diff -Nrup httpd-trunk.patched/modules/cache/mod_cache.c
httpd-trunk/modules/cache/mod_cache.c
--- httpd-trunk.patched/modules/cache/mod_cache.c 2005-08-08
16:53:08.000000000 +0200
+++ httpd-trunk/modules/cache/mod_cache.c 2005-08-08 20:43:59.000000000
+0200
@@ -802,8 +802,6 @@ static int cache_remove_url_filter(ap_fi
/*
* Now remove this cache entry from the cache
*/
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "cache: Removing url %s from the cache", f->r->unparsed_uri);
cache_remove_url(cache, r->pool);
/* remove ourselves */
ap_remove_output_filter(f);