github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/internal/replacefile/replacefile_unix.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package replacefile 5 6 import ( 7 "os" 8 ) 9 10 // AtomicRename renames from the source path to the destination path, 11 // atomically replacing any file that might already exist at the destination. 12 // 13 // Typically this operation can succeed only if the source and destination 14 // are within the same physical filesystem, so this function is best reserved 15 // for cases where the source and destination exist in the same directory and 16 // only the local filename differs between them. 17 // 18 // The Unix implementation of AtomicRename relies on the atomicity of renaming 19 // that is required by the ISO C standard, which in turn assumes that Go's 20 // implementation of rename is calling into a system call that preserves that 21 // guarantee. 22 func AtomicRename(source, destination string) error { 23 // On Unix systems, a rename is sufficiently atomic. 24 return os.Rename(source, destination) 25 }