Package: ncdu Version: 1.10-1 Severity: wishlist I understand why ncdu doesn't count symlinks by default, but in some cases, it would be very useful to do so. My use case is specifically about git-annex repositories, which make heavy use of symlinks.
There is a patch in the upstream bugtracker, but the thread has been inactive for a few years now: https://dev.yorhel.nl/ncdu/bug/16 https://p.blicky.net/j3py5 A copy of the patch is attached. -- System Information: Debian Release: 8.4 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'proposed-updates'), (500, 'stable'), (1, 'testing') Architecture: amd64 (x86_64) Kernel: Linux 4.2.0-0.bpo.1-amd64 (SMP w/2 CPU cores) Locale: LANG=fr_CA.UTF-8, LC_CTYPE=fr_CA.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages ncdu depends on: ii libc6 2.19-18+deb8u4 ii libncursesw5 5.9+20140913-1+b1 ii libtinfo5 5.9+20140913-1+b1 ncdu recommends no packages. ncdu suggests no packages. -- no debconf information
diff --git a/src/dir_scan.c b/src/dir_scan.c index 6c38eeb..0b9d679 100644 --- a/src/dir_scan.c +++ b/src/dir_scan.c @@ -188,7 +188,7 @@ static int dir_scan_item(struct dir *d) { if(exclude_match(dir_curpath)) d->flags |= FF_EXL; - if(!(d->flags & (FF_ERR|FF_EXL)) && lstat(d->name, &st)) { + if(!(d->flags & (FF_ERR|FF_EXL)) && (follow_symlinks ? stat : lstat)(d->name, &st)) { d->flags |= FF_ERR; dir_setlasterr(dir_curpath); } diff --git a/src/global.h b/src/global.h index e298f1e..4ef8bc6 100644 --- a/src/global.h +++ b/src/global.h @@ -84,6 +84,8 @@ struct dir { extern int pstate; /* read-only flag */ extern int read_only; +/* Whether to follow symlinks */ +extern int follow_symlinks; /* minimum screen update interval when calculating, in ms */ extern long update_delay; /* filter directories with CACHEDIR.TAG */ diff --git a/src/main.c b/src/main.c index 2e30d25..5b5e5f1 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,7 @@ int pstate; int read_only = 0; +int follow_symlinks = 0; long update_delay = 100; int cachedir_tags = 0; @@ -119,6 +120,7 @@ static void argv_parse(int argc, char **argv) { { 'v', 0, "-v" }, { 'x', 0, "-x" }, { 'r', 0, "-r" }, + { 'L', 0, "-L" }, { 'o', 1, "-o" }, { 'f', 1, "-f" }, { '0', 0, "-0" }, @@ -159,6 +161,7 @@ static void argv_parse(int argc, char **argv) { exit(0); case 'x': dir_scan_smfs = 1; break; case 'r': read_only = 1; break; + case 'L': follow_symlinks = 1; break; case 's': si = 1; break; case 'o': export = val; break; case 'f': import = val; break;