Skip to content

Commit 768cbce

Browse files
committed
Truly don't follow symlinks unless they are the only top-level path.
This is a brute-force hack which won't show them at all, there certainly is better ways if we would know if we expanded paths ourselves or not.
1 parent 2bbbb0b commit 768cbce

File tree

5 files changed

+56
-34
lines changed

5 files changed

+56
-34
lines changed

CHANGELOG.md

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,68 @@
1-
#### ✅ v2.3.8 `dua interactive` (`dua i`) is now about twice as fast due to using all logical cores, not just physical ones
1+
#### v2.3.9 Do not follow symlinks unless it's the only root path to follow
2+
3+
This brutally fixes an issue where symbolics links are honored when they are placed in the current working directory, as internally `dua` will
4+
treat each cwd directory entry as individual root path.
5+
6+
#### v2.3.8 `dua interactive` (`dua i`) is now about twice as fast due to using all logical cores, not just physical ones
27

38
This is also the first release with github releases: https://github.com/Byron/dua-cli/releases/tag/v2.3.8
49

5-
#### v2.3.7 Upgrade to filesize 0.2.0 from 0.1.0; update dependency versions
10+
#### v2.3.7 Upgrade to filesize 0.2.0 from 0.1.0; update dependency versions
611

7-
#### v2.3.6 Upgrade to jwalk 0.5 bringing better threading control and no symlink following during traversal
12+
#### v2.3.6 Upgrade to jwalk 0.5 bringing better threading control and no symlink following during traversal
813

9-
#### v2.3.5 Fast exit from interactive mode for a responsive exit; dependency updates (except jwalk)
14+
#### v2.3.5 Fast exit from interactive mode for a responsive exit; dependency updates (except jwalk)
1015

11-
#### v2.3.4 YANKED - jwalk 0.5.0 wasn't used correctly which led to a performance regression
16+
#### v2.3.4 YANKED - jwalk 0.5.0 wasn't used correctly which led to a performance regression
1217

13-
#### v2.3.3 YANKED - journey tests failed to changed method signature
18+
#### v2.3.3 YANKED - journey tests failed to changed method signature
1419

15-
#### v2.3.2 Incude the license file in crate
20+
#### v2.3.2 Incude the license file in crate
1621

17-
#### v2.3.1 Include .md files in Crate, update dependencies
22+
#### v2.3.1 Include .md files in Crate, update dependencies
1823

19-
#### v2.3 Show size on disk by default; Dependency Update
24+
#### v2.3 Show size on disk by default; Dependency Update
2025

