instead of os.rename, io.WriteFile and os.Remove

This commit is contained in:
bel
2024-12-20 20:38:11 -07:00
parent 1d958e8a52
commit f72cb35e79
2 changed files with 16 additions and 3 deletions

View File

@@ -68,7 +68,20 @@ func merge(filepath string, mergeTargetFilePath string) error {
if err != nil {
return err
}
return os.Rename(tmppath, filepath)
return rename(tmppath, filepath)
}
func rename(oldpath, newpath string) error {
b, err := io.ReadFile(oldpath)
if err != nil {
return err
}
if err := io.WriteFile(b, newpath, os.ModePerm); err != nil {
return err
}
return os.Remove(oldpath)
}
func marshalRootToTempFile(root pttodo.Root) (string, error) {