package atomicwriter
import "github.com/moby/sys/atomicwriter"
Package atomicwriter provides utilities to perform atomic writes to a file or set of files.
Index ¶
- func New(filename string, perm os.FileMode) (io.WriteCloser, error)
- func WriteFile(filename string, data []byte, perm os.FileMode) error
- type WriteSet
- func NewWriteSet(tmpDir string) (*WriteSet, error)
- func (ws *WriteSet) Cancel() error
- func (ws *WriteSet) Commit(target string) error
- func (ws *WriteSet) FileWriter(name string, flag int, perm os.FileMode) (io.WriteCloser, error)
- func (ws *WriteSet) String() string
- func (ws *WriteSet) WriteFile(filename string, data []byte, perm os.FileMode) error
Functions ¶
func New ¶
New returns a WriteCloser so that writing to it writes to a temporary file and closing it atomically changes the temporary file to destination path. Writing and closing concurrently is not allowed. NOTE: umask is not considered for the file's permissions.
New uses sequential.CreateTemp to use sequential file access on Windows, avoiding depleting the standby list un-necessarily. On Linux, this equates to a regular os.CreateTemp. Refer to the Win32 API documentation for details on sequential file access.
func WriteFile ¶
WriteFile atomically writes data to a file named by filename and with the specified permission bits. The given filename is created if it does not exist, but the destination directory must exist. It can be used as a drop-in replacement for os.WriteFile, but currently does not allow the destination path to be a symlink. WriteFile is implemented using New for its implementation.
NOTE: umask is not considered for the file's permissions.
Types ¶
type WriteSet ¶
type WriteSet struct {
// contains filtered or unexported fields
}
WriteSet is used to atomically write a set of files and ensure they are visible at the same time. Must be committed to a new directory.
func NewWriteSet ¶
NewWriteSet creates a new atomic write set to atomically create a set of files. The given directory is used as the base directory for storing files before commit. If no temporary directory is given the system default is used.
func (*WriteSet) Cancel ¶
Cancel cancels the set and removes all temporary data created in the set.
func (*WriteSet) Commit ¶
Commit moves all created files to the target directory. The target directory must not exist and the parent of the target directory must exist.
func (*WriteSet) FileWriter ¶
FileWriter opens a file writer inside the set. The file should be synced and closed before calling commit.
FileWriter uses sequential.OpenFile to use sequential file access on Windows, avoiding depleting the standby list un-necessarily. On Linux, this equates to a regular os.OpenFile. Refer to the Win32 API documentation for details on sequential file access.
func (*WriteSet) String ¶
String returns the location the set is writing to.
func (*WriteSet) WriteFile ¶
WriteFile writes a file to the set, guaranteeing the file has been synced.
Source Files ¶
- Version
- v0.1.0 (latest)
- Published
- Apr 7, 2025
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- now –
Tools for package owners.