Fix bonehead error in hex escape processing when loading dump files.
[sgt/agedu] / agedu.c
diff --git a/agedu.c b/agedu.c
index 07e9415..4cdfee6 100644 (file)
--- a/agedu.c
+++ b/agedu.c
@@ -66,6 +66,7 @@ struct ctx {
     struct inclusion_exclusion *inex;
     int ninex;
     int crossfs;
+    int fakeatimes;
 };
 
 static void dump_line(const char *pathname, const struct trie_file *tf)
@@ -102,7 +103,10 @@ static int gotdata(void *vctx, const char *pathname, const struct stat64 *st)
        return 0;
 
     file.size = (unsigned long long)512 * st->st_blocks;
-    file.atime = st->st_atime;
+    if (ctx->fakeatimes && S_ISDIR(st->st_mode))
+       file.atime = st->st_mtime;
+    else
+       file.atime = st->st_atime;
 
     /*
      * Filter based on wildcards.
@@ -173,6 +177,9 @@ static void text_query(const void *mappedfile, const char *querydir,
     xi1 = trie_before(mappedfile, querydir);
     xi2 = trie_before(mappedfile, pathbuf);
 
+    if (xi2 - xi1 == 1)
+       return;                        /* file, or empty dir => no display */
+
     /*
      * Now do the lookups in the age index.
      */
@@ -299,6 +306,10 @@ static void text_query(const void *mappedfile, const char *querydir,
         HELPARG("wildcard") HELPOPT("[--scan] prune files matching pattern") \
     VAL(PRUNEPATH) LONG(prune_path) \
         HELPARG("wildcard") HELPOPT("[--scan] prune pathnames matching pattern") \
+    NOVAL(DIRATIME) LONG(dir_atime) LONG(dir_atimes) \
+        HELPOPT("[--scan] keep real atimes on directories") \
+    NOVAL(NODIRATIME) LONG(no_dir_atime) LONG(no_dir_atimes) \
+        HELPOPT("[--scan] fake atimes on directories") \
     VAL(TQDEPTH) LONG(depth) LONG(max_depth) LONG(maximum_depth) \
         HELPARG("levels") HELPOPT("[--text] recurse to this many levels") \
     VAL(MINAGE) SHORT(a) LONG(age) LONG(min_age) LONG(minimum_age) \
@@ -459,6 +470,7 @@ int main(int argc, char **argv)
     int ninex = 0, inexsize = 0;
     int crossfs = 0;
     int tqdepth = 1;
+    int fakediratimes = 1;
 
 #ifdef DEBUG_MAD_OPTION_PARSING_MACROS
     {
@@ -689,6 +701,12 @@ int main(int argc, char **argv)
                  case OPT_NOCROSSFS:
                    crossfs = 0;
                    break;
+                 case OPT_DIRATIME:
+                   fakediratimes = 0;
+                   break;
+                 case OPT_NODIRATIME:
+                   fakediratimes = 1;
+                   break;
                  case OPT_DATAFILE:
                    filename = optval;
                    break;
@@ -890,6 +908,7 @@ int main(int argc, char **argv)
            ctx->inex = inex;
            ctx->ninex = ninex;
            ctx->crossfs = crossfs;
+           ctx->fakeatimes = fakediratimes;
 
            ctx->last_output_update = time(NULL);
 
@@ -951,6 +970,7 @@ int main(int argc, char **argv)
                            p++;
                            c = 0;
                            for (i = 0; i < 2; i++) {
+                               c *= 16;
                                if (*p >= '0' && *p <= '9')
                                    c += *p - '0';
                                else if (*p >= 'A' && *p <= 'F')
@@ -970,6 +990,7 @@ int main(int argc, char **argv)
                    *q = '\0';
                    triebuild_add(ctx->tb, buf, &tf);
                    sfree(buf);
+                   line++;
                }
            } else {
                du(scandir, gotdata, ctx);
@@ -1015,6 +1036,12 @@ int main(int argc, char **argv)
                    return 1;
                }
 
+               if (fakediratimes) {
+                   printf("Faking directory atimes\n");
+                   trie_fake_dir_atimes(mappedfile);
+               }
+
+               printf("Building index\n");
                ib = indexbuild_new(mappedfile, st.st_size, count);
                tw = triewalk_new(mappedfile);
                while ((tf = triewalk_next(tw, NULL)) != NULL)