Skip to content

Commit

Permalink
fix(symlink): fix --dereference --sort=size
Browse files Browse the repository at this point in the history
 `File::length()` did not take `--dereference` into account, and used
 symlink metadata unconditionally.

 This commit fixes that.

Signed-off-by: Mohammad AlSaleh <[email protected]>
  • Loading branch information
MoSal committed May 17, 2024
1 parent bbede6d commit b8a481e
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,12 @@ impl<'dir> File<'dir> {
/// of a directory when `total_size` is used.
#[inline]
pub fn length(&self) -> u64 {
self.recursive_size.unwrap_bytes_or(self.metadata.len())
self.recursive_size.unwrap_bytes_or(
match (self.is_link(), self.deref_links, self.link_target_recurse()) {
(true, true, FileTarget::Ok(f)) => f.metadata.len(),
_ => self.metadata.len(),
},
)
}

/// Is the file is using recursive size calculation
Expand Down
10 changes: 10 additions & 0 deletions tests/cmd/absolute_recurse_unix.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[CWD]/tests/itest/b
[CWD]/tests/itest/c
[CWD]/tests/itest/d
[CWD]/tests/itest/dereferenced-sort-size
[CWD]/tests/itest/dir-symlink -> vagrant/debug
[CWD]/tests/itest/e
[CWD]/tests/itest/exa
Expand All @@ -21,6 +22,15 @@
[CWD]/tests/itest/q
[CWD]/tests/itest/vagrant

tests/itest/dereferenced-sort-size:
[CWD]/tests/itest/dereferenced-sort-size/links
[CWD]/tests/itest/dereferenced-sort-size/longgggggggggggggg-name-smaller-size
[CWD]/tests/itest/dereferenced-sort-size/short-name-larger-size

tests/itest/dereferenced-sort-size/links:
[CWD]/tests/itest/dereferenced-sort-size/links/a -> ../longgggggggggggggg-name-smaller-size
[CWD]/tests/itest/dereferenced-sort-size/links/b -> ../short-name-larger-size

tests/itest/exa:
[CWD]/tests/itest/exa/file.c -> djihisudjuhfius
[CWD]/tests/itest/exa/sssssssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
Expand Down
1 change: 1 addition & 0 deletions tests/cmd/absolute_unix.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[CWD]/tests/itest/b
[CWD]/tests/itest/c
[CWD]/tests/itest/d
[CWD]/tests/itest/dereferenced-sort-size
[CWD]/tests/itest/dir-symlink -> vagrant/debug
[CWD]/tests/itest/e
[CWD]/tests/itest/exa
Expand Down
1 change: 1 addition & 0 deletions tests/cmd/basic_all.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ a
b
c
d
dereferenced-sort-size
dir-symlink -> vagrant/debug
e
exa
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions tests/cmd/dereferenced_sort_size_unix.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a
b
2 changes: 2 additions & 0 deletions tests/cmd/dereferenced_sort_size_unix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.name = "eza"
args = "tests/itest/dereferenced-sort-size/links -1 --sort=size --dereference"
1 change: 1 addition & 0 deletions tests/cmd/icons_all.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
 b
 c
 d
 dereferenced-sort-size
 dir-symlink -> vagrant/debug
 e
 exa
Expand Down
1 change: 1 addition & 0 deletions tests/cmd/long_windows.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-a--- b
-a--- c
-a--- d
d---- dereferenced-sort-size
l---- dir-symlink -> vagrant/debug
-a--- e
d---- exa
Expand Down
1 change: 1 addition & 0 deletions tests/itest/dereferenced-sort-size/links/a
1 change: 1 addition & 0 deletions tests/itest/dereferenced-sort-size/links/b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12345
1 change: 1 addition & 0 deletions tests/itest/dereferenced-sort-size/short-name-larger-size
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234567890

0 comments on commit b8a481e

Please sign in to comment.