Documentation
¶
Overview ¶
Package atomicfile replaces a file by writing a staged sibling and renaming it over the target, so readers see either the old file or the complete new one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
File is a staged replacement for a target path. Write to it, then call CloseAtomicallyReplace. Defer Cleanup to remove the staged file on any path that does not reach the replace. A process that exits before either leaves the staged file in the target's directory, and nothing removes it later.
func Create ¶
Create stages a replacement for target in target's directory. The staged name is random and created exclusively, so another account that can write to the directory can neither pre-create it nor learn it in advance. Its permissions are the existing target's when the target is a regular file, and 0644 otherwise, both narrowed by the umask: replacing a file never widens its mode.
func (*File) Cleanup ¶
func (f *File) Cleanup()
Cleanup closes and removes the staged file unless CloseAtomicallyReplace succeeded. It removes nothing else.
func (*File) CloseAtomicallyReplace ¶
CloseAtomicallyReplace syncs and closes the staged file and renames it over the target.