Update vendored library github.com/pkg/xattr

This commit is contained in:
Alexander Neumann 2018-03-30 12:38:37 +02:00
parent 19035e977b
commit 75946e7c58
9 changed files with 48 additions and 11 deletions

4
Gopkg.lock generated
View file

@ -136,8 +136,8 @@
[[projects]]
name = "github.com/pkg/xattr"
packages = ["."]
revision = "23c75e3f6c1d8b13b3dd905b011a7f38a06044b7"
version = "v0.2.1"
revision = "1d7b7ffe7c46974a836eb583b7452f22de1c18cf"
version = "v0.2.3"
[[projects]]
name = "github.com/restic/chunker"

View file

@ -2,8 +2,9 @@ language: go
sudo: false
go:
- 1.8
- tip
- "1.8.x"
- "1.9.x"
- "1.10"
os:
- linux

View file

@ -10,7 +10,7 @@ Extended attribute support for Go (linux + darwin + freebsd).
### Example
```
```go
const path = "/tmp/myfile"
const prefix = "user."

1
vendor/github.com/pkg/xattr/go.mod generated vendored Normal file
View file

@ -0,0 +1 @@
module "github.com/pkg/xattr"

View file

@ -8,7 +8,6 @@ import (
)
func getxattr(path string, name string, value *byte, size int, pos int, options int) (int, error) {
r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))), uintptr(unsafe.Pointer(syscall.StringBytePtr(name))), uintptr(unsafe.Pointer(value)), uintptr(size), uintptr(pos), uintptr(options))
if e1 != syscall.Errno(0) {
return int(r0), e1

View file

@ -2,6 +2,8 @@
package xattr
import "syscall"
// Get retrieves extended attribute data associated with path.
func Get(path, name string) ([]byte, error) {
// find size.
@ -30,7 +32,6 @@ func List(path string) ([]string, error) {
return nil, &Error{"xattr.List", path, "", err}
}
if size > 0 {
buf := make([]byte, size)
// Read into buffer of that size.
read, err := listxattr(path, &buf[0], size, 0)
@ -44,7 +45,7 @@ func List(path string) ([]string, error) {
// Set associates name and data together as an attribute of path.
func Set(path, name string, data []byte) error {
var dataval *byte = nil
var dataval *byte
datalen := len(data)
if datalen > 0 {
dataval = &data[0]
@ -62,3 +63,11 @@ func Remove(path, name string) error {
}
return nil
}
// Supported checks if filesystem supports extended attributes
func Supported(path string) bool {
if _, err := listxattr(path, nil, 0, 0); err != nil {
return err != syscall.ENOTSUP
}
return true
}

View file

@ -51,7 +51,7 @@ func List(path string) ([]string, error) {
// Set associates name and data together as an attribute of path.
func Set(path, name string, data []byte) error {
var dataval *byte = nil
var dataval *byte
datalen := len(data)
if datalen > 0 {
dataval = &data[0]
@ -74,6 +74,14 @@ func Remove(path, name string) error {
return nil
}
// Supported checks if filesystem supports extended attributes
func Supported(path string) bool {
if _, err := extattr_list_file(path, EXTATTR_NAMESPACE_USER, nil, 0); err != nil {
return err != syscall.ENOTSUP
}
return true
}
// attrListToStrings converts a sequnce of attribute name entries to a []string.
// Each entry consists of a single byte containing the length
// of the attribute name, followed by the attribute name.

View file

@ -32,7 +32,9 @@ func List(path string) ([]string, error) {
return nil, &Error{"xattr.List", path, "", err}
}
if size > 0 {
buf := make([]byte, size)
// `size + 1` because of ERANGE error when reading
// from a SMB1 mount point (https://github.com/pkg/xattr/issues/16).
buf := make([]byte, size+1)
// Read into buffer of that size.
read, err := syscall.Listxattr(path, buf)
if err != nil {
@ -59,3 +61,11 @@ func Remove(path, name string) error {
}
return nil
}
// Supported checks if filesystem supports extended attributes
func Supported(path string) bool {
if _, err := syscall.Listxattr(path, nil); err != nil {
return err != syscall.ENOTSUP
}
return true
}

View file

@ -12,12 +12,16 @@ const UserPrefix = "user."
func Test(t *testing.T) {
tmp, err := ioutil.TempFile("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmp.Name())
// Check if filesystem supports extended attributes
if !Supported(tmp.Name()) {
t.Skip("Skipping test - filesystem does not support extended attributes")
}
err = Set(tmp.Name(), UserPrefix+"test", []byte("test-attr-value"))
if err != nil {
t.Fatal(err)
@ -63,6 +67,11 @@ func TestNoData(t *testing.T) {
}
defer os.Remove(tmp.Name())
// Check if filesystem supports extended attributes
if !Supported(tmp.Name()) {
t.Skip("Skipping test - filesystem does not support extended attributes")
}
err = Set(tmp.Name(), UserPrefix+"test", []byte{})
if err != nil {
t.Fatal(err)