mirror of
https://github.com/itchyny/mmv.git
synced 2025-12-26 22:24:58 +08:00
return the stat error on failure
This commit is contained in:
parent
0d1a97a09b
commit
a4647e9205
1 changed files with 8 additions and 7 deletions
15
mmv.go
15
mmv.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue