if oldpath==newpath, then skip mv and just rm oldpath
This commit is contained in:
26
cmd/main.go
26
cmd/main.go
@@ -259,13 +259,27 @@ func _merge(filepath string, mergeTargetFilePath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func rename(oldpath, newpath string) error {
|
func rename(oldpath, newpath string) error {
|
||||||
b, err := os.ReadFile(oldpath)
|
if same, err := func() (bool, error) {
|
||||||
if err != nil {
|
oldb, err := os.ReadFile(oldpath)
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
if err := os.WriteFile(newpath, b, os.ModePerm); err != nil {
|
newb, err := os.ReadFile(newpath)
|
||||||
return err
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes.Equal(oldb, newb), nil
|
||||||
|
}(); err != nil || !same {
|
||||||
|
b, err := os.ReadFile(oldpath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.WriteFile(newpath, b, os.ModePerm); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return os.Remove(oldpath)
|
return os.Remove(oldpath)
|
||||||
|
|||||||
Reference in New Issue
Block a user