Skip to content

Commit f66e656

Browse files
committed
df: follow symlinks
Signed-off-by: Alexander Bakanovskii <[email protected]>
1 parent 68a0369 commit f66e656

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/uu/df/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ path = "src/df.rs"
1919

2020
[dependencies]
2121
clap = { workspace = true }
22-
uucore = { workspace = true, features = ["libc", "fsext", "parser"] }
22+
uucore = { workspace = true, features = ["libc", "fsext", "parser", "fs"] }
2323
unicode-width = { workspace = true }
2424
thiserror = { workspace = true }
2525
fluent = { workspace = true }

src/uu/df/src/df.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,24 @@ fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
306306
}
307307

308308
let mut mounts = vec![];
309-
for mi in read_fs_list()? {
309+
for mut mi in read_fs_list()? {
310310
// TODO The running time of the `is_best()` function is linear
311311
// in the length of `result`. That makes the running time of
312312
// this loop quadratic in the length of `vmi`. This could be
313313
// improved by a more efficient implementation of `is_best()`,
314314
// but `vmi` is probably not very long in practice.
315315
if is_included(&mi, opt) && is_best(&mounts, &mi) {
316+
let dev_path: &Path = Path::new(&mi.dev_name);
317+
if dev_path.is_symlink() {
318+
if let Ok(canonicalized_symlink) = uucore::fs::canonicalize(
319+
dev_path,
320+
uucore::fs::MissingHandling::Existing,
321+
uucore::fs::ResolveMode::Logical,
322+
) {
323+
mi.dev_name = canonicalized_symlink.to_string_lossy().to_string();
324+
}
325+
}
326+
316327
mounts.push(mi);
317328
}
318329
}

0 commit comments

Comments
 (0)