apfs-cow-timemachine
Zero-CGo, zero-sudo FSEvents-driven APFS Copy-on-Write time machine built with x/fswatch, x/apfs, x/compression, and x/plist.
What It Demonstrates
- Live FSEvents Watching (
x/fswatch): Monitors a workspace on a dedicated GCD serial queue with debouncing and .timemachine/ exclusion.
- Instant APFS CoW Snapshots & Restore (
x/apfs): Captures zero-copy file snapshots on save via clonefile(2) (apfs.CloneFile) and restores earlier snapshots atomically in microseconds.
- Apple LZFSE Compressed Diffs (
x/compression): Computes line diffs between successive file versions and compresses them with compression.LZFSE via libcompression.dylib.
- Binary-Plist Manifests (
x/plist): Persists and verifies snapshot metadata in Apple's compact binary property list format (plist.FormatBinary).
Usage
# Self-contained temp-workspace demo (default when -dir is omitted)
CGO_ENABLED=0 go run ./examples/kernel/apfs-cow-timemachine -demo
# Watch a live directory (writes snapshots to <dir>/.timemachine)
CGO_ENABLED=0 go run ./examples/kernel/apfs-cow-timemachine -dir ./my-workspace
Measured Output
apfs-cow-timemachine (demo workspace: /private/var/folders/kj/qbc32fzd2pv6ngnsysy8vpmw0000gn/T/apfs-cow-timemachine-612343434)
[save #1 -> FSEvents] snap #01: size=237 KiB | clonefile= 351µs | diff=242744B -> LZFSE 378B (642.2x)
[save #2 -> FSEvents] snap #02: size=237 KiB | clonefile= 271µs | diff=2640B -> LZFSE 388B (6.8x)
[save #3 -> FSEvents] snap #03: size=237 KiB | clonefile= 262µs | diff=2640B -> LZFSE 388B (6.8x)
[manifest] binary plist=746B (format=binary:true, 3 snapshots verified)
[restore ] snap #01 restored via APFS CoW in 205µs (byte-identical to v1: true)