Commit 4d1e95bb authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

os: add support for long path names on solaris RemoveAll

Follow CL 146020 and enable RemoveAll based on Unlinkat and Openat on
solaris.

Updates #27029

Change-Id: I0b0e92f4422fa960a13dcd3e9adb57cd23f09ed4
Reviewed-on: https://go-review.googlesource.com/c/145839
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 86ad85ce
// 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.
#include "textflag.h"
// System calls for Solaris are implemented in runtime/syscall_solaris.go
TEXT ·sysvicall6(SB),NOSPLIT,$0-88
JMP syscall·sysvicall6(SB)
// 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"
)
// Implemented in runtime/syscall_solaris.go.
func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
//go:cgo_import_dynamic libc_fstatat fstatat "libc.so"
//go:cgo_import_dynamic libc_openat openat "libc.so"
//go:cgo_import_dynamic libc_unlinkat unlinkat "libc.so"
//go:linkname procFstatat libc_fstatat
//go:linkname procOpenat libc_openat
//go:linkname procUnlinkat libc_unlinkat
var (
procFstatat,
procOpenat,
procUnlinkat uintptr
)
const AT_REMOVEDIR = 0x1
const AT_SYMLINK_NOFOLLOW = 0x1000
func Unlinkat(dirfd int, path string, flags int) error {
var p *byte
p, err := syscall.BytePtrFromString(path)
if err != nil {
return err
}
_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procUnlinkat)), 3, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), 0, 0, 0)
if errno != 0 {
return errno
}
return nil
}
func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
var p *byte
p, err := syscall.BytePtrFromString(path)
if err != nil {
return 0, err
}
fd, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procOpenat)), 4, 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 {
var p *byte
p, err := syscall.BytePtrFromString(path)
if err != nil {
return err
}
_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procFstatat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
if errno != 0 {
return errno
}
return nil
}
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build linux darwin openbsd netbsd dragonfly
// +build linux darwin openbsd netbsd dragonfly solaris
package os
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !linux,!darwin,!openbsd,!netbsd,!dragonfly
// +build !linux,!darwin,!openbsd,!netbsd,!dragonfly,!solaris
package os
......
......@@ -153,7 +153,7 @@ func TestRemoveAllLarge(t *testing.T) {
func TestRemoveAllLongPath(t *testing.T) {
switch runtime.GOOS {
case "linux", "darwin", "openbsd", "netbsd", "dragonfly":
case "linux", "darwin", "openbsd", "netbsd", "dragonfly", "solaris":
break
default:
t.Skip("skipping for not implemented platforms")
......@@ -201,7 +201,7 @@ func TestRemoveAllLongPath(t *testing.T) {
func TestRemoveAllDot(t *testing.T) {
switch runtime.GOOS {
case "linux", "darwin", "openbsd", "netbsd", "dragonfly":
case "linux", "darwin", "openbsd", "netbsd", "dragonfly", "solaris":
break
default:
t.Skip("skipping for not implemented platforms")
......
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