Report io.EOF from UnionFile.ReadAt - #653
Open
youdie006 wants to merge 1 commit into
Open
Conversation
ReadAt overwrote the layer's error with the result of the base seek, so a short read came back with a nil error. Read already guards the seek for exactly this reason; ReadAt now does the same.
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.
UnionFile.ReadAtreturns a nil error on a short read, so callers that rely onio.EOFto stopnever do.
io.ReaderAt, verbatim from$GOROOT/src/io/io.go:210:Same calls through three implementations, 10-byte file:
The
(0, nil)case is what bites in practice.io.NewSectionReader— the natural thing to writewhen the exact size is not known — cannot terminate:
Both of the other columns are afero's own code, so this is not an os-vs-mem difference.
Cause
unionFile.go:70:The assignment replaces the layer's
io.EOFwith the seek's nil.Read, sixteen lines above, getsthis right and carries the comment saying why:
Change
Five lines, mirroring
Read. A test is added tocomposite_test.gocovering the short read and theread at EOF. Red with only
unionFile.goreverted:Green with the change;
go test ./...passes across all packages andgofmt -llists neither file.Reachable through the public API via
NewCacheOnReadFs(base, layer, 0).OpenFile(name, os.O_RDWR, perm), which returns a*UnionFile(cacheOnReadFs.go:233).Disclosure: prepared with AI assistance; I verified the three-way comparison, the section-reader
behaviour and the red/green runs myself.