From 5552a988b7b5affda993e094be620f94205b0a5d Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 16 Jan 2019 09:00:58 +0000 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- unix/syscall_dragonfly.go | 1 + unix/syscall_unix_test.go | 23 +++++++++++++++++++++++ unix/zsyscall_dragonfly_amd64.go | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/unix/syscall_dragonfly.go b/unix/syscall_dragonfly.go index 891c94d7..962eee30 100644 --- a/unix/syscall_dragonfly.go +++ b/unix/syscall_dragonfly.go @@ -304,6 +304,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) //sys Rename(from string, to string) (err error) +//sys Renameat(fromfd int, from string, tofd int, to string) (err error) //sys Revoke(path string) (err error) //sys Rmdir(path string) (err error) //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index c1b1ea59..c393f68d 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -623,6 +623,29 @@ func TestMkdev(t *testing.T) { } } +func TestRenameat(t *testing.T) { + defer chtmpdir(t)() + + from, to := "renamefrom", "renameto" + + touch(t, from) + + err := unix.Renameat(unix.AT_FDCWD, from, unix.AT_FDCWD, to) + if err != nil { + t.Fatalf("Renameat: unexpected error: %v", err) + } + + _, err = os.Stat(to) + if err != nil { + t.Error(err) + } + + _, err = os.Stat(from) + if err == nil { + t.Errorf("Renameat: stat of renamed file %q unexpectedly suceeded", from) + } +} + // mktmpfifo creates a temporary FIFO and provides a cleanup function. func mktmpfifo(t *testing.T) (*os.File, func()) { err := unix.Mkfifo("fifo", 0666) diff --git a/unix/zsyscall_dragonfly_amd64.go b/unix/zsyscall_dragonfly_amd64.go index da9986dd..ae9f1a21 100644 --- a/unix/zsyscall_dragonfly_amd64.go +++ b/unix/zsyscall_dragonfly_amd64.go @@ -1194,6 +1194,26 @@ func Rename(from string, to string) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Renameat(fromfd int, from string, tofd int, to string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(from) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(to) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(fromfd), uintptr(unsafe.Pointer(_p0)), uintptr(tofd), uintptr(unsafe.Pointer(_p1)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Revoke(path string) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path)