Skip to content

Add reflink/COW support for shared/copy files#21

Merged
bkildow merged 2 commits into
mainfrom
feat/reflink-shared-copy
Apr 22, 2026
Merged

Add reflink/COW support for shared/copy files#21
bkildow merged 2 commits into
mainfrom
feat/reflink-shared-copy

Conversation

@bkildow
Copy link
Copy Markdown
Owner

@bkildow bkildow commented Apr 22, 2026

Summary

  • New internal/project/fscopy package: CopyFile tries reflink first via unix.Clonefile (darwin) or unix.IoctlSetInt + FICLONE (linux), falls back to byte-copy on Windows/ext4/cross-volume/etc.
  • Atomic write via <dst>.wtclone tmp + rename; interrupted runs self-heal on next invocation.
  • Rewires internal/project/apply.go:ApplyCopy to use fscopy.CopyFile; deletes the private copyFile.
  • Promotes golang.org/x/sys from indirect to direct dep (no new transitive deps).
  • README: adds a Features bullet and a "Reflink copies" paragraph under How It Works.

Closes bd-3is.

Test plan

  • make dev (fmt + vet + test + build) green on darwin
  • Cross-builds clean for GOOS=linux and GOOS=windows
  • New internal/project/fscopy tests cover happy path, empty file, overwrite, stale-tmp cleanup, missing source, missing parent, and the byteCopy fallback directly
  • Existing internal/project/apply_test.go tests continue to pass unchanged
  • Manual APFS smoke test: 200 MB file in shared/copy/ -> wt add Go process used ~60 ms CPU; byte-equal shasums
  • Reviewer: verify on a btrfs or XFS(reflink=1) Linux host if available

bkildow added 2 commits April 22, 2026 09:32
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.
@bkildow bkildow merged commit e53a59d into main Apr 22, 2026
@bkildow bkildow deleted the feat/reflink-shared-copy branch April 22, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant