Skip to content

shred: report the real error for an inaccessible file - #13640

Merged
sylvestre merged 1 commit into
uutils:mainfrom
0xfandom:shred-inaccessible-real-error
Jul 30, 2026
Merged

shred: report the real error for an inaccessible file#13640
sylvestre merged 1 commit into
uutils:mainfrom
0xfandom:shred-inaccessible-real-error

Conversation

@0xfandom

Copy link
Copy Markdown
Contributor

Fixes #13639.

shred's pre-checks used Path::exists() and Path::is_file(), both of which return false for any metadata access error, including a permission error. As a result, a file whose parent directory lacks search permission was reported as:

shred: locked/file: No such file or directory

even though it exists.

This replaces the two checks with a single fs::metadata() match:

  • a genuine ENOENT still yields "No such file or directory";
  • an existing non-file still yields "Not a file";
  • a metadata error such as a permission error now falls through to the open-for-writing path, which surfaces the real reason instead of masquerading as a missing file.

All the normal cases (missing file, dangling symlink, directory, regular file) keep their existing behaviour. Added a #[cfg(unix)] regression test that shreds a file inside a 0o000 directory and asserts the error mentions "Permission denied" and not "No such file"; it fails on the old Path::exists() code and passes with the fix. This mirrors the fix in #9789 (chmod).

shred used Path::exists() and Path::is_file() to pre-check the target, but both return false on any metadata error, so a file whose parent directory lacks search permission was reported as "No such file or directory". Inspect the metadata directly so a genuine ENOENT stays a not-found error while a permission error falls through to the open-for-writing path, which surfaces the real reason.
@codspeed-hq

codspeed-hq Bot commented Jul 29, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 24.47%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 344 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation df_with_path 305.3 µs 245.3 µs +24.47%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing 0xfandom:shred-inaccessible-real-error (8b695ce) with main (197eac4)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (was skipped on 'main', now failing)

@sylvestre
sylvestre merged commit d183a67 into uutils:main Jul 30, 2026
166 of 167 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants