tools/util_darwin.go: Remove use of direct syscalls

Previously, trying to compile `util_darwin.go` against a recent version
of `golang/sys` library failed with:

```
util_darwin.go:127:3: undefined: unix.SYS_CLONEFILEAT
```

Go v1.12 removed the ability to use direct syscalls. The clonefile
system calls was added to the latest `golang/sys` in
https://github.com/golang/go/issues/41366, so we can use that now.
This commit is contained in:
Stan Hu 2020-09-15 21:44:40 -07:00
parent 7dfe9fe110
commit 6ed8849319
3 changed files with 8 additions and 28 deletions

3
go.mod

@ -17,14 +17,13 @@ require (
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/ssgelm/cookiejarparser v1.0.1
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.5.1
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v0.0.0-20170210233622-6b67b3fab74d
golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
golang.org/x/sys v0.0.0-20190412213103-97732733099d
golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f
gopkg.in/jcmturner/goidentity.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)

6
go.sum

@ -41,11 +41,8 @@ github.com/ssgelm/cookiejarparser v1.0.1 h1:cRdXauUbOTFzTPJFaeiWbHnQ+tRGlpKKzvIK
github.com/ssgelm/cookiejarparser v1.0.1/go.mod h1:DUfC0mpjIzlDN7DzKjXpHj0qMI5m9VrZuz3wSlI+OEI=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
@ -68,8 +65,11 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f h1:6Sc1XOXTulBN6imkqo6XoAXDEzoQ4/ro6xy7Vn8+rOM=
golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/jcmturner/aescts.v1 v1.0.1 h1:cVVZBK2b1zY26haWB4vbBiZrfFQnfbTVrE3xZq6hrEw=
gopkg.in/jcmturner/aescts.v1 v1.0.1/go.mod h1:nsR8qBOg+OucoIW+WMhB3GspUQXq9XorLnQb9XtvcOo=

@ -9,7 +9,7 @@ import (
"os"
"strconv"
"strings"
"unsafe"
"syscall"
"github.com/git-lfs/git-lfs/errors"
"golang.org/x/sys/unix"
@ -112,30 +112,11 @@ func CloneFileByPath(dst, src string) (bool, error) {
}
func cloneFileSyscall(dst, src string) *CloneFileError {
srcCString, err := unix.BytePtrFromString(src)
err := unix.Clonefileat(C.AT_FDCWD, src, C.AT_FDCWD, dst, C.CLONE_NOFOLLOW)
if err != nil {
return &CloneFileError{errorString: err.Error()}
}
dstCString, err := unix.BytePtrFromString(dst)
if err != nil {
return &CloneFileError{errorString: err.Error()}
}
atFDCwd := C.AT_FDCWD // current directory.
_, _, errNo := unix.Syscall6(
unix.SYS_CLONEFILEAT,
uintptr(atFDCwd),
uintptr(unsafe.Pointer(srcCString)),
uintptr(atFDCwd),
uintptr(unsafe.Pointer(dstCString)),
uintptr(C.CLONE_NOFOLLOW),
0,
)
if errNo != 0 {
return &CloneFileError{
Unsupported: errNo == C.ENOTSUP,
errorString: fmt.Sprintf("%s. from %v to %v", unix.ErrnoName(errNo), src, dst),
Unsupported: err == syscall.ENOTSUP,
errorString: fmt.Sprintf("%s. from %v to %v", err, src, dst),
}
}