feature: Support for dereference links -L follow

du has -L flag which allows it to dereference or follow
symlinks. Clone this feature into dust.
https://github.com/bootandy/dust/issues/276
This commit is contained in:
andy.boot
2023-01-07 14:04:14 +00:00
parent a3ab5bfe0f
commit abcc46c5ea
8 changed files with 19 additions and 3 deletions
+7 -1
View File
@@ -33,6 +33,12 @@ pub fn build_cli() -> Command<'static> {
.number_of_values(1)
.multiple_occurrences(true)
.help("Exclude any file or directory with this name"),
)
.arg(
Arg::new("dereference_links")
.short('L')
.long("dereference-links")
.help("dereference sym links - Treat sym links as directories and go into them"),
)
.arg(
Arg::new("limit_filesystem")
@@ -136,6 +142,6 @@ pub fn build_cli() -> Command<'static> {
Arg::new("only_dir")
.short('D')
.long("only-dir")
.help("Only directories will be displayed."),
.help("Only directories will be displayed."),
)
}
+2 -1
View File
@@ -26,6 +26,7 @@ pub struct WalkData<'a> {
pub use_apparent_size: bool,
pub by_filecount: bool,
pub ignore_hidden: bool,
pub follow_links: bool,
}
pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: WalkData) -> (Vec<Node>, bool) {
@@ -144,7 +145,7 @@ fn walk(
if !ignore_file(entry, walk_data) {
if let Ok(data) = entry.file_type() {
return if data.is_dir() && !data.is_symlink() {
return if data.is_dir() || (walk_data.follow_links && data.is_symlink()) {
walk(entry.path(), permissions_flag, walk_data, depth + 1)
} else {
build_node(
+2
View File
@@ -154,6 +154,7 @@ fn main() {
let by_filecount = options.is_present("by_filecount");
let limit_filesystem = options.is_present("limit_filesystem");
let follow_links = options.is_present("dereference_links");
let simplified_dirs = simplify_dir_names(target_dirs);
let allowed_filesystems = limit_filesystem
@@ -172,6 +173,7 @@ fn main() {
use_apparent_size: config.get_apparent_size(&options),
by_filecount,
ignore_hidden: config.get_ignore_hidden(&options),
follow_links,
};
let _rayon = init_rayon();