mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os: reject Rename("old", "new") where new is a directory
Unix rejects this when new is a non-empty directory. Other systems reject this when new is a directory, empty or not. Make Unix reject empty directory too. Fixes #14527. Change-Id: Ice24b8065264c91c22cba24aa73e142386c29c87 Reviewed-on: https://go-review.googlesource.com/31358 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
8fbfdad281
commit
321c312d82
2 changed files with 35 additions and 0 deletions
|
|
@ -12,6 +12,10 @@ import (
|
|||
)
|
||||
|
||||
func rename(oldname, newname string) error {
|
||||
fi, err := Lstat(newname)
|
||||
if err == nil && fi.IsDir() {
|
||||
return &LinkError{"rename", oldname, newname, syscall.EEXIST}
|
||||
}
|
||||
e := syscall.Rename(oldname, newname)
|
||||
if e != nil {
|
||||
return &LinkError{"rename", oldname, newname, e}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue