Files
magpie/internal/sessions/cursor_clone_darwin.go
T
yetone 0e39c8e7e9 sessions: reading Cursor's history no longer writes its database to the temp folder again and again (#1988, kangxi94)
v0.1.1224 reads Cursor's editor chats from its global state.vscdb, which
is often several GB. A store with a live -wal is read from a copy, and
every listing, count, manage page, transcript, context read and each
chat of a search made a fresh full copy in $TMPDIR/magpie-cursor-*.
A visit to Sessions wrote the file out several times (28 in the test
below): heavy disk writes with low CPU, and Time Machine's local
snapshots can hold on to deleted copies' blocks, which would shrink free
space (not reproduced on the reporter's machine). A magpie killed mid-read also left
its copy behind for good.

- A store of 16 MB or more is copied once and the copy is shared by
  every reader while the store and its -wal keep their size and time;
  a change makes one new copy, and a copy goes 30s after its last reader.
- On macOS the copy is an APFS clone (clonefile), so it takes no space
  until Cursor writes; elsewhere, or when cloning fails, it is copied.
- The first copy a process makes sweeps magpie-cursor-* folders older
  than an hour (a shared copy is touched on every reuse).

Run:
- TestCursorEditorCopiedOncePerChange: 6 editor chats, list + Agents +
  transcript + search of each, twice: 1 copy (28 with sharing turned off
  by hand), 2 after one change, none left. TestCursorLeftCopiesSwept
  goes red with the sweep turned off.
- go test -race ./internal/sessions/ ok; -run TestCursor -race -count=10 ok.
- gofmt -l clean; go vet -tags nogui for darwin, linux, windows.
- Sandbox HOME with a 300 MB Cursor-shaped state.vscdb kept live by a
  writer every 5s: v0.1.1224 made 1-3 full copies per endpoint and 5
  for one search (11s, searched 0 of 30); this build made 2 over
  sessions, stats, overview, manage, context, two searches and a second
  listing (search 30 of 30 in ms), and removed a planted day-old
  magpie-cursor-* folder.
2026-10-13 18:16:18 +08:00

11 lines
371 B
Go

//go:build darwin
package sessions
import "golang.org/x/sys/unix"
// cloneFile makes to share from's blocks on APFS, so a snapshot of a
// multi-GB Cursor database costs no disk until one side is written. It
// fails off APFS or across volumes, and the caller then copies.
func cloneFile(from, to string) error { return unix.Clonefile(from, to, unix.CLONE_NOFOLLOW) }