You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by je...@apache.org on 2005/08/11 01:15:00 UTC

svn commit: r231351 - in /httpd/httpd/trunk: docs/man/htcacheclean.8 docs/manual/programs/htcacheclean.html.en docs/manual/programs/htcacheclean.xml support/htcacheclean.c

Author: jerenkrantz
Date: Wed Aug 10 16:14:57 2005
New Revision: 231351

URL: http://svn.apache.org/viewcvs?rev=231351&view=rev
Log:
Add -t option to htcacheclean to clean out empty directories.

* support/htcacheclean.c: Implement -t option.
* docs/man/htcacheclean.8, docs/manual/programs/htcacheclean.html.en,
  docs/manual/programs/htcacheclean.xml: Document -t option.

Justin did some minor tweaks as he agrees with Andreas and Rudiger that
apr_dir_remove should return an error if the directory isn't empty; hence,
remove the apr_dir_read calls.

Submitted by: Colm MacCarthaigh
Reviewed by:  Justin Erenkrantz, Andreas Steinmetz, Rudiger Pluem

Modified:
    httpd/httpd/trunk/docs/man/htcacheclean.8
    httpd/httpd/trunk/docs/manual/programs/htcacheclean.html.en
    httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml
    httpd/httpd/trunk/support/htcacheclean.c

Modified: httpd/httpd/trunk/docs/man/htcacheclean.8
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/man/htcacheclean.8?rev=231351&r1=231350&r2=231351&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/man/htcacheclean.8 (original)
+++ httpd/httpd/trunk/docs/man/htcacheclean.8 Wed Aug 10 16:14:57 2005
@@ -19,7 +19,7 @@
 .el .ne 3
 .IP "\\$1" \\$2
 ..
-.TH "HTCACHECLEAN" 8 "2004-11-10" "Apache HTTP Server" "htcacheclean"
+.TH "HTCACHECLEAN" 8 "2005-08-08" "Apache HTTP Server" "htcacheclean"
 
 .SH NAME
 htcacheclean \- Clean up the disk cache
@@ -27,10 +27,10 @@
 .SH "SYNOPSIS"
  
 .PP
-\fBhtcacheclean\fR [ -\fBD\fR ] [ -\fBv\fR ] [ -\fBr\fR ] [ -\fBn\fR ] -\fBp\fR\fIpath\fR -\fBl\fR\fIlimit\fR
+\fBhtcacheclean\fR [ -\fBD\fR ] [ -\fBv\fR ] [ -\fBt\fR ] [ -\fBr\fR ] [ -\fBn\fR ] -\fBp\fR\fIpath\fR -\fBl\fR\fIlimit\fR
  
 .PP
-\fBhtcacheclean\fR -\fBb\fR [ -\fBn\fR ] [ -\fBi\fR ] -\fBd\fR\fIinterval\fR -\fBp\fR\fIpath\fR -\fBl\fR\fIlimit\fR
+\fBhtcacheclean\fR -\fBb\fR [ -\fBn\fR ] [ -\fBt\fR ] [ -\fBi\fR ] -\fBd\fR\fIinterval\fR -\fBp\fR\fIpath\fR -\fBl\fR\fIlimit\fR
  
 
 .SH "SUMMARY"
@@ -53,10 +53,13 @@
 Be verbose and print statistics\&. This option is mutually exclusive with the -d option\&.  
 .TP
 -r
-Clean thoroughly\&. This assumes that the Apache web server is not running (otherwise you may get garbage in the cache)\&. This option is mutually exclusive with the -d option\&.  
+Clean thoroughly\&. This assumes that the Apache web server is not running (otherwise you may get garbage in the cache)\&. This option is mutually exclusive with the -d option and implies the -t option\&.  
 .TP
 -n
 Be nice\&. This causes slower processing in favour of other processes\&. htcacheclean will sleep from time to time so that (a) the disk IO will be delayed and (b) the kernel can schedule other processes in the meantime\&.  
+.TP
+-t
+Delete all empty directories\&. By default only cache files are removed, however with some configurations the large number of directories created may require attention\&. If your configuration requires a very large number of directories, to the point that inode or file allocation table exhaustion may become an issue, use of this option is advised\&.  
 .TP
 -p\fIpath\fR
 Specify \fIpath\fR as the root directory of the disk cache\&. This should be the same value as specified with the CacheRoot directive\&.  

