return the stat error on failure

This commit is contained in:
itchyny 2020-01-09 12:07:26 +09:00
parent 0d1a97a09b
commit a4647e9205

15
mmv.go
View file

@ -27,14 +27,15 @@ func doRename(src, dst string) (err error) {
if err = os.Rename(src, dst); err != nil && os.IsNotExist(err) {
// check the source file existence to exit without creating the destination
// directory when the both source file and destination directory do not exist
if _, err := os.Stat(src); err == nil {
// create the destination directory
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
return err
}
// try renaming again
return os.Rename(src, dst)
if _, err := os.Stat(src); err != nil {
return err
}
// create the destination directory
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
return err
}
// try renaming again
return os.Rename(src, dst)
}
return
}