mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os: lstat oldname before renaming
Fixes #19647 Change-Id: Ife4f98cf2c55ee9490843797213dae2f2647b0a3 Reviewed-on: https://go-review.googlesource.com/40577 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
1ea796ee69
commit
0f0a51f1d1
2 changed files with 24 additions and 3 deletions
|
|
@ -20,11 +20,20 @@ func fixLongPath(path string) string {
|
|||
func rename(oldname, newname string) error {
|
||||
fi, err := Lstat(newname)
|
||||
if err == nil && fi.IsDir() {
|
||||
// if we cannot stat oldname we should
|
||||
// return that error in favor of EEXIST
|
||||
fi, err = Lstat(oldname)
|
||||
if err != nil {
|
||||
if pErr, ok := err.(*PathError); ok {
|
||||
err = pErr.Err
|
||||
}
|
||||
return &LinkError{"rename", oldname, newname, err}
|
||||
}
|
||||
return &LinkError{"rename", oldname, newname, syscall.EEXIST}
|
||||
}
|
||||
e := syscall.Rename(oldname, newname)
|
||||
if e != nil {
|
||||
return &LinkError{"rename", oldname, newname, e}
|
||||
err = syscall.Rename(oldname, newname)
|
||||
if err != nil {
|
||||
return &LinkError{"rename", oldname, newname, err}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue