Download this file
| 1 | // Package privatefile handles bounded private files. Runtime support is Linux |
| 2 | // only; other platforms refuse operations until their privacy guarantees exist. |
| 3 | package privatefile |
| 4 | |
| 5 | import "errors" |
| 6 | |
| 7 | var ErrUnavailable = errors.New("private file unavailable") |
| 8 | var ErrUnsupported = errors.New("private files unsupported on this platform") |
| 9 | |
| 10 | // Read returns exact bytes from an owned, single-link, regular 0600 file. |
| 11 | // Paths must be absolute and already clean. It rejects symlinks in every path component. The caller validates payload |
| 12 | // syntax and completeness: Read cannot distinguish an interrupted write from |
| 13 | // intentionally short content. max must be positive. |
| 14 | func Read(path string, max int) ([]byte, error) { return read(path, max) } |
| 15 | |
| 16 | // CreateExclusiveDurable creates a new 0600 file and checks file and parent |
| 17 | // synchronization before returning success. The parent must already exist and |
| 18 | // be owned and private. The path must be absolute and already clean. Failures preserve any created file, which prevents |
| 19 | // retry from overwriting it. The caller must retain its recovery material and |
| 20 | // must not treat a later Read as proof that this operation completed. A future |
| 21 | // resume caller needs its own checked durability barrier after validating the |
| 22 | // saved payload; reopening a file does not repair a failed synchronization. |
| 23 | func CreateExclusiveDurable(path string, data []byte, max int) error { |
| 24 | return create(path, data, max) |
| 25 | } |
| 26 | |