Skip to content

Commit 5552a98

Browse files
committed
unix: add Renameat on dragonfly
Also add a test now that all unices have Renameat. Change-Id: I9098662569e9910122dc686559bbd04be06328fa Reviewed-on: https://go-review.googlesource.com/c/157898 Run-TryBot: Tobias Klauser <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent a457fd0 commit 5552a98

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

unix/syscall_dragonfly.go

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
304304
//sys read(fd int, p []byte) (n int, err error)
305305
//sys Readlink(path string, buf []byte) (n int, err error)
306306
//sys Rename(from string, to string) (err error)
307+
//sys Renameat(fromfd int, from string, tofd int, to string) (err error)
307308
//sys Revoke(path string) (err error)
308309
//sys Rmdir(path string) (err error)
309310
//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK

unix/syscall_unix_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,29 @@ func TestMkdev(t *testing.T) {
623623
}
624624
}
625625

626+
func TestRenameat(t *testing.T) {
627+
defer chtmpdir(t)()
628+
629+
from, to := "renamefrom", "renameto"
630+
631+
touch(t, from)
632+
633+
err := unix.Renameat(unix.AT_FDCWD, from, unix.AT_FDCWD, to)
634+
if err != nil {
635+
t.Fatalf("Renameat: unexpected error: %v", err)
636+
}
637+
638+
_, err = os.Stat(to)
639+
if err != nil {
640+
t.Error(err)
641+
}
642+
643+
_, err = os.Stat(from)
644+
if err == nil {
645+
t.Errorf("Renameat: stat of renamed file %q unexpectedly suceeded", from)
646+
}
647+
}
648+
626649
// mktmpfifo creates a temporary FIFO and provides a cleanup function.
627650
func mktmpfifo(t *testing.T) (*os.File, func()) {
628651
err := unix.Mkfifo("fifo", 0666)

unix/zsyscall_dragonfly_amd64.go

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)