ls: contain PermissionError on stat and readdir - #12
Open
ninowalker wants to merge 1 commit into
Open
Conversation
A backend that refuses stat raises PermissionError, which ls let escape bash.exec() as a Python exception where cat and stat fail the command in-band. Catch it on the operand and on per-entry stats; readdir already handled it.
ninowalker
force-pushed
the
fix/ls-permission-denied
branch
from
September 7, 2026 14:15
f474ea3 to
50fae16
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Discovered while developing. Companion to #10 and #11 — same family, found the same way, by hitting it.
The problem
lscatchesFileNotFoundErroron its operand'sstatandPermissionErroronreaddir, but a backend whosestatraisesPermissionErrorescapesbash.exec()as a Python exception.catandstatfail the same backend in-band:ls -lhas the same gap on per-entrystat: a child whose stat refuses escapes mid-listing, where a vanished child already renders as?????????.The change
stat:except PermissionErroralongsideFileNotFoundError—ls: cannot access 'PATH': Permission denied, exit 2.statin the-l,-1 -F, and plain-Fpaths:PermissionErrorjoinsFileNotFoundError(placeholder row / skip), so one denied child no longer aborts the listing.readdiralready caughtPermissionError; untouched.A sweep found this is not just ls
Running every non-network command against a backend that denies
/deniedonstat/readdir/read, the same gap is in 32 other commands (head, tail, wc, sort, md5sum, awk, find, du, tree, touch, bash, sh, ...). Those raise for the same reason ls did: the read/stat call catchesFileNotFoundErrorbut notPermissionError. #11 contains them all at the boundary; this PR gives ls the coreutils-consistent message the issue asked for. The others can take the same one-line treatment if you'd like them to.Tests
tests/test_commands/test_minor_commands.py— aDenyingFsbackend and four tests: denied operand (plain and-l) reportscannot accesswith exit 2, deniedreaddirstays in-band, and a denied child renders as?????????without aborting the listing.ruff checkon the touched files: the 5 pre-existing findings inls.pybefore and after; the test file is clean.