Write the file in same directory
Temporary file may not locate at same disk-partition, or same filesytem.
When the path of temporary file doesn't locate at same disk-partition,
os.Rename works like copying file.
@@ -356,7 +356,8 @@ func writeBytesToSkip(f string, num int64) error {
}
func writeFileAtomically(f string, contents []byte) error {
- tmpf, err := ioutil.TempFile("", "")
+ // MUST be located on same disk partition
+ tmpf, err := ioutil.TempFile(filepath.Dir(f), "tmp")
if err != nil {
return err
}
