Skip to content

testing/fstest: TestFS: relax check ReadDir based on perms #63707

@dolmen

Description

@dolmen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions