mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Add a '--follow-symlinks' option
Symlink loops are handled by the stat(2) syscall. Symlinks pointing to a directory are ignored (to avoid loops in the recursive scan).
This commit is contained in:
parent
2409cc7a32
commit
74efdfaf97
4 changed files with 17 additions and 0 deletions
|
|
@ -172,6 +172,11 @@ displayed, but not their content, and they are not counted towards the disk
|
||||||
usage statistics.
|
usage statistics.
|
||||||
See http://www.brynosaurus.com/cachedir/
|
See http://www.brynosaurus.com/cachedir/
|
||||||
|
|
||||||
|
=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.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,12 @@ static int dir_scan_item(const char *name) {
|
||||||
if(!(buf_dir->flags & (FF_ERR|FF_EXL)))
|
if(!(buf_dir->flags & (FF_ERR|FF_EXL)))
|
||||||
stat_to_dir(&st);
|
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(cachedir_tags && (buf_dir->flags & FF_DIR) && !(buf_dir->flags & (FF_ERR|FF_EXL|FF_OTHFS)))
|
if(cachedir_tags && (buf_dir->flags & FF_DIR) && !(buf_dir->flags & (FF_ERR|FF_EXL|FF_OTHFS)))
|
||||||
if(has_cachedir_tag(buf_dir->name)) {
|
if(has_cachedir_tag(buf_dir->name)) {
|
||||||
buf_dir->flags |= FF_EXL;
|
buf_dir->flags |= FF_EXL;
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,8 @@ extern int cachedir_tags;
|
||||||
extern int confirm_quit;
|
extern int confirm_quit;
|
||||||
/* flag whether we want to enable use of struct dir_ext */
|
/* flag whether we want to enable use of struct dir_ext */
|
||||||
extern int extended_info;
|
extern int extended_info;
|
||||||
|
/* flag whether we want to follow symlinks */
|
||||||
|
extern int follow_symlinks;
|
||||||
|
|
||||||
/* handle input from keyboard and update display */
|
/* handle input from keyboard and update display */
|
||||||
int input_handle(int);
|
int input_handle(int);
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ int read_only = 0;
|
||||||
long update_delay = 100;
|
long update_delay = 100;
|
||||||
int cachedir_tags = 0;
|
int cachedir_tags = 0;
|
||||||
int extended_info = 0;
|
int extended_info = 0;
|
||||||
|
int follow_symlinks = 0;
|
||||||
|
|
||||||
static int min_rows = 17, min_cols = 60;
|
static int min_rows = 17, min_cols = 60;
|
||||||
static int ncurses_init = 0;
|
static int ncurses_init = 0;
|
||||||
|
|
@ -132,6 +133,7 @@ static void argv_parse(int argc, char **argv) {
|
||||||
{ '2', 0, "-2" },
|
{ '2', 0, "-2" },
|
||||||
{ 1, 1, "--exclude" },
|
{ 1, 1, "--exclude" },
|
||||||
{ 'X', 1, "-X,--exclude-from" },
|
{ 'X', 1, "-X,--exclude-from" },
|
||||||
|
{ 'L', 0, "-L,--follow-symlinks" },
|
||||||
{ 'C', 0, "--exclude-caches" },
|
{ 'C', 0, "--exclude-caches" },
|
||||||
{ 's', 0, "--si" },
|
{ 's', 0, "--si" },
|
||||||
{ 'Q', 0, "--confirm-quit" },
|
{ 'Q', 0, "--confirm-quit" },
|
||||||
|
|
@ -160,6 +162,7 @@ static void argv_parse(int argc, char **argv) {
|
||||||
printf(" --si Use base 10 (SI) prefixes instead of base 2\n");
|
printf(" --si Use base 10 (SI) prefixes instead of base 2\n");
|
||||||
printf(" --exclude PATTERN Exclude files that match PATTERN\n");
|
printf(" --exclude PATTERN Exclude files that match PATTERN\n");
|
||||||
printf(" -X, --exclude-from FILE Exclude files that match any pattern in FILE\n");
|
printf(" -X, --exclude-from FILE Exclude files that match any pattern in FILE\n");
|
||||||
|
printf(" -L, --follow-symlinks Follow symbolic links (excluding directories)\n");
|
||||||
printf(" --exclude-caches Exclude directories containing CACHEDIR.TAG\n");
|
printf(" --exclude-caches Exclude directories containing CACHEDIR.TAG\n");
|
||||||
printf(" --confirm-quit Confirm quitting ncdu\n");
|
printf(" --confirm-quit Confirm quitting ncdu\n");
|
||||||
printf(" --color SCHEME Set color scheme\n");
|
printf(" --color SCHEME Set color scheme\n");
|
||||||
|
|
@ -185,6 +188,7 @@ static void argv_parse(int argc, char **argv) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'L': follow_symlinks = 1; break;
|
||||||
case 'C':
|
case 'C':
|
||||||
cachedir_tags = 1;
|
cachedir_tags = 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue