|
| 1 | +package atomicwriter |
| 2 | + |
| 3 | +import ( |
| 4 | + "io" |
| 5 | + "os" |
| 6 | + |
| 7 | + "github.com/moby/sys/atomicwriter" |
| 8 | +) |
| 9 | + |
| 10 | +// New returns a WriteCloser so that writing to it writes to a |
| 11 | +// temporary file and closing it atomically changes the temporary file to |
| 12 | +// destination path. Writing and closing concurrently is not allowed. |
| 13 | +// NOTE: umask is not considered for the file's permissions. |
| 14 | +// |
| 15 | +// New uses [sequential.CreateTemp] to use sequential file access on Windows, |
| 16 | +// avoiding depleting the standby list un-necessarily. On Linux, this equates to |
| 17 | +// a regular [os.CreateTemp]. Refer to the [Win32 API documentation] for details |
| 18 | +// on sequential file access. |
| 19 | +// |
| 20 | +// Deprecated: use [atomicwriter.New] instead. |
| 21 | +// |
| 22 | +// [Win32 API documentation]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN |
| 23 | +func New(filename string, perm os.FileMode) (io.WriteCloser, error) { |
| 24 | + return atomicwriter.New(filename, perm) |
| 25 | +} |
| 26 | + |
| 27 | +// WriteFile atomically writes data to a file named by filename and with the |
| 28 | +// specified permission bits. The given filename is created if it does not exist, |
| 29 | +// but the destination directory must exist. It can be used as a drop-in replacement |
| 30 | +// for [os.WriteFile], but currently does not allow the destination path to be |
| 31 | +// a symlink. WriteFile is implemented using [New] for its implementation. |
| 32 | +// |
| 33 | +// NOTE: umask is not considered for the file's permissions. |
| 34 | +// |
| 35 | +// Deprecated: use [atomicwriter.WriteFile] instead. |
| 36 | +func WriteFile(filename string, data []byte, perm os.FileMode) error { |
| 37 | + return atomicwriter.WriteFile(filename, data, perm) |
| 38 | +} |
| 39 | + |
| 40 | +// WriteSet is used to atomically write a set |
| 41 | +// of files and ensure they are visible at the same time. |
| 42 | +// Must be committed to a new directory. |
| 43 | +// |
| 44 | +// Deprecated: use [atomicwriter.WriteSet] instead. |
| 45 | +type WriteSet = atomicwriter.WriteSet |
| 46 | + |
| 47 | +// NewWriteSet creates a new atomic write set to |
| 48 | +// atomically create a set of files. The given directory |
| 49 | +// is used as the base directory for storing files before |
| 50 | +// commit. If no temporary directory is given the system |
| 51 | +// default is used. |
| 52 | +// |
| 53 | +// Deprecated: use [atomicwriter.NewWriteSet] instead. |
| 54 | +func NewWriteSet(tmpDir string) (*atomicwriter.WriteSet, error) { |
| 55 | + return atomicwriter.NewWriteSet(tmpDir) |
| 56 | +} |
0 commit comments