← Back to Pull requests

memfs: Reject ReadDir calls on regular files #247

Closed
unknown closed this pull request without merging on Oct 16, 2026 21:17 UTC
View on GitHub
unknown unknown commented on Oct 16, 2026 18:43 UTC
Author

memfs.ReadDir currently returns an empty result and no error for a regular file. Callers cannot distinguish that invalid directory path from an empty directory, unlike the OS-backed filesystem and the documented billy.Dir contract.

Return a *os.PathError wrapping syscall.ENOTDIR after resolving symlinks. The shared directory-conformance test compares the same call through memfs and osfs. A memfs regression also checks that a link to a file is rejected while a link to a directory remains readable.

Minimal reproduction:

fs := memfs.New()
f, err := fs.Create("file")
if err != nil {
    panic(err)
}
if err := f.Close(); err != nil {
    panic(err)
}
entries, err := fs.ReadDir("file")
fmt.Printf("entries=%v error=%v\n", entries, err)

Before: empty entries, nil error. After: nil entries and a non-nil path error. The OS-backed regression passed before the change; the memfs and symlink-to-file regressions failed before and pass after.

Validation on Windows / Go 1.26.8:

  • go test ./memfs -count=1

  • go test ./test -run '^TestDir_' -count=1

  • go vet ./memfs ./test, gofmt and git diff --check

  • Pinned golangci-lint 2.14.0: no newly introduced issues with --new-from-rev=eae82c9f2d37fb502d080eef0ab6bc1655501985.
  • Full-suite limitations were checked against a separate clean snapshot of the same upstream revision: both runs hit existing Windows symlink-privilege failures and the 45-second bound in the large TempFileMany stress test. Full lint reports unrelated findings in unchanged files on both snapshots; full vet flags the existing osfs.WriteTo signature. A full-suite pass or race-test pass is not claimed; the local C compiler could not start.

    AI assistance: OpenAI Codex (GPT-6) assisted with investigation, implementation, regression tests, validation and this description. The commit includes an Assisted-by trailer and DCO sign-off.

    Diff: 235 lines (+176 / -59) across 2 files Reviewer: pjbgf Review duration: 154m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 235 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.327
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #247"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37.1% (MEDIUM) · Higher = larger blast radius
    37.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.7% · Safe to merge
    14.7%