Modified: httpd/httpd/trunk/docs/manual/programs/htcacheclean.html.en
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/programs/htcacheclean.html.en?rev=231351&r1=231350&r2=231351&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/programs/htcacheclean.html.en (original)
+++ httpd/httpd/trunk/docs/manual/programs/htcacheclean.html.en Wed Aug 10 16:14:57 2005
@@ -39,6 +39,7 @@
     <p><code><strong>htcacheclean</strong>
     [ -<strong>D</strong> ]
     [ -<strong>v</strong> ]
+    [ -<strong>t</strong> ]
     [ -<strong>r</strong> ]
     [ -<strong>n</strong> ]
     -<strong>p</strong><var>path</var>
@@ -46,6 +47,7 @@
 
     <p><code><strong>htcacheclean</strong> -<strong>b</strong>
     [ -<strong>n</strong> ]
+    [ -<strong>t</strong> ]
     [ -<strong>i</strong> ]
     -<strong>d</strong><var>interval</var>
     -<strong>p</strong><var>path</var>
@@ -71,13 +73,22 @@
     <dt><code>-r</code></dt>
     <dd>Clean thoroughly. This assumes that the Apache web server is
     not running (otherwise you may get garbage in the cache). This option
-    is mutually exclusive with the <code>-d</code> option.</dd>
+    is mutually exclusive with the <code>-d</code> option and implies
+    the <code>-t</code> option.</dd>
 
     <dt><code>-n</code></dt>
     <dd>Be nice. This causes slower processing in favour of other
     processes. <code>htcacheclean</code> will sleep from time to time
     so that (a) the disk IO will be delayed and (b) the kernel can schedule
     other processes in the meantime.</dd>
+
+    <dt><code>-t</code></dt>
+    <dd>Delete all empty directories. By default only cache files are
+    removed, however with some configurations the large number of
+    directories created may require attention. If your configuration
+    requires a very large number of directories, to the point that
+    inode or file allocation table exhaustion may become an issue, use 
+    of this option is advised.</dd>
 
     <dt><code>-p<var>path</var></code></dt>
     <dd>Specify <var>path</var> as the root directory of the disk cache. This

Modified: httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml?rev=231351&r1=231350&r2=231351&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml (original)
+++ httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml Wed Aug 10 16:14:57 2005
@@ -39,6 +39,7 @@
     <p><code><strong>htcacheclean</strong>
     [ -<strong>D</strong> ]
     [ -<strong>v</strong> ]
+    [ -<strong>t</strong> ]
     [ -<strong>r</strong> ]
     [ -<strong>n</strong> ]
     -<strong>p</strong><var>path</var>
@@ -46,6 +47,7 @@
 
     <p><code><strong>htcacheclean</strong> -<strong>b</strong>
     [ -<strong>n</strong> ]
+    [ -<strong>t</strong> ]
     [ -<strong>i</strong> ]
     -<strong>d</strong><var>interval</var>
     -<strong>p</strong><var>path</var>
@@ -71,13 +73,22 @@
     <dt><code>-r</code></dt>
     <dd>Clean thoroughly. This assumes that the Apache web server is
     not running (otherwise you may get garbage in the cache). This option
-    is mutually exclusive with the <code>-d</code> option.</dd>
+    is mutually exclusive with the <code>-d</code> option and implies
+    the <code>-t</code> option.</dd>
 
     <dt><code>-n</code></dt>
     <dd>Be nice. This causes slower processing in favour of other
     processes. <code>htcacheclean</code> will sleep from time to time
     so that (a) the disk IO will be delayed and (b) the kernel can schedule
     other processes in the meantime.</dd>
+
+    <dt><code>-t</code></dt>
+    <dd>Delete all empty directories. By default only cache files are
+    removed, however with some configurations the large number of
+    directories created may require attention. If your configuration
+    requires a very large number of directories, to the point that
+    inode or file allocation table exhaustion may become an issue, use 
+    of this option is advised.</dd>
 
     <dt><code>-p<var>path</var></code></dt>
     <dd>Specify <var>path</var> as the root directory of the disk cache. This

Modified: httpd/httpd/trunk/support/htcacheclean.c
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/support/htcacheclean.c?rev=231351&r1=231350&r2=231351&view=diff
==============================================================================
--- httpd/httpd/trunk/support/htcacheclean.c (original)
+++ httpd/httpd/trunk/support/htcacheclean.c Wed Aug 10 16:14:57 2005
@@ -143,6 +143,7 @@
 static int benice;      /* flag: true means nice mode is activated */
 static int dryrun;      /* flag: true means dry run, don't actually delete
                                  anything */
