Documentation / Safety and recovery

Safety and recovery

A file is never changed until a clone of it exists, and never kept until the result is proven correct.

Clone, write, gate, truncate, verify, done. A write by the user or any mismatch restores the original from the clone.

The steps for one file

  1. Read the facts. Coldpack opens the file without following links and checks that it is still the same file it chose.
  2. Sample. In dry run the work stops here and returns an estimate.
  3. Clone. It makes an APFS clone of the file in a private journal folder, which costs no space, and saves a journal entry. If the volume cannot clone, Coldpack skips the file and touches nothing.
  4. Write. It stores the compressed data next to the original data, and computes a SHA-256 checksum of the bytes it read.
  5. Flush. It forces the data to stable storage before the last gate.
  6. Gate. The original data must still equal the clone, byte for byte, the checksum must match, and the file must not have changed. This is the last action before the point of no return.
  7. Truncate and flag. Only now Coldpack releases the plain data and marks the file as compressed. It restores the four dates.
  8. Verify. On a fresh descriptor it reads the file back through the kernel decompressor and compares the checksum. The file must still be the same inode, still compressed and the same size.
  9. Finish. If everything matches, the clone and the journal entry are deleted. If anything differs, Coldpack restores the file from the clone and then proves the restore.

The rules Coldpack never breaks

  1. No file is changed without a clone and a journal entry on the same volume first.
  2. The destructive step happens only after the data equals the clone and the file is stable.
  3. A file is compressed only if it is eligible, not open, not a clone, and has no other links.
  4. Every compression is verified byte for byte, through the kernel. Any difference rolls it back.
  5. A write by you during the operation wins. Coldpack undoes its own change and keeps your newest data.
  6. Four dates survive every operation (see File dates and Git).
  7. Recovery runs before new work at every start.
  8. Some places are never touched.

Never touched

Built-in excludes always apply. No setting and no rule can remove them.

Cloud folders: excluded by default

Editable default rules skip ~/Library/Mobile Documents (iCloud), ~/Library/CloudStorage, and the legacy /Volumes/GoogleDrive location. Remove a rule or put a compress rule first to opt in; all per-file safety checks still apply. Add skip rules for custom synchronized folders. Compatibility with cloud synchronization has not been measured.

Per-file safety checks

Beyond folders, Coldpack skips these kinds of files in every case:

Clones that share blocks

A file that is a full clone of another file is left alone. A file that shares only part of its blocks is safe to compress: disk use cannot grow, because Coldpack never rewrites the shared data. Its saving counts only the bytes that belong to that file alone.

Crash recovery

At every start, before any new work, Coldpack reads the journal. For each entry it decides from the state of the file:

State at the crashWhat recovery does
Before the clone was completeThe file was never touched. Leftover temp files are removed.
Payload written, plain data still thereRemoves Coldpack's own data. If you wrote meanwhile, your data and dates stay.
After the point of no returnRestores from the clone, or finishes a compression that was complete.
A restore was interruptedRestores again until the file equals the clone.

Recovery discards an entry only when it can prove that nothing of the original is left. If it cannot tell (for example a permission error), the entry and the clone stay, the problem is logged, and the next start tries again.

Only one process at a time may change files for a journal folder. The app and every command that changes files take an exclusive lock, and a second process stops at once with a clear message. Read-only commands never run recovery.

If a rollback fails

If Coldpack cannot roll a file back, it stops compressing, runs recovery at once, and shows the failure in the popover. It resumes only when the journal is clean. The rest of the batch goes back to the waiting list, so no file is lost.

Known limits