Repository navigation
vfs: preserve shrinking truncate on uncached files - #10063
Merged
Merged
Conversation
If a file that hadn't been read was shrunk with Truncate, the cache file was cut to the new size but the kept part of the file still had to be fetched on close. The downloader wrote the whole remote object into the cache file, which grew it back to its old size, so the upload replaced the object with the original contents. Stop the downloader writing past the end of the item, and add tests at the vfscache and vfs levels. Fixes rclone#10047
ncw
requested changes
Oct 14, 2026
ncw
left a comment
Member
There was a problem hiding this comment.
This is a nice fix - thank you :-)
I put some nits inline for you to look at.
| require.NoError(t, err) | ||
| require.NoError(t, node.(*File).Truncate(5)) | ||
|
|
||
| vfs.WaitForWriters(10 * time.Second) |
Member
There was a problem hiding this comment.
Could you use the waitForWritersDelay constant rather than 10 * time.Second? These tests run against every backend on the integration tester and some of them are slow.
|
|
||
| obj, err := r.Fremote.NewObject(context.Background(), "file1") | ||
| require.NoError(t, err) | ||
| assert.Equal(t, int64(5), obj.Size()) |
Member
There was a problem hiding this comment.
It would be good to check the contents of the object as well as its size here.
| } | ||
| } | ||
| item.mu.Unlock() | ||
| if err == nil { |
Member
There was a problem hiding this comment.
The doc comment on WriteAtNoOverwrite should mention that bytes past the end of the item are counted as skipped.
Use waitForWritersDelay instead of a literal timeout, check the uploaded object's contents as well as its size, and document that bytes past the end of the item are counted as skipped.
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.
What does this change do?
If an uncached file is shrunk with
Truncate(what a mount does fortruncate(2)with no open handle), the cache file is cut to the new size, but the kept part of the file still has to be fetched on close. The downloader wrote the whole remote object into the cache file, which grew it back to its old size, so the upload replaced the object with the original contents.This stops the downloader writing past the end of the item. Added tests at the vfscache level and the vfs level (
--vfs-cache-mode writesandfull).Linked issue
Fixes #10047
Checklist
test_allpasses for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.I used an AI coding assistant to help write this. I built it and ran
make quicktest; the only failure was cmd/gitannex, which needs rclone on the PATH and passes when it is.