mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
Merge pull request #8631 from cakebaker/du_some_small_refactorings
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/nightly (push) Blocked by required conditions
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Build/stable (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
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/nightly (push) Blocked by required conditions
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Build/stable (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
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
du: some small refactorings
This commit is contained in:
commit
7ca62d620e
1 changed files with 12 additions and 29 deletions
|
|
@ -166,11 +166,7 @@ impl Stat {
|
|||
|
||||
/// Create a Stat using safe traversal methods with `DirFd` for the root directory
|
||||
#[cfg(target_os = "linux")]
|
||||
fn new_from_dirfd(
|
||||
dir_fd: &DirFd,
|
||||
full_path: &Path,
|
||||
_options: &TraversalOptions,
|
||||
) -> std::io::Result<Self> {
|
||||
fn new_from_dirfd(dir_fd: &DirFd, full_path: &Path) -> std::io::Result<Self> {
|
||||
// Get metadata for the directory itself using fstat
|
||||
let safe_metadata = dir_fd.metadata()?;
|
||||
|
||||
|
|
@ -361,7 +357,7 @@ fn safe_du(
|
|||
Err(_e) => {
|
||||
// Try using our new DirFd method for the root directory
|
||||
match DirFd::open(path) {
|
||||
Ok(dir_fd) => match Stat::new_from_dirfd(&dir_fd, path, options) {
|
||||
Ok(dir_fd) => match Stat::new_from_dirfd(&dir_fd, path) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
let error = e.map_err_context(
|
||||
|
|
@ -446,23 +442,19 @@ fn safe_du(
|
|||
// Handle symlinks with -L option
|
||||
// For safe traversal with -L, we skip symlinks to directories entirely
|
||||
// and let the non-safe traversal handle them at the top level
|
||||
let (entry_stat, is_dir) = if is_symlink && options.dereference == Deref::All {
|
||||
if is_symlink && options.dereference == Deref::All {
|
||||
// Skip symlinks to directories when using safe traversal with -L
|
||||
// They will be handled by regular traversal
|
||||
continue;
|
||||
} else {
|
||||
let is_dir = (lstat.st_mode & S_IFMT) == S_IFDIR;
|
||||
(lstat, is_dir)
|
||||
};
|
||||
}
|
||||
|
||||
let file_info = if entry_stat.st_ino != 0 {
|
||||
Some(FileInfo {
|
||||
file_id: entry_stat.st_ino as u128,
|
||||
dev_id: entry_stat.st_dev,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let is_dir = (lstat.st_mode & S_IFMT) == S_IFDIR;
|
||||
let entry_stat = lstat;
|
||||
|
||||
let file_info = (entry_stat.st_ino != 0).then_some(FileInfo {
|
||||
file_id: entry_stat.st_ino as u128,
|
||||
dev_id: entry_stat.st_dev,
|
||||
});
|
||||
|
||||
// For safe traversal, we need to handle stats differently
|
||||
// We can't use std::fs::Metadata since that requires the full path
|
||||
|
|
@ -723,18 +715,9 @@ fn du_regular(
|
|||
}
|
||||
}
|
||||
Err(e) => {
|
||||
// Check if this is the "too many symlinks" error we want to catch
|
||||
if e.kind() == std::io::ErrorKind::InvalidData
|
||||
&& e.to_string().contains("Too many levels")
|
||||
{
|
||||
print_tx.send(Err(e.map_err_context(
|
||||
print_tx.send(Err(e.map_err_context(
|
||||
|| translate!("du-error-cannot-access", "path" => entry_path.quote()),
|
||||
)))?;
|
||||
} else {
|
||||
print_tx.send(Err(e.map_err_context(
|
||||
|| translate!("du-error-cannot-access", "path" => entry_path.quote()),
|
||||
)))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue