WriteFileWithRename is a drop-in replacement for os.WriteFile, with the same signature and almost identical behavior (see note below on inodes). Unlike os.WriteFile, it does provide extra guarantees: - Atomicity (provided by rename - *mostly* atomic, except on OS crash, where rename behavior is unde
(filename string, data []byte, perm os.FileMode)
| 40 | // Finally note that we do not do anything smart wrt symlinks. |
| 41 | // User is expected to resolve symlink for the destination before calling this if needed. |
| 42 | func WriteFileWithRename(filename string, data []byte, perm os.FileMode) error { |
| 43 | return CopyToFileWithRename(filename, bytes.NewBuffer(data), int64(len(data)), perm, time.Time{}) |
| 44 | } |
| 45 | |
| 46 | // CopyToFileWithRename is an atomic wrapper around io.Copy(file, reader). See notes above in WriteFile for details. |
| 47 | func CopyToFileWithRename(filename string, reader io.Reader, dataSize int64, perm os.FileMode, mTime time.Time) (err error) { |
no test coverage detected
searching dependent graphs…