if oldpath==newpath, then skip mv and just rm oldpath
This commit is contained in:
14
cmd/main.go
14
cmd/main.go
@@ -259,6 +259,19 @@ func _merge(filepath string, mergeTargetFilePath string) error {
|
||||
}
|
||||
|
||||
func rename(oldpath, newpath string) error {
|
||||
if same, err := func() (bool, error) {
|
||||
oldb, err := os.ReadFile(oldpath)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
newb, err := os.ReadFile(newpath)
|
||||
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
|
||||
@@ -267,6 +280,7 @@ func rename(oldpath, newpath string) error {
|
||||
if err := os.WriteFile(newpath, b, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return os.Remove(oldpath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user