At Tom Womack's request, a trivial option to use mtimes instead of
[sgt/agedu] / agedu.c
diff --git a/agedu.c b/agedu.c
index c3ac6a7..5bd05d4 100644 (file)
--- a/agedu.c
+++ b/agedu.c
@@ -2,25 +2,8 @@
  * Main program for agedu.
  */
 
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <time.h>
-#include <assert.h>
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-#include <fnmatch.h>
-
 #include "agedu.h"
+
 #include "du.h"
 #include "trie.h"
 #include "index.h"
@@ -66,6 +49,7 @@ struct ctx {
     struct inclusion_exclusion *inex;
     int ninex;
     int crossfs;
+    int usemtime;
     int fakeatimes;
 };
 
@@ -103,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;
@@ -316,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) \
@@ -477,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
     {
@@ -727,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;
@@ -929,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);
 
@@ -1033,8 +1024,8 @@ int main(int argc, char **argv)
                    return 1;
                }
 
-               printf("Built pathname index, %d entries, %ju bytes\n", count,
-                      (intmax_t)st.st_size);
+               printf("Built pathname index, %d entries, %llu bytes\n", count,
+                      (unsigned long long)st.st_size);
 
                totalsize = index_compute_size(st.st_size, count);
 
@@ -1047,8 +1038,8 @@ int main(int argc, char **argv)
                    return 1;
                }
 
-               printf("Upper bound on index file size = %ju bytes\n",
-                      (intmax_t)totalsize);
+               printf("Upper bound on index file size = %llu bytes\n",
+                      (unsigned long long)totalsize);
 
                mappedfile = mmap(NULL, totalsize, PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0);
                if (!mappedfile) {
@@ -1073,7 +1064,8 @@ int main(int argc, char **argv)
                munmap(mappedfile, totalsize);
                ftruncate(fd, realsize);
                close(fd);
-               printf("Actual index file size = %ju bytes\n", (intmax_t)realsize);
+               printf("Actual index file size = %llu bytes\n",
+                      (unsigned long long)realsize);
            }
        } else if (mode == TEXT) {
            char *querydir = actions[action].arg;