Skip to content

fork of a plain folder: a frozen copy, its files cloned - #158

Merged
lydakis merged 2 commits into
mainfrom
claude/project-thread-clh2lc
Oct 26, 2026
Merged

lydakis merged 2 commits into
mainfrom
claude/project-thread-clh2lc

Conversation

@lydakis

@lydakis lydakis commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Requested by George · project thread

sandfs fork FROM DIR refused a folder outside any workspace or git repository, so a task copy of a plain folder had to be a sandfs mount of it. A mount is a live view: edits made in the folder show up in the copy, and changes --copy-to FOLDER couldn't tell an edit made in the folder since the copy started. This PR makes that fork a frozen copy, which was the last piece of the agreed fork design (#154, #153).

Changes

  • Home::freeze (store.rs): clones the folder's files, links and folders, with their modes and modification times, into $SANDFS_HOME/copies/copy-XXXX/. The workspace is a Base::Dir over that copy, and its source is the original folder, for display. Files are cloned with reflink-copy (clonefile on macOS, FICLONE on Linux), which takes no space for their contents. On a disk that can't clone (ext4), or when the folder is on another disk than the home, the fork is refused with a message pointing to sandfs mount, instead of falling back to a full copy. Pipes, sockets and devices are left out with a warning. A folder that holds the home is refused, as resolve already does.
  • Cleanup: rm deletes copies no workspace is over any more (Home::remove_unused_copies, under the exclusive repos lock that clean takes, so it can't race a fork that is being made). clean sweeps them too, and so does a failed fork or mount. remove_copy makes cloned read-only folders writable before deleting them, for a folder such as Go's module cache.
  • main.rs: fork_origin returns Origin::Folder instead of refusing. --branch with a plain folder is refused ("needs a git repository").
  • Docs: README (task-copy section plus an example), the sandfs-cli README (the fork paragraph, and the copy-to paragraph, which now says a fork keeps the check working where a straight mount can't), changelog.
  • New dependency: reflink-copy 0.1 (its Windows crates are only pulled in on Windows). The CLI crate forbids unsafe code, and this gives a safe clone call that fails rather than falling back to a full copy, which std::fs::copy does on ext4.

Testing

  • New mount test a_fork_of_a_plain_folder_keeps_it_as_it_was. On a disk that clones, it checks that the fork keeps contents, times, modes and links; that later edits in the folder stay out; that changes --copy-to FOLDER refuses to overwrite a file edited there since and then copies; and that a snapshot shares the copy, which goes with the last rm. On a disk that can't clone (Linux CI on ext4), it checks the refusal and that nothing is left behind. It must take the cloning path on macOS (APFS).
  • I ran that test locally both on ext4 and with TMPDIR on a btrfs loop device (cloning path). By hand on btrfs: a folder with a 50 MB file forked with no change in disk use, and 20,000 small files forked in 1.8 s (cp -R --reflink=always took 2.2 s).
  • The existing clone-fork test now checks the --branch refusal for a plain folder instead of the old "not supported" refusal.
  • cargo fmt --check and cargo clippy --workspace --all-targets -D warnings are clean, and cargo test -p sandfs-cli passes (116 + 12 + 27).

On macOS, cloning goes file by file. If it is slow for large folders on George's Mac, cloning the whole tree in one clonefile call is the follow-up, but that needs FFI.


Generated by Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T01:24:09.692921Z 808269e New commits
🔒 Security Review ✅ Completed 2026-10-26T01:27:44.387269Z 808269e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

sandfs fork FOLDER DIR now takes a folder outside any workspace or git
repository. Its files, links and folders are cloned with their modes and
times into $SANDFS_HOME/copies (reflink: APFS, btrfs, XFS), so the fork
is the folder as it was and changes --copy-to FOLDER can tell an edit
made there since. A disk that can't clone is refused rather than copied
in full. The copy is deleted with the last workspace over it (rm), or by
clean.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LAgZE9cvrECwdHFyP41Vd2
A workspace made with SANDFS_HOME spelled through a link (as /tmp is on
macOS) records its copy under that spelling; rm under another spelling
took the copy for unused and deleted it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LAgZE9cvrECwdHFyP41Vd2
@lydakis
lydakis force-pushed the claude/project-thread-clh2lc branch from 88609a8 to 808269e Compare October 26, 2026 01:22
@lydakis
lydakis merged commit 4d68042 into main Oct 26, 2026
23 checks passed
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.

2 participants