Repository navigation
A file whose copy fails part of the way is no longer left in the image: Close wrote it at its declared size over bytes it did not have - #311
Open
closer-claudio wants to merge 2 commits into
Conversation
With a data file, CopyFrom read a regular file to the end of its reader and recorded what it had read as the file's size. Without one, Close stops at the size the source declared and fails on a short read. The two stored different files from one source: a file declared 10 bytes that read as a megabyte was 10 bytes in the image and 1048576 with a data file, all of them written to it, and a reader that never ended filled the data file. A file that read shorter than it declared was stored short, without an error. CopyFrom now reads the declared size and no more into the data file, and fails with io.ErrUnexpectedEOF on a file that ends before it, as Close does without a data file. mkfs.erofs copies the size it found the file with and fails on fewer (lib/inode.c, erofs_write_unencoded_file: i_size is st_size, and a tail read short of it is -EIO), read and not run. The other reader a copy stores in a data file, a holed file's data laid out by chunks, is this package's own, over an image's ranges, and bounded by them: no source hands one. TestContractCopiedFileIsTheSizeItsSourceDeclared, with a data file and without: a file that reads a megabyte where it declared ten bytes is ten bytes, and the data file holds no more than a block of it; one that reads none, four or nine of its ten bytes fails with io.ErrUnexpectedEOF, in CopyFrom with a data file and at Close without. With a data file the first, the second and the size of the data file fail before the change. With the read not bounded, the short read not refused, or one byte short allowed, the test fails. For #272 Signed-off-by: closer-claudio <claudio@farcloser.world> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
CopyFrom places a file's entry in the tree and then finishes it: its
chunks put on the copy's devices when metadata-only, its data read
into the data file when there is one. When that failed, CopyFrom
returned the error and the entry stayed, with the size the source
declared and less data than that, or none. A Writer closed after it
wrote the entry as it was: with a data file, a file of 10,000 bytes
whose read failed at once gave an image this package's own reader
refuses ("data range [0, +10000) lies past the end of the 8192 byte
image"), and a smaller one a file that reads the next file's bytes.
The entry now goes with the failure, as Remove takes it. What follows
the placement is a function of its own (settle, and toDataFile for the
read into the data file), so that one place sees every way it fails.
What is not changed: a CopyFrom that failed has still left in the tree
what it copied before the failure, and Close still writes that and
returns nil. Whether such a Writer should refuse to go on is
#309; what it writes is at
least an image of whole files.
TestContractAFileWhoseCopyFailedIsNotInTheImage, with a data file:
between two files that copy, one of 10, 4097 or 10000 bytes whose read
fails or ends at once or half way. CopyFrom fails; the Writer no longer
finds the file; after a later copy and Close the image opens and holds
the two other files and the later one's, each with its own bytes. All
twelve cases fail before the change, three of them on an image that
does not read.
For #309
Signed-off-by: closer-claudio <claudio@farcloser.world>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Author
|
Reviewed at c98e8d4 |
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.
This is the second layer of a stack: it sits on #310, whose commit shows in the diff until that one merges. Its own commit is "A file whose copy fails once it is in the tree is taken out of it".
The defect
CopyFromplaces a file's entry in the tree and then finishes it: its chunks put on the copy's devices when metadata-only, its data read into the data file when there is one. When that failed,CopyFromreturned the error and the entry stayed, with the size the source declared and less data than that, or none.A Writer closed after it wrote the entry as it was. With a data file:
The change
The entry goes with the failure, as
Removetakes it. What follows the placement is a function of its own (settle, andtoDataFilefor the read into the data file), so that one place sees every way it fails. No other line of logic changes.What a consumer sees
After a
CopyFromthat failed on a file, the Writer no longer finds that file, and an image written afterwards holds whole files only. A caller that stops atCopyFrom's error sees no difference.What is not changed
A
CopyFromthat failed has still left in the tree what it copied before the failure, andClosestill writes that and returns nil. Whether such a Writer should refuse to go on is the open half of #309.Evidence
TestContractAFileWhoseCopyFailedIsNotInTheImage, with a data file: between two files that copy, one of 10, 4097 or 10000 bytes whose read fails or ends, at once or half way.CopyFromfails; the Writer no longer finds the file; after a later copy andClosethe image opens and holds the other files, each with its own bytes. All twelve cases fail before the change, three of them on an image that does not read. With the entry left in place the twelve fail.just lintandjust testpass.For #309