Commit 161f2e85 authored by David du Colombier's avatar David du Colombier Committed by Russ Cox

os: fix rename on Plan 9

Rename should remove newname if the file already exists
and is not a directory.

Fixes #13844.

Change-Id: I85a5cc28e8d161637a8bc1de33f4a637d9154cd1
Reviewed-on: https://go-review.googlesource.com/18291Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 9a2d717f
......@@ -339,7 +339,9 @@ func rename(oldname, newname string) error {
// If newname still contains slashes after removing the oldname
// prefix, the rename is cross-directory and must be rejected.
// This case is caught by d.Marshal below.
if lastIndex(newname, '/') >= 0 {
return &LinkError{"rename", oldname, newname, ErrInvalid}
}
var d syscall.Dir
......@@ -351,6 +353,13 @@ func rename(oldname, newname string) error {
if err != nil {
return &LinkError{"rename", oldname, newname, err}
}
// If newname already exists and is not a directory, rename replaces it.
f, err := Stat(dirname + newname)
if err == nil && !f.IsDir() {
Remove(dirname + newname)
}
if err = syscall.Wstat(oldname, buf[:n]); err != nil {
return &LinkError{"rename", oldname, newname, err}
}
......
......@@ -773,9 +773,6 @@ func TestRename(t *testing.T) {
}
func TestRenameOverwriteDest(t *testing.T) {
if runtime.GOOS == "plan9" {
t.Skip("skipping on plan9")
}
defer chtmpdir(t)()
from, to := "renamefrom", "renameto"
// Just in case.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment