ccfos / ccfos/huatuo

[Bug]: localfile storage ignores non-ENOENT directory stat errors

Open Beginner friendly
#802 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.1k
Forks
139
Avg merge
3d 16h
Merged PRs (30d)
18

Description

**Problem**
`Storage.writerByName` calls `os.Stat` on the configured directory but only handles `os.IsNotExist`. Other stat errors (permission denied, invalid path, ENOTDIR) are silently discarded, and the method returns a lazy writer with a nil error. The actual failure is deferred until the first `Write`, or may be reported in a confusing place.

**Evidence**
`internal/storage/localfile/localfile.go`:
```go
if _, err := os.Stat(b.path); os.IsNotExist(err) {
if mkdirErr := os.MkdirAll(b.path, 0o755); mkdirErr != nil {
return nil, mkdirErr
}
}
```
A non-ENOENT error reaches `newFileWriter` with no validation, so `writerByName` returns `(writer, nil)`.

**Expected behavior**
`writerByName` should return any non-ENOENT `os.Stat` error immediately, just as it already does for `MkdirAll` failures.

**Test plan**
- Add a regression test in `internal/storage/localfile` that creates a backend path whose stat returns a non-ENOENT error and asserts `writerByName` returns a non-nil error.
- Run `gofmt`, `git diff --check`, and `go test -mod=vendor ./internal/storage/localfile`.

Contributor guide

Open the contributing guide

Research direction

Start at writerByName in internal/storage/localfile/localfile.go and review the existing os.Stat and MkdirAll handling. Add a regression test in internal/storage/localfile for a non-ENOENT stat error, then run gofmt, git diff --check, and go test -mod=vendor ./internal/storage/localfile. Done means writerByName returns the stat error immediately.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.