#pragma once // Spec: shell.md section 5 (DIFF: UserDefaults/Keychain become files). Verify before write: content is built in // memory, written to ".tmp" with the requested mode, closed, then renamed over the target (atomic). #include #include namespace dp { class AtomicFile { public: // false when the content exceeds maxBytes or any step fails (temp file removed, target untouched). static bool write(const std::string& path, const std::string& content, unsigned mode, std::size_t maxBytes); // nullopt when missing, unreadable or larger than maxBytes (sets *tooLarge when it was the size). static std::optional read(const std::string& path, std::size_t maxBytes, bool* tooLarge = nullptr); }; } // namespace dp