At Tom Womack's request, a trivial option to use mtimes instead of
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 5 Nov 2008 21:57:32 +0000 (21:57 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 5 Nov 2008 21:57:32 +0000 (21:57 +0000)
atimes. Generally less useful, unless your atimes have been
completely hosed in which case it's better than nothing.

git-svn-id: svn://svn.tartarus.org/sgt/agedu@8283 cda61777-01e9-0310-a592-d414129be87e

agedu.but
agedu.c

index 5bf5d0b..ff97346 100644 (file)
--- a/agedu.but
+++ b/agedu.but
@@ -443,6 +443,20 @@ complexity.)
 
 }
 
+\dt \cw{--mtime}
+
+\dd This option causes \cw{agedu} to index files by their last
+modification time instead of their last access time. You might want
+to use this if your last access times were completely useless for
+some reason: for example, if you had recently searched every file on
+your system, the system would have lost all the information about
+what files you hadn't recently accessed before then. Using this
+option is liable to be less effective at finding genuinely wasted
+space than the normal mode (that is, it will be more likely to flag
+things as disused when they're not, so you will have more candidates
+to go through by hand looking for data you don't need), but may be
+better than nothing if your last-access times are unhelpful.
+
 The following options affect the web server mode \cw{-w}, and in one
 case also the stand-along HTML generation mode \cw{-H}:
 
diff --git a/agedu.c b/agedu.c
index 1a68eb4..5bd05d4 100644 (file)
--- a/agedu.c
+++ b/agedu.c
@@ -49,6 +49,7 @@ struct ctx {
     struct inclusion_exclusion *inex;
     int ninex;
     int crossfs;
+    int usemtime;
     int fakeatimes;
 };
 
@@ -86,7 +87,7 @@ static int gotdata(void *vctx, const char *pathname, const STRUCT_STAT *st)
        return 0;
 
     file.size = (unsigned long long)512 * st->st_blocks;
-    if (ctx->fakeatimes && S_ISDIR(st->st_mode))
+    if (ctx->usemtime || (ctx->fakeatimes && S_ISDIR(st->st_mode)))
        file.atime = st->st_mtime;
     else
        file.atime = st->st_atime;
@@ -299,6 +300,8 @@ static void text_query(const void *mappedfile, const char *querydir,
         HELPOPT("[--scan,--load] keep real atimes on directories") \
     NOVAL(NODIRATIME) LONG(no_dir_atime) LONG(no_dir_atimes) \
         HELPOPT("[--scan,--load] fake atimes on directories") \
+    NOVAL(MTIME) LONG(mtime) \
+        HELPOPT("[--scan] use mtime instead of atime") \
     VAL(AGERANGE) SHORT(r) LONG(age_range) LONG(range) LONG(ages) \
         HELPARG("age[-age]") HELPOPT("[--web,--html] set limits of colour coding") \
     VAL(SERVERADDR) LONG(address) LONG(addr) LONG(server_address) \
@@ -460,6 +463,7 @@ int main(int argc, char **argv)
     int crossfs = 0;
     int tqdepth = 1;
     int fakediratimes = 1;
+    int mtime = 0;
 
 #ifdef DEBUG_MAD_OPTION_PARSING_MACROS
     {
@@ -710,6 +714,9 @@ int main(int argc, char **argv)
                  case OPT_NODIRATIME:
                    fakediratimes = 1;
                    break;
+                 case OPT_MTIME:
+                   mtime = 1;
+                   break;
                  case OPT_DATAFILE:
                    filename = optval;
                    break;
@@ -912,6 +919,7 @@ int main(int argc, char **argv)
            ctx->ninex = ninex;
            ctx->crossfs = crossfs;
            ctx->fakeatimes = fakediratimes;
+           ctx->usemtime = mtime;
 
            ctx->last_output_update = time(NULL);