2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-01 08:30:49 +00:00

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]] [[projects]]
name = "github.com/pkg/xattr" name = "github.com/pkg/xattr"
packages = ["."] packages = ["."]
revision = "23c75e3f6c1d8b13b3dd905b011a7f38a06044b7" revision = "1d7b7ffe7c46974a836eb583b7452f22de1c18cf"
version = "v0.2.1" version = "v0.2.3"
[[projects]] [[projects]]
name = "github.com/restic/chunker" name = "github.com/restic/chunker"

View File

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

View File

@ -10,7 +10,7 @@ Extended attribute support for Go (linux + darwin + freebsd).
### Example ### Example
``` ```go
const path = "/tmp/myfile" const path = "/tmp/myfile"
const prefix = "user." 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) { 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)) 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) { if e1 != syscall.Errno(0) {
return int(r0), e1 return int(r0), e1

View File

@ -2,6 +2,8 @@
package xattr package xattr
import "syscall"
// Get retrieves extended attribute data associated with path. // Get retrieves extended attribute data associated with path.
func Get(path, name string) ([]byte, error) { func Get(path, name string) ([]byte, error) {
// find size. // find size.
@ -30,7 +32,6 @@ func List(path string) ([]string, error) {
return nil, &Error{"xattr.List", path, "", err} return nil, &Error{"xattr.List", path, "", err}
} }
if size > 0 { if size > 0 {
buf := make([]byte, size) buf := make([]byte, size)
// Read into buffer of that size. // Read into buffer of that size.
read, err := listxattr(path, &buf[0], size, 0) 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. // Set associates name and data together as an attribute of path.
func Set(path, name string, data []byte) error { func Set(path, name string, data []byte) error {
var dataval *byte = nil var dataval *byte
datalen := len(data) datalen := len(data)
if datalen > 0 { if datalen > 0 {
dataval = &data[0] dataval = &data[0]
@ -62,3 +63,11 @@ func Remove(path, name string) error {
} }
return nil 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. // Set associates name and data together as an attribute of path.
func Set(path, name string, data []byte) error { func Set(path, name string, data []byte) error {
var dataval *byte = nil var dataval *byte
datalen := len(data) datalen := len(data)
if datalen > 0 { if datalen > 0 {
dataval = &data[0] dataval = &data[0]
@ -74,6 +74,14 @@ func Remove(path, name string) error {
return nil 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. // attrListToStrings converts a sequnce of attribute name entries to a []string.
// Each entry consists of a single byte containing the length // Each entry consists of a single byte containing the length
// of the attribute name, followed by the attribute name. // 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} return nil, &Error{"xattr.List", path, "", err}
} }
if size > 0 { 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 into buffer of that size.
read, err := syscall.Listxattr(path, buf) read, err := syscall.Listxattr(path, buf)
if err != nil { if err != nil {
@ -59,3 +61,11 @@ func Remove(path, name string) error {
} }
return nil 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) { func Test(t *testing.T) {
tmp, err := ioutil.TempFile("", "") tmp, err := ioutil.TempFile("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(tmp.Name()) 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")) err = Set(tmp.Name(), UserPrefix+"test", []byte("test-attr-value"))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -63,6 +67,11 @@ func TestNoData(t *testing.T) {
} }
defer os.Remove(tmp.Name()) 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{}) err = Set(tmp.Name(), UserPrefix+"test", []byte{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)