C.W.K.
Stream
Lesson 05 of 05 · published

Preserve or Fail Loudly

~12 min · metadata, preservation, fail-loud

Level 0Lost in Finder
0 XP0/36 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete
"A copy that silently drops the file's tags, permissions, and creation date didn't copy the file. It copied the bytes and lost the rest."

A File Is More Than Its Bytes

When you copy a file, you naively think of the data. But a macOS file carries a whole train of metadata: creation and modification dates, POSIX permissions and ACLs, extended attributes, Finder tags and color labels, resource forks, quarantine flags. A 'copy' that moves only the data bytes and drops all of that has quietly damaged the file — the tags you used to organize it are gone, the permissions that protected it are wrong, the creation date is today. And nothing told you.

Preserve, With Explicit Tests

Waygate copies metadata deliberately, using APIs that preserve the full set, and it has explicit preservation tests in its corpus — a copied file is checked to confirm its ACLs, xattrs, tags, resource forks, and dates survived. This isn't assumed; it's verified against a fixture corpus so a regression that starts dropping xattrs is caught by a failing test, not by a user noticing their tags vanished weeks later.

When Preservation Can't Happen, Say So

Sometimes the destination can't hold everything — copying to a filesystem that doesn't support extended attributes or resource forks, for instance. The rule then is absolute: unsupported semantics produce a visible warning or failure, never quiet loss. Waygate would rather stop and tell you 'this destination can't preserve your Finder tags' than silently complete a copy that threw them away. Silent loss is the one outcome a trustworthy file manager can never ship. And the fiddly cases get real handling too: a case-only rename on a case-insensitive volume goes through a journaled unique intermediate name with crash recovery, and special files like device nodes are refused until an explicit policy exists.

Metadata is preserved with explicit tests, and unsupported semantics fail loudly — never with quiet loss. ACLs, extended attributes, Finder tags, resource forks, and dates have preservation tests in the corpus. When a destination can't hold something, Waygate surfaces a visible warning or failure rather than silently dropping it.
Track cleared — responsive and correct under load. Off-main I/O, coordinated access, conservative traversal, no accidental cloud downloads, and metadata that's preserved or the loss is loud. This track is why Waygate stays usable on a slow SMB share full of packages, symlinks, and cloud placeholders — the conditions where lesser file managers beachball or quietly corrupt. Next: where the network and its secrets belong.

Code

Copy the whole file, then verify the metadata survived·swift
import Darwin

func copyPreservingMetadata(_ src: URL, to dst: URL) throws {
    // copyfile with COPYFILE_ALL preserves data + metadata + xattrs + ACLs:
    let state = copyfile_state_alloc()
    defer { copyfile_state_free(state) }
    let flags = copyfile_flags_t(COPYFILE_ALL | COPYFILE_NOFOLLOW)
    guard copyfile(src.path, dst.path, state, flags) == 0 else {
        throw OpError.copyFailed(errno: errno)
    }
    // Then VERIFY the metadata actually landed (a preservation test):
    let srcVals = try src.resourceValues(forKeys: [.creationDateKey, .tagNamesKey])
    let dstVals = try dst.resourceValues(forKeys: [.creationDateKey, .tagNamesKey])
    guard srcVals.creationDate == dstVals.creationDate,
          srcVals.tagNames == dstVals.tagNames else {
        throw OpError.metadataNotPreserved   // fail LOUD, don't ship silent loss
    }
}

External links

Exercise

Tag a file in Finder with a color and a keyword, set a custom creation date, then copy it with a basic tool and inspect the copy. Which metadata survived and which didn't? Now design the 'fail loudly' behavior: when the copy can't preserve the tags, what exactly should the app show the user, and why is a warning strictly better than a silent success here?
Hint
Basic copies often preserve dates and permissions but drop Finder tags or resource forks depending on the tool and destination. A silent success teaches the user to trust a copy that actually damaged their organization scheme — they find out weeks later when a tag search comes up empty. A warning ('this destination can't keep your tags') lets them decide now, while they still remember what they'd lose. Loud beats silent whenever data is at stake.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.