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:
Russ Cox 2016-10-18 12:34:19 -04:00
parent 8fbfdad281
commit 321c312d82
2 changed files with 35 additions and 0 deletions

View file

@ -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}