Skip to content

shred reports "No such file or directory" for an inaccessible file #13639

Description

@0xfandom

Description

shred reports "No such file or directory" for a file that actually exists but whose metadata cannot be read because its parent directory lacks search permission.

In src/uu/shred/src/shred.rs, the pre-checks use Path::exists() and Path::is_file():

if !path.exists() {
    return Err(... "No such file or directory" ...);
}
if !path.is_file() {
    return Err(... "Not a file" ...);
}

Both return false for any metadata error, including a permission error, so an inaccessible file is misclassified as missing.

Reproduction

$ mkdir locked && touch locked/file && chmod 000 locked
$ target/debug/coreutils shred locked/file
shred: locked/file: No such file or directory      # wrong
# GNU reports the real error instead:
$ shred locked/file
shred: locked/file: failed to open for writing: Permission denied

Expected

shred should surface the real error (a permission error), not claim the file does not exist.

This is the same Path::exists() misclassification as #9789 (chmod).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions