]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod: Add a flag to limit scan depth
authorRoman Bolshakov <roman@subtile.systems>
Wed, 8 Apr 2026 02:19:56 +0000 (07:19 +0500)
committerAaron Merey <amerey@redhat.com>
Wed, 8 Apr 2026 13:54:30 +0000 (09:54 -0400)
As of now the scanner may consume a lot of time, descending deep into
irrelevant directories where no build artifacts are known to be stored.

The change introduces --max-depth flag that has semantics similar to
-maxdepth in GNU find.

Signed-off-by: Roman Bolshakov <rbolshakov@ddn.com>
debuginfod/debuginfod.cxx
doc/debuginfod.8

index 2cf77bcc9127771440c2c9146503ef56929dd5b1..88a69d092124813368ec1c021b5c90258a2f67d9 100644 (file)
@@ -440,6 +440,7 @@ static const struct argp_option options[] =
 
    { NULL, 0, NULL, 0, "Options:", 2 },
    { "logical", 'L', NULL, 0, "Follow symlinks, default=ignore.", 0 },
+   { "max-depth", 'M', "LEVELS", 0, "Depth of directory levels to descend into, default=no-limit.", 0 },
    { "rescan-time", 't', "SECONDS", 0, "Number of seconds to wait between rescans, 0=disable.", 0 },
    { "groom-time", 'g', "SECONDS", 0, "Number of seconds to wait between database grooming, 0=disable.", 0 },
    { "maxigroom", 'G', NULL, 0, "Run a complete database groom/shrink pass at startup.", 0 },
@@ -520,6 +521,7 @@ static unsigned http_port = 8002;
 static struct sockaddr_in6 http_sockaddr;
 static string addr_info = "";
 static bool webapi_cors = false;
+static int max_depth = -1;
 static unsigned rescan_s = 300;
 static unsigned groom_s = 86400;
 static bool maxigroom = false;
@@ -660,6 +662,13 @@ parse_opt (int key, char *arg,
         argp_failure(state, 1, EINVAL, "-D option inconsistent with passive mode");
       extra_ddl.push_back(string(arg));
       break;
+    case 'M':
+      if (passive_p)
+        argp_failure(state, 1, EINVAL, "-M option inconsistent with passive mode");
+      max_depth = atoi(arg);
+      if (max_depth < 0)
+        argp_failure(state, 1, EINVAL, "-M LEVELS needs to be at least 0");
+      break;
     case 't':
       if (passive_p)
         argp_failure(state, 1, EINVAL, "-t option inconsistent with passive mode");
@@ -5183,6 +5192,17 @@ scan_source_paths()
 
     fts_scanned ++;
 
+    if (max_depth >= 0 && (f->fts_info == FTS_D || f->fts_info == FTS_DP) &&
+        f->fts_level > max_depth)
+      {
+        fts_set(fts, f, FTS_SKIP);
+        if (verbose > 2)
+          obatched(clog) << "fts skip " << f->fts_path
+                         << (f->fts_info == FTS_D ? " pre-traversal" :
+                                                    " post-traversal") << endl;
+        continue;
+      };
+
     if (verbose > 2)
       obatched(clog) << "fts traversing " << f->fts_path << endl;
 
index ead3d3b178f71bb2fa1aec47a51361c1c57883b7..9dceb9b04b86eaf8a4e6ea4cf8532708b7ff487b 100644 (file)
@@ -252,6 +252,12 @@ device, and ignore symlinks - as in \fIfind\ -P\ -xdev\fP.  Caution: a
 loops in the symbolic directory tree might lead to \fIinfinite
 traversal\fP.
 
+.TP
+.B "\-M LEVELS"  "\-\-max\-depth=LEVELS"
+Limit the depth of directory traversal to \fILEVELS\fP levels
+below the source paths - as in \fIfind\ -maxdepth\fP.
+The default is unlimited depth; minimum is 0.
+
 .TP
 .B "\-\-fdcache\-mbs=MB"
 Configure limits on a cache that keeps recently extracted files from