-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Description
TL;DR
Drop one false positive case in testing/fstest.TestFS: it is ok for ReadDir to return ErrPermission if the fs.FileMode of the file says some users are not allowed to read the directory.
Context
With io/fs.FS, there is no way to select which permission bits (fs.FileMode) apply when reading a file. So fstest.TestFS has no way to enforce that given a FileMode's file/directory based on user/group/others permission bits, Open, ReadFile or ReadDir should trigger or not an fs.ErrPermission.
Currently any error (including ErrPermission) on ReadDir is always considered an error. However returning fs.ErrPermission is correct behaviour if the filesystem enforces fs.FileMode and the directory has read permissions bits off.
Proposal
I propose that TestFS to ignore ErrPermission on ReadDir if at least one read permission bit is not set: ignore ErrPermission (and silently skip other ReadDir checks) if mode & 0444 != 0444.
Impact
This change will only drop some returned errors and will never raise more errors, so backward compatibility is preserved.