Add reflink/COW support for shared/copy files#21
Merged
Conversation
Large directories under shared/copy/ (vendor/, node_modules/, .venv/, target/) previously took minutes to duplicate into each worktree via io.Copy. On filesystems that support copy-on-write cloning -- APFS on macOS, btrfs on Linux, XFS with reflink=1 -- the new fscopy package uses clonefile(2) / FICLONE so copies are near-instant and share on-disk blocks until one side is modified. On ext4, NFS, tmpfs, Windows, and across volumes, fscopy falls back transparently to the previous byte-for-byte copy. No configuration or user-visible change required.
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.
Summary
internal/project/fscopypackage:CopyFiletries reflink first viaunix.Clonefile(darwin) orunix.IoctlSetInt+FICLONE(linux), falls back to byte-copy on Windows/ext4/cross-volume/etc.<dst>.wtclonetmp + rename; interrupted runs self-heal on next invocation.internal/project/apply.go:ApplyCopyto usefscopy.CopyFile; deletes the privatecopyFile.golang.org/x/sysfrom indirect to direct dep (no new transitive deps).Closes bd-3is.
Test plan
make dev(fmt + vet + test + build) green on darwinGOOS=linuxandGOOS=windowsinternal/project/fscopytests cover happy path, empty file, overwrite, stale-tmp cleanup, missing source, missing parent, and thebyteCopyfallback directlyinternal/project/apply_test.gotests continue to pass unchangedshared/copy/->wt addGo process used ~60 ms CPU; byte-equal shasums