2126
Thanks to [this PR](https://github.com/Byron/dua-cli/pull/37), hard links are now not counted anymore.
2227
The `-l` flag will count hard links as it did before.
2328

2429
And of course, this has no noticable performance impact.
2530

26-
#### v2.2 Show size on disk by default; Dependency Update
31+
#### v2.2 Show size on disk by default; Dependency Update
2732

2833
Thanks to [this PR](https://github.com/Byron/dua-cli/pull/35), the old apparent size can be displayed with the
2934
`-A` flag, and the much more useful 'size on disk' is now shown by default.
3035

3136
To my pleasant surprise, this does not seem to affect performance at all - everything stays speedy.
3237

33-
#### v2.1.13-- Dependency Update; Github Releases
38+
#### v2.1.13-- Dependency Update; Github Releases
3439

3540
Binaries for Linux and MacOS are now available on GitHub Releases.
3641

37-
#### v2.1.12-- More obvious highlighting of active panel
42+
#### v2.1.12-- More obvious highlighting of active panel
3843

3944
Depending on the terminal used, it might not have been obvious which panel was active. This might be
4045
confusing to new and current users.
4146
Now the color of the widget frame is changed to light gray, instead of remaining gray.
4247

43-
#### v2.1.11 - Finally fix symlink handling
48+
#### v2.1.11 - Finally fix symlink handling
4449

4550
`dua` will not follow symbolic links when deleting directories. Thank a ton, @vks!
4651

4752
_Technical Notes_: Handling symbolic links properly is impossible without usage of `symlink_metadata()`.
4853

49-
#### v2.1.10 - compatibility with light terminals
54+
#### v2.1.10 - compatibility with light terminals
5055

5156
* the TUI is now usable on light terminals, and highlighting is more consistent. Thank you, @vks!
5257
* Fixes misaligned columns when displaying '100.00%' alongside other rows by displaying `100.0%` instead. Thanks, @vks, for pointing it out.
5358

54-
#### v2.1.9 - improved handling of broken symlinks
59+
#### v2.1.9 - improved handling of broken symlinks
5560

5661
* during symlink deletion, now broken symlinks will be deleted as expected.
5762
* always return to the previous terminal screen so the TUI doesn't stick to the current one.
5863
* display broken symlinks on the first level of iteration.
5964

60-
#### v2.1.8 - don't follow symbolic links when deleting directories
65+
#### v2.1.8 - don't follow symbolic links when deleting directories
6166

6267
[A critical bug was discovered](https://github.com/Byron/dua-cli/issues/24) which would lead to deletion
6368
of unwanted `directories` as `dua` would follow symbolic links during traversal during deletion.
@@ -66,50 +71,50 @@ Please note that symbolic links to files would be treated correctly, only removi
6671

6772
This is now fixed.
6873

69-
#### v2.1.7 - use latest version of open-rs
74+
#### v2.1.7 - use latest version of open-rs
7075

7176
That way, pressing `shift + O` to open the currently selected file won't possibly spam the terminal
7277
with messages caused by the program used to find the system program to open the file.
7378

7479
Fixes [#14](https://github.com/Byron/dua-cli/issues/14)
7580

76-
#### v2.1.5 - re-release with Cargo.lock
81+
#### v2.1.5 - re-release with Cargo.lock
7782

78-
#### v2.1.2 bug fixes and improvements
83+
#### v2.1.2 bug fixes and improvements
7984

8085
* Performance fix when showing folders with large amounts of files
8186
* Display of amount of entries per directory
8287

83-
#### v2.1.1 bug fixes and improvements
88+
#### v2.1.1 bug fixes and improvements
8489

8590
* Better information about deletion progress
8691
* removal of windows support
8792

88-
#### v2.1.0- bug fixes and improvements
93+
#### v2.1.0- bug fixes and improvements
8994

9095
* windows support (never actually worked), usage of crossterm is difficult thanks to completely
9196
different input handling.
9297
* additional key-bindings
9398
* auto-restore previous selection in each visited directory
9499

95-
#### v2.0.1- bug fixes and improvements
100+
#### v2.0.1- bug fixes and improvements
96101

97102
* fix typo in title
98103
* better display of IO-Errors in aggregate mode
99104

100-
#### v2.0.0 - interactive visualization of directory sizes with an option to queue their deletion
105+
#### v2.0.0 - interactive visualization of directory sizes with an option to queue their deletion
101106

102107
A sub-command bringing up a terminal user interface to allow drilling into directories, and clearing them out, all using the keyboard exclusively.
103108

104109
##### Other Features
105110

106111
* [x] Single Unit Mode, see [reddit](https://www.reddit.com/r/rust/comments/bvjtan/introducing_dua_a_parallel_du_for_humans/epsroxg/)
107112

108-
#### ✅v1.2 (_released_) - - the first usable, read-only interactive terminal user interface
113+
#### 1.2 (_released_) - - the first usable, read-only interactive terminal user interface
109114

110115
That's that. We also use `tui-react`, something that makes it much more pleasant to handle the
111116
application and GUI state.
112117

113-
#### ✅v1.0 (_released_) - aggregate directories, fast
118+
#### 1.0 (_released_) - aggregate directories, fast
114119

115120
Simple CLI to list top-level directories similar to sn-sort, but faster and more tailored to getting an idea of where most space is used.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dua-cli"
3-
version = "2.3.8"
3+
version = "2.3.9"
44
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
55
edition = "2018"
66
include = ["src/**/*", "Cargo.*", "*.md", "LICENSE"]

src/aggregate.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ pub fn aggregate(
2222
let mut num_roots = 0;
2323
let mut aggregates = Vec::new();
2424
let mut inodes = InodeFilter::default();
25+
let paths: Vec<_> = paths.into_iter().collect();
26+
let input_len = paths.len();
2527
for path in paths.into_iter() {
28+
// For now, bluntly ignore symlinks that are on the top-level, and there are more roots to follow
29+
if input_len > 1 {
30+
if let Ok(meta) = path.as_ref().symlink_metadata() {
31+
if meta.file_type().is_symlink() {
32+
continue;
33+
}
34+
}
35+
}
2636
num_roots += 1;
2737
let mut num_bytes = 0u64;
2838
let mut num_errors = 0u64;

src/traverse.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ impl Traversal {
7878
// Also means that we will spin up a bunch of threads per root path, instead of reusing them.
7979
walk_options.threads = num_cpus::get();
8080
}
81+
let input_len = input.len();
8182
for path in input.into_iter() {
83+
// For now, bluntly ignore symlinks that are on the top-level, and there are more roots to follow
84+
if input_len > 1 {
85+
if let Ok(meta) = path.symlink_metadata() {
86+
if meta.file_type().is_symlink() {
87+
continue;
88+
}
89+
}
90+
}
8291
let mut last_seen_eid = 0;
8392
for (eid, entry) in walk_options
8493
.iter_from_path(path.as_ref())
@@ -102,13 +111,11 @@ impl Traversal {
102111
if walk_options.apparent_size {
103112
m.len()
104113
} else {
105-
data.name.size_on_disk_fast(m).unwrap_or_else(
106-
|_| {
107-
t.io_errors += 1;
108-
data.metadata_io_error = true;
109-
0
110-
},
111-
)
114+
data.name.size_on_disk_fast(m).unwrap_or_else(|_| {
115+
t.io_errors += 1;
116+
data.metadata_io_error = true;
117+
0
118+
})
112119
}
113120
}
114121
Some(Ok(_)) => 0,

0 commit comments

Comments
 (0)