Skip to content

Commit

Permalink
Truly don't follow symlinks unless they are the only top-level path.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Byron committed Mar 27, 2020
1 parent 2bbbb0b commit 768cbce
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
55 changes: 30 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,68 @@
#### ✅ v2.3.8 `dua interactive` (`dua i`) is now about twice as fast due to using all logical cores, not just physical ones
#### v2.3.9 Do not follow symlinks unless it's the only root path to follow

This brutally fixes an issue where symbolics links are honored when they are placed in the current working directory, as internally `dua` will
treat each cwd directory entry as individual root path.

#### v2.3.8 `dua interactive` (`dua i`) is now about twice as fast due to using all logical cores, not just physical ones

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

#### v2.3.7 Upgrade to filesize 0.2.0 from 0.1.0; update dependency versions
#### v2.3.7 Upgrade to filesize 0.2.0 from 0.1.0; update dependency versions

#### v2.3.6 Upgrade to jwalk 0.5 bringing better threading control and no symlink following during traversal
#### v2.3.6 Upgrade to jwalk 0.5 bringing better threading control and no symlink following during traversal

#### v2.3.5 Fast exit from interactive mode for a responsive exit; dependency updates (except jwalk)
#### v2.3.5 Fast exit from interactive mode for a responsive exit; dependency updates (except jwalk)

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

#### v2.3.3 YANKED - journey tests failed to changed method signature
#### v2.3.3 YANKED - journey tests failed to changed method signature

#### v2.3.2 Incude the license file in crate
#### v2.3.2 Incude the license file in crate

#### v2.3.1 Include .md files in Crate, update dependencies
#### v2.3.1 Include .md files in Crate, update dependencies

#### v2.3 Show size on disk by default; Dependency Update
#### v2.3 Show size on disk by default; Dependency Update

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

And of course, this has no noticable performance impact.

#### v2.2 Show size on disk by default; Dependency Update
#### v2.2 Show size on disk by default; Dependency Update

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

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

#### v2.1.13-- Dependency Update; Github Releases
#### v2.1.13-- Dependency Update; Github Releases

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

#### v2.1.12-- More obvious highlighting of active panel
#### v2.1.12-- More obvious highlighting of active panel

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

#### v2.1.11 - Finally fix symlink handling
#### v2.1.11 - Finally fix symlink handling

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

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

#### v2.1.10 - compatibility with light terminals
#### v2.1.10 - compatibility with light terminals

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

#### v2.1.9 - improved handling of broken symlinks
#### v2.1.9 - improved handling of broken symlinks

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

#### v2.1.8 - don't follow symbolic links when deleting directories
#### v2.1.8 - don't follow symbolic links when deleting directories

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

This is now fixed.

#### v2.1.7 - use latest version of open-rs
#### v2.1.7 - use latest version of open-rs

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

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

#### v2.1.5 - re-release with Cargo.lock
#### v2.1.5 - re-release with Cargo.lock

#### v2.1.2 bug fixes and improvements
#### v2.1.2 bug fixes and improvements

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

#### v2.1.1 bug fixes and improvements
#### v2.1.1 bug fixes and improvements

* Better information about deletion progress
* removal of windows support

#### v2.1.0- bug fixes and improvements
#### v2.1.0- bug fixes and improvements

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

#### v2.0.1- bug fixes and improvements
#### v2.0.1- bug fixes and improvements

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

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

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

##### Other Features

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

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

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

#### ✅v1.0 (_released_) - aggregate directories, fast
#### 1.0 (_released_) - aggregate directories, fast

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.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dua-cli"
version = "2.3.8"
version = "2.3.9"
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
edition = "2018"
include = ["src/**/*", "Cargo.*", "*.md", "LICENSE"]
Expand Down
10 changes: 10 additions & 0 deletions src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ pub fn aggregate(
let mut num_roots = 0;
let mut aggregates = Vec::new();
let mut inodes = InodeFilter::default();
let paths: Vec<_> = paths.into_iter().collect();
let input_len = paths.len();
for path in paths.into_iter() {
// For now, bluntly ignore symlinks that are on the top-level, and there are more roots to follow
if input_len > 1 {
if let Ok(meta) = path.as_ref().symlink_metadata() {
if meta.file_type().is_symlink() {
continue;
}
}
}
num_roots += 1;
let mut num_bytes = 0u64;
let mut num_errors = 0u64;
Expand Down
21 changes: 14 additions & 7 deletions src/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ impl Traversal {
// Also means that we will spin up a bunch of threads per root path, instead of reusing them.
walk_options.threads = num_cpus::get();
}
let input_len = input.len();
for path in input.into_iter() {
// For now, bluntly ignore symlinks that are on the top-level, and there are more roots to follow
if input_len > 1 {
if let Ok(meta) = path.symlink_metadata() {
if meta.file_type().is_symlink() {
continue;
}
}
}
let mut last_seen_eid = 0;
for (eid, entry) in walk_options
.iter_from_path(path.as_ref())
Expand All @@ -102,13 +111,11 @@ impl Traversal {
if walk_options.apparent_size {
m.len()
} else {
data.name.size_on_disk_fast(m).unwrap_or_else(
|_| {
t.io_errors += 1;
data.metadata_io_error = true;
0
},
)
data.name.size_on_disk_fast(m).unwrap_or_else(|_| {
t.io_errors += 1;
data.metadata_io_error = true;
0
})
}
}
Some(Ok(_)) => 0,
Expand Down

0 comments on commit 768cbce

Please sign in to comment.