mirror of
https://github.com/golang/go
synced 2024-11-23 09:20:05 -07:00
os: add support for long path names on freebsd RemoveAll
Follow CL 146020 and enable RemoveAll based on Unlinkat and Openat on freebsd. Since the layout of syscall.Stat_t changes in FreeBSD 12, Fstatat needs a compatibility wrapper akin to Fstatat in x/sys/unix. See CL 138595 and CL 136816 for details. Updates #27029 Change-Id: I8851a5b7fa658eaa6e69a1693150b16d9a68f36a Reviewed-on: https://go-review.googlesource.com/c/146597 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Yuval Pavel Zholkover <paulzhol@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
efc185029b
commit
fa466a4f5a
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build linux darwin freebsd openbsd netbsd dragonfly
|
// +build linux darwin openbsd netbsd dragonfly
|
||||||
|
|
||||||
package unix
|
package unix
|
||||||
|
|
||||||
|
47
src/internal/syscall/unix/at_freebsd.go
Normal file
47
src/internal/syscall/unix/at_freebsd.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2018 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package unix
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
AT_REMOVEDIR = 0x800
|
||||||
|
AT_SYMLINK_NOFOLLOW = 0x200
|
||||||
|
)
|
||||||
|
|
||||||
|
func Unlinkat(dirfd int, path string, flags int) error {
|
||||||
|
p, err := syscall.BytePtrFromString(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, errno := syscall.Syscall(syscall.SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags))
|
||||||
|
if errno != 0 {
|
||||||
|
return errno
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
|
||||||
|
p, err := syscall.BytePtrFromString(path)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fd, _, errno := syscall.Syscall6(syscall.SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0)
|
||||||
|
if errno != 0 {
|
||||||
|
return 0, errno
|
||||||
|
}
|
||||||
|
|
||||||
|
return int(fd), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error {
|
||||||
|
return syscall.Fstatat(dirfd, path, stat, flags)
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package unix
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const unlinkatTrap uintptr = syscall.SYS_UNLINKAT
|
|
||||||
const openatTrap uintptr = syscall.SYS_OPENAT
|
|
||||||
const fstatatTrap uintptr = syscall.SYS_FSTATAT
|
|
||||||
|
|
||||||
const AT_REMOVEDIR = 0x800
|
|
||||||
const AT_SYMLINK_NOFOLLOW = 0x200
|
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build linux darwin openbsd netbsd dragonfly solaris
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||||
|
|
||||||
package os
|
package os
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build !linux,!darwin,!openbsd,!netbsd,!dragonfly,!solaris
|
// +build !linux,!darwin,!freebsd,!openbsd,!netbsd,!dragonfly,!solaris
|
||||||
|
|
||||||
package os
|
package os
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ func TestRemoveAllLarge(t *testing.T) {
|
|||||||
|
|
||||||
func TestRemoveAllLongPath(t *testing.T) {
|
func TestRemoveAllLongPath(t *testing.T) {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux", "darwin", "openbsd", "netbsd", "dragonfly", "solaris":
|
case "linux", "darwin", "freebsd", "openbsd", "netbsd", "dragonfly", "solaris":
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
t.Skip("skipping for not implemented platforms")
|
t.Skip("skipping for not implemented platforms")
|
||||||
@ -212,7 +212,7 @@ func TestRemoveAllLongPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestRemoveAllDot(t *testing.T) {
|
func TestRemoveAllDot(t *testing.T) {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux", "darwin", "openbsd", "netbsd", "dragonfly", "solaris":
|
case "linux", "darwin", "freebsd", "openbsd", "netbsd", "dragonfly", "solaris":
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
t.Skip("skipping for not implemented platforms")
|
t.Skip("skipping for not implemented platforms")
|
||||||
|
@ -223,6 +223,20 @@ func Fstat(fd int, st *Stat_t) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Fstatat(fd int, path string, st *Stat_t, flags int) (err error) {
|
||||||
|
var oldStat stat_freebsd11_t
|
||||||
|
if supportsABI(_ino64First) {
|
||||||
|
return fstatat_freebsd12(fd, path, st, flags)
|
||||||
|
}
|
||||||
|
err = fstatat(fd, path, &oldStat, flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
st.convertFrom(&oldStat)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func Statfs(path string, st *Statfs_t) (err error) {
|
func Statfs(path string, st *Statfs_t) (err error) {
|
||||||
var oldStatfs statfs_freebsd11_t
|
var oldStatfs statfs_freebsd11_t
|
||||||
if supportsABI(_ino64First) {
|
if supportsABI(_ino64First) {
|
||||||
@ -403,6 +417,7 @@ func convertFromDirents11(buf []byte, old []byte) int {
|
|||||||
//sys Fpathconf(fd int, name int) (val int, err error)
|
//sys Fpathconf(fd int, name int) (val int, err error)
|
||||||
//sys fstat(fd int, stat *stat_freebsd11_t) (err error)
|
//sys fstat(fd int, stat *stat_freebsd11_t) (err error)
|
||||||
//sys fstat_freebsd12(fd int, stat *Stat_t) (err error) = _SYS_FSTAT_FREEBSD12
|
//sys fstat_freebsd12(fd int, stat *Stat_t) (err error) = _SYS_FSTAT_FREEBSD12
|
||||||
|
//sys fstatat(fd int, path string, stat *stat_freebsd11_t, flags int) (err error)
|
||||||
//sys fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) = _SYS_FSTATAT_FREEBSD12
|
//sys fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) = _SYS_FSTATAT_FREEBSD12
|
||||||
//sys fstatfs(fd int, stat *statfs_freebsd11_t) (err error)
|
//sys fstatfs(fd int, stat *statfs_freebsd11_t) (err error)
|
||||||
//sys fstatfs_freebsd12(fd int, stat *Statfs_t) (err error) = _SYS_FSTATFS_FREEBSD12
|
//sys fstatfs_freebsd12(fd int, stat *Statfs_t) (err error) = _SYS_FSTATFS_FREEBSD12
|
||||||
|
@ -483,6 +483,21 @@ func fstat_freebsd12(fd int, stat *Stat_t) (err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
|
func fstatat(fd int, path string, stat *stat_freebsd11_t, flags int) (err error) {
|
||||||
|
var _p0 *byte
|
||||||
|
_p0, err = BytePtrFromString(path)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) {
|
func fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) {
|
||||||
var _p0 *byte
|
var _p0 *byte
|
||||||
_p0, err = BytePtrFromString(path)
|
_p0, err = BytePtrFromString(path)
|
||||||
|
@ -483,6 +483,21 @@ func fstat_freebsd12(fd int, stat *Stat_t) (err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
|
func fstatat(fd int, path string, stat *stat_freebsd11_t, flags int) (err error) {
|
||||||
|
var _p0 *byte
|
||||||
|
_p0, err = BytePtrFromString(path)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) {
|
func fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) {
|
||||||
var _p0 *byte
|
var _p0 *byte
|
||||||
_p0, err = BytePtrFromString(path)
|
_p0, err = BytePtrFromString(path)
|
||||||
|
@ -483,6 +483,21 @@ func fstat_freebsd12(fd int, stat *Stat_t) (err error) {
|
|||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
|
func fstatat(fd int, path string, stat *stat_freebsd11_t, flags int) (err error) {
|
||||||
|
var _p0 *byte
|
||||||
|
_p0, err = BytePtrFromString(path)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _, e1 := Syscall6(SYS_FSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
func fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) {
|
func fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) {
|
||||||
var _p0 *byte
|
var _p0 *byte
|
||||||
_p0, err = BytePtrFromString(path)
|
_p0, err = BytePtrFromString(path)
|
||||||
|
Loading…
Reference in New Issue
Block a user