+static int deldirs;     /* flag: true means directories should be deleted */
 static int baselen;     /* string length of the path to the proxy directory */
 static apr_time_t now;  /* start time of this processing run */
 
@@ -319,6 +320,32 @@
 }
 
 /*
+ * Determine if a directory is empty
+ */
+static int directory_empty(char *path, apr_pool_t *pool)
+{
+    apr_dir_t *dir;
+    apr_finfo_t info;
+    
+    if (apr_dir_open(&dir, path, pool) != APR_SUCCESS) {
+        return 0;
+    }
+
+    while (apr_dir_read(&info, 0, dir) == APR_SUCCESS && !interrupted) {
+        if (!strcmp(info.name, ".") || !strcmp(info.name, "..")) {
+            continue;
+        }
+        
+        /* If we're here, the directory is not empty */
+        apr_dir_close(dir);
+        return 0;
+    }
+
+    apr_dir_close(dir);
+    return 1;
+}
+
+/*
  * walk the cache directory tree
  */
 static int process_dir(char *path, apr_pool_t *pool)
@@ -332,7 +359,7 @@
     apr_finfo_t info;
     apr_size_t len;
     apr_time_t current, deviation;
-    char *nextpath, *base, *ext;
+    char *nextpath, *base, *ext, *orig_basename;
     APR_RING_ENTRY(_direntry) anchor;
     DIRENTRY *d, *t, *n;
     ENTRY *e;
@@ -413,9 +440,18 @@
         }
 
         if (info.filetype == APR_DIR) {
+            /* Make a copy of the basename, as process_dir modifies it */
+            orig_basename = apr_pstrdup(pool, d->basename);
             if (process_dir(d->basename, pool)) {
                 return 1;
             }
+
+            /* If asked to delete dirs, do so now. We don't care if it fails.
+             * If it fails, it likely means there was something else there.
+             */
+            if (deldirs && !dryrun) {
+                apr_dir_remove(orig_basename, pool);
+            }
             continue;
         }
 
@@ -740,8 +776,8 @@
 {
     apr_file_printf(errfile,
     "%s -- program for cleaning the disk cache."                             NL
-    "Usage: %s [-Dvrn] -pPATH -lLIMIT"                                       NL
-    "       %s [-ni] -dINTERVAL -pPATH -lLIMIT"                              NL
+    "Usage: %s [-Dvtrn] -pPATH -lLIMIT"                                      NL
+    "       %s [-nti] -dINTERVAL -pPATH -lLIMIT"                             NL
                                                                              NL
     "Options:"                                                               NL
     "  -d   Daemonize and repeat cache cleaning every INTERVAL minutes."     NL
@@ -756,11 +792,15 @@
                                                                              NL
     "  -r   Clean thoroughly. This assumes that the Apache web server is "   NL
     "       not running. This option is mutually exclusive with the -d"      NL
-    "       option."                                                         NL
+    "       option and implies -t."                                          NL
                                                                              NL
     "  -n   Be nice. This causes slower processing in favour of other"       NL
     "       processes."                                                      NL
                                                                              NL
+    "  -t   Delete all empty directories. By default only cache files are"   NL
+    "       removed, however with some configurations the large number of"   NL
+    "       directories created may require attention."                      NL
+                                                                             NL
     "  -p   Specify PATH as the root directory of the disk cache."           NL
                                                                              NL
     "  -l   Specify LIMIT as the total disk cache size limit. Attach 'K'"    NL
@@ -803,6 +843,7 @@
     verbose = 0;
     realclean = 0;
     benice = 0;
+    deldirs = 0;
     intelligent = 0;
     previous = 0; /* avoid compiler warning */
     proxypath = NULL;
@@ -827,7 +868,7 @@
     apr_getopt_init(&o, pool, argc, argv);
 
     while (1) {
-        status = apr_getopt(o, "iDnvrd:l:L:p:", &opt, &arg);
+        status = apr_getopt(o, "iDnvrtd:l:L:p:", &opt, &arg);
         if (status == APR_EOF) {
             break;
         }
@@ -856,6 +897,13 @@
                 }
                 benice = 1;
                 break;
+		
+            case 't':
+                if (deldirs) {
+                    usage();
+                }
+                deldirs = 1;
+                break;
 
             case 'v':
                 if (verbose) {
@@ -869,6 +917,7 @@
                     usage();
                 }
                 realclean = 1;
+                deldirs = 1;
                 break;
 
             case 'd':