Repository navigation
Conversation
On NTFS a hardlink shares its read-only attribute with the cache object. To delete a protected workspace file, dvc_objects' remove() clears that attribute first, which also leaves the cache object writable. This happens on `dvc checkout --relink` and whenever a hardlinked file is replaced by another version. A later edit of the workspace file then silently corrupts the cache object, and `dvc status` deletes it. The old hashfile checkout protected the object again in _relink(). Do the same in index-based checkout: after deleting workspace files, protect the cache objects they pointed to. Part of treeverse/dvc#11119.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #679 +/- ##
==========================================
+ Coverage 72.42% 74.26% +1.83%
==========================================
Files 67 65 -2
Lines 5132 5409 +277
Branches 605 629 +24
==========================================
+ Hits 3717 4017 +300
+ Misses 1227 1195 -32
- Partials 188 197 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Part of treeverse/dvc#11119.
On NTFS a hardlink shares its read-only attribute with the cache object. To delete a protected workspace file,
dvc_objects.fs.utils.remove()clears that attribute first, so the cache object becomes writable too. In index-based checkout this happens ondvc checkout --relinkand whenever a hardlinked file is replaced by another version. A later edit of the workspace file then rewrites the cache object, and the nextdvc statusdeletes it as corrupted.The old
hashfile/checkout.pyhandled this in_relink()by callingcache.protect()after re-linking. Index-based checkout lost that step. This PR adds it back inapply(): before deleting workspace files, it collects the cache objects they point to (from the new index's cache storage), then protects them again once the files are gone. The links are then created from protected objects, so both the old and the new version stay read-only. It only runs when the workspace filesystem is local.Not covered here:
dvc unprotectandStage.remove_outsreach the sameremove()call from dvc's side (see the issue and the comment from @kpaxico). They can follow in separate PRs if this approach looks right.Tests: two new tests in
tests/index/test_checkout.py, one for relink and one for switching a hardlinked file to another version. On Windows both fail onmainand pass with this change. On Linux and macOS they pass either way, because deleting a file there does not touch its mode.