mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
Merge pull request #8763 from bakanovskii/df-follow-symlinks
Some checks are pending
CICD / Style/cargo-deny (push) Waiting to run
CICD / Style/deps (push) Waiting to run
CICD / Documentation/warnings (push) Waiting to run
CICD / MinRustV (push) Waiting to run
CICD / Dependencies (push) Waiting to run
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Build/stable (push) Blocked by required conditions
CICD / Build/nightly (push) Blocked by required conditions
CICD / Binary sizes (push) Blocked by required conditions
CICD / Build (push) Blocked by required conditions
CICD / Tests/BusyBox test suite (push) Blocked by required conditions
CICD / Tests/Toybox test suite (push) Blocked by required conditions
CICD / Code Coverage (push) Waiting to run
CICD / Separate Builds (push) Waiting to run
CICD / Test all features separately (push) Blocked by required conditions
CICD / Build/SELinux (push) Blocked by required conditions
CICD / Run benchmarks (CodSpeed) (push) Blocked by required conditions
GnuTests / Run GNU tests (native) (push) Waiting to run
GnuTests / Run GNU tests (SELinux) (push) Waiting to run
GnuTests / Aggregate GNU test results (push) Blocked by required conditions
Android / Test builds (push) Waiting to run
Code Quality / Style/format (push) Waiting to run
Code Quality / Style/lint (push) Waiting to run
Code Quality / Style/spelling (push) Waiting to run
Code Quality / Style/toml (push) Waiting to run
Code Quality / Style/Python (push) Waiting to run
Code Quality / Pre-commit hooks (push) Waiting to run
Devcontainer / Verify devcontainer (push) Waiting to run
FreeBSD / Style and Lint (push) Waiting to run
FreeBSD / Tests (push) Waiting to run
WSL2 / Test (push) Waiting to run
Some checks are pending
CICD / Style/cargo-deny (push) Waiting to run
CICD / Style/deps (push) Waiting to run
CICD / Documentation/warnings (push) Waiting to run
CICD / MinRustV (push) Waiting to run
CICD / Dependencies (push) Waiting to run
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Build/stable (push) Blocked by required conditions
CICD / Build/nightly (push) Blocked by required conditions
CICD / Binary sizes (push) Blocked by required conditions
CICD / Build (push) Blocked by required conditions
CICD / Tests/BusyBox test suite (push) Blocked by required conditions
CICD / Tests/Toybox test suite (push) Blocked by required conditions
CICD / Code Coverage (push) Waiting to run
CICD / Separate Builds (push) Waiting to run
CICD / Test all features separately (push) Blocked by required conditions
CICD / Build/SELinux (push) Blocked by required conditions
CICD / Run benchmarks (CodSpeed) (push) Blocked by required conditions
GnuTests / Run GNU tests (native) (push) Waiting to run
GnuTests / Run GNU tests (SELinux) (push) Waiting to run
GnuTests / Aggregate GNU test results (push) Blocked by required conditions
Android / Test builds (push) Waiting to run
Code Quality / Style/format (push) Waiting to run
Code Quality / Style/lint (push) Waiting to run
Code Quality / Style/spelling (push) Waiting to run
Code Quality / Style/toml (push) Waiting to run
Code Quality / Style/Python (push) Waiting to run
Code Quality / Pre-commit hooks (push) Waiting to run
Devcontainer / Verify devcontainer (push) Waiting to run
FreeBSD / Style and Lint (push) Waiting to run
FreeBSD / Tests (push) Waiting to run
WSL2 / Test (push) Waiting to run
df: follow symlinks
This commit is contained in:
commit
4cab890676
3 changed files with 29 additions and 2 deletions
|
|
@ -19,7 +19,7 @@ path = "src/df.rs"
|
|||
|
||||
[dependencies]
|
||||
clap = { workspace = true }
|
||||
uucore = { workspace = true, features = ["libc", "fsext", "parser"] }
|
||||
uucore = { workspace = true, features = ["libc", "fsext", "parser", "fs"] }
|
||||
unicode-width = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
fluent = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -306,13 +306,24 @@ fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
|
|||
}
|
||||
|
||||
let mut mounts = vec![];
|
||||
for mi in read_fs_list()? {
|
||||
for mut mi in read_fs_list()? {
|
||||
// TODO The running time of the `is_best()` function is linear
|
||||
// in the length of `result`. That makes the running time of
|
||||
// this loop quadratic in the length of `vmi`. This could be
|
||||
// improved by a more efficient implementation of `is_best()`,
|
||||
// but `vmi` is probably not very long in practice.
|
||||
if is_included(&mi, opt) && is_best(&mounts, &mi) {
|
||||
let dev_path: &Path = Path::new(&mi.dev_name);
|
||||
if dev_path.is_symlink() {
|
||||
if let Ok(canonicalized_symlink) = uucore::fs::canonicalize(
|
||||
dev_path,
|
||||
uucore::fs::MissingHandling::Existing,
|
||||
uucore::fs::ResolveMode::Logical,
|
||||
) {
|
||||
mi.dev_name = canonicalized_symlink.to_string_lossy().to_string();
|
||||
}
|
||||
}
|
||||
|
||||
mounts.push(mi);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,6 +123,22 @@ fn test_df_output() {
|
|||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_follows_symlinks() {
|
||||
let output = new_ucmd!()
|
||||
.arg("-h")
|
||||
.arg("--output=source")
|
||||
.succeeds()
|
||||
.stdout_str_lossy();
|
||||
|
||||
let filesystems = output.lines().skip(1).collect::<Vec<&str>>();
|
||||
assert!(
|
||||
filesystems
|
||||
.iter()
|
||||
.all(|&x| !std::path::Path::new(x).is_symlink())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_output_overridden() {
|
||||
let expected = if cfg!(target_os = "macos") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue