summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-01-24 08:56:19 +0100
committerYorhel <git@yorhel.nl>2019-01-24 08:56:19 +0100
commit882a32613d5addd01c669bb36b1cdab93317a1b8 (patch)
tree8c35bbb9a2c1635793aa56297b6b1af541591faf
parent74efdfaf97ff538bd5bc18d15bc1854e15a7ad05 (diff)
symlinks: Only call stat_to_dir() once, impove manual
stat_to_dir() assumes that buf_dir is clean; calling it twice breaks that asumption.
-rw-r--r--doc/ncdu.pod8
-rw-r--r--src/dir_scan.c16
2 files changed, 12 insertions, 12 deletions
diff --git a/doc/ncdu.pod b/doc/ncdu.pod
index eaa0ddc..784500f 100644
--- a/doc/ncdu.pod
+++ b/doc/ncdu.pod
@@ -172,10 +172,12 @@ displayed, but not their content, and they are not counted towards the disk
usage statistics.
See http://www.brynosaurus.com/cachedir/
-=item -L,--follow-symlinks
+=item -L, --follow-symlinks
-Follow symlinks (except to directories) 00and count the size of the file
-they point to. Symlink loops and directories will be ignored.
+Follow symlinks and count the size of the file they point to. As of ncdu 1.14,
+this option will not follow symlinks to directories and will count each
+symlinked file as a unique file (i.e. unlike how hard links are handled). This
+is subject to change in later versions.
=back
diff --git a/src/dir_scan.c b/src/dir_scan.c
index 3ec508c..38068f1 100644
--- a/src/dir_scan.c
+++ b/src/dir_scan.c
@@ -185,7 +185,7 @@ static int dir_scan_recurse(const char *name) {
* directory. Assumes we're chdir'ed in the directory in which this item
* resides. */
static int dir_scan_item(const char *name) {
- struct stat st;
+ static struct stat st, stl;
int fail = 0;
#ifdef __CYGWIN__
@@ -204,14 +204,12 @@ static int dir_scan_item(const char *name) {
dir_setlasterr(dir_curpath);
}
- if(!(buf_dir->flags & (FF_ERR|FF_EXL)))
- stat_to_dir(&st);
-
- if (!(buf_dir->flags & (FF_ERR|FF_EXL)) && follow_symlinks && S_ISLNK(st.st_mode))
- if (!stat(name, &st)) {
- if (!S_ISDIR(st.st_mode))
- stat_to_dir(&st);
- }
+ if(!(buf_dir->flags & (FF_ERR|FF_EXL))) {
+ if(follow_symlinks && S_ISLNK(st.st_mode) && !stat(name, &stl) && !S_ISDIR(stl.st_mode))
+ stat_to_dir(&stl);
+ else
+ stat_to_dir(&st);
+ }
if(cachedir_tags && (buf_dir->flags & FF_DIR) && !(buf_dir->flags & (FF_ERR|FF_EXL|FF_OTHFS)))
if(has_cachedir_tag(buf_dir->name)) {