From 82458d4de0f6e9491bb75c866740ec1092dc1bc7 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 4 Mar 2017 14:23:15 +0100 Subject: [PATCH] Update github.com/pkg/xattr Closes #843 --- vendor/manifest | 2 +- vendor/src/github.com/pkg/xattr/README.md | 12 ++++-- vendor/src/github.com/pkg/xattr/xattr.go | 10 ++++- .../src/github.com/pkg/xattr/xattr_darwin.go | 43 ++++++++++--------- .../src/github.com/pkg/xattr/xattr_freebsd.go | 42 ++++++++++-------- .../src/github.com/pkg/xattr/xattr_linux.go | 41 ++++++++++-------- 6 files changed, 88 insertions(+), 62 deletions(-) diff --git a/vendor/manifest b/vendor/manifest index 53d94c88d..ec75a1f99 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -52,7 +52,7 @@ { "importpath": "github.com/pkg/xattr", "repository": "https://github.com/pkg/xattr", - "revision": "1d40b70a947cd8e8457e4715e1123f8e99f5f241", + "revision": "b867675798fa7708a444945602b452ca493f2272", "branch": "master" }, { diff --git a/vendor/src/github.com/pkg/xattr/README.md b/vendor/src/github.com/pkg/xattr/README.md index 9fb2e0d00..77d89567f 100644 --- a/vendor/src/github.com/pkg/xattr/README.md +++ b/vendor/src/github.com/pkg/xattr/README.md @@ -1,3 +1,7 @@ +[![GoDoc](https://godoc.org/github.com/pkg/xattr?status.svg)](http://godoc.org/github.com/pkg/xattr) +[![Go Report Card](https://goreportcard.com/badge/github.com/pkg/xattr)](https://goreportcard.com/report/github.com/pkg/xattr) +[![Build Status](https://travis-ci.org/pkg/xattr.svg?branch=master)](https://travis-ci.org/pkg/xattr) + xattr ===== Extended attribute support for Go (linux + darwin + freebsd). @@ -10,12 +14,12 @@ Extended attribute support for Go (linux + darwin + freebsd). const path = "/tmp/myfile" const prefix = "user." - if err = Setxattr(path, prefix+"test", []byte("test-attr-value")); err != nil { - t.Fatal(err) + if err := xattr.Setxattr(path, prefix+"test", []byte("test-attr-value")); err != nil { + log.Fatal(err) } var data []byte - data, err = Getxattr(path, prefix+"test"); err != nil { - t.Fatal(err) + data, err = xattr.Getxattr(path, prefix+"test"); err != nil { + log.Fatal(err) } ``` diff --git a/vendor/src/github.com/pkg/xattr/xattr.go b/vendor/src/github.com/pkg/xattr/xattr.go index a13007f8b..a4f06b7c3 100644 --- a/vendor/src/github.com/pkg/xattr/xattr.go +++ b/vendor/src/github.com/pkg/xattr/xattr.go @@ -1,3 +1,10 @@ +/* +Package xattr provides support for extended attributes on linux, darwin and freebsd. +Extended attributes are name:value pairs associated permanently with files and directories, +similar to the environment strings associated with a process. +An attribute may be defined or undefined. If it is defined, its value may be empty or non-empty. +More details you can find here: https://en.wikipedia.org/wiki/Extended_file_attributes +*/ package xattr // XAttrError records an error and the operation, file path and attribute that caused it. @@ -12,8 +19,7 @@ func (e *XAttrError) Error() string { return e.Op + " " + e.Path + " " + e.Name + ": " + e.Err.Error() } -// Convert an array of NULL terminated UTF-8 strings -// to a []string. +// nullTermToStrings converts an array of NULL terminated UTF-8 strings to a []string. func nullTermToStrings(buf []byte) (result []string) { offset := 0 for index, b := range buf { diff --git a/vendor/src/github.com/pkg/xattr/xattr_darwin.go b/vendor/src/github.com/pkg/xattr/xattr_darwin.go index 443d049f2..07c1228e3 100644 --- a/vendor/src/github.com/pkg/xattr/xattr_darwin.go +++ b/vendor/src/github.com/pkg/xattr/xattr_darwin.go @@ -2,44 +2,47 @@ package xattr -// Retrieve extended attribute data associated with path. +// Getxattr retrieves extended attribute data associated with path. func Getxattr(path, name string) ([]byte, error) { // find size. size, err := getxattr(path, name, nil, 0, 0, 0) if err != nil { return nil, &XAttrError{"getxattr", path, name, err} } - buf := make([]byte, size) - // Read into buffer of that size. - read, err := getxattr(path, name, &buf[0], size, 0, 0) - if err != nil { - return nil, &XAttrError{"getxattr", path, name, err} + if size > 0 { + buf := make([]byte, size) + // Read into buffer of that size. + read, err := getxattr(path, name, &buf[0], size, 0, 0) + if err != nil { + return nil, &XAttrError{"getxattr", path, name, err} + } + return buf[:read], nil } - return buf[:read], nil + return []byte{}, nil } -// Retrieves a list of names of extended attributes associated with the -// given path in the file system. +// Listxattr retrieves a list of names of extended attributes associated +// with the given path in the file system. func Listxattr(path string) ([]string, error) { // find size. size, err := listxattr(path, nil, 0, 0) if err != nil { return nil, &XAttrError{"listxattr", path, "", err} } - if size == 0 { - return []string{}, nil - } + if size > 0 { - buf := make([]byte, size) - // Read into buffer of that size. - read, err := listxattr(path, &buf[0], size, 0) - if err != nil { - return nil, &XAttrError{"listxattr", path, "", err} + buf := make([]byte, size) + // Read into buffer of that size. + read, err := listxattr(path, &buf[0], size, 0) + if err != nil { + return nil, &XAttrError{"listxattr", path, "", err} + } + return nullTermToStrings(buf[:read]), nil } - return nullTermToStrings(buf[:read]), nil + return []string{}, nil } -// Associates name and data together as an attribute of path. +// Setxattr associates name and data together as an attribute of path. func Setxattr(path, name string, data []byte) error { if err := setxattr(path, name, &data[0], len(data), 0, 0); err != nil { return &XAttrError{"setxattr", path, name, err} @@ -47,7 +50,7 @@ func Setxattr(path, name string, data []byte) error { return nil } -// Remove the attribute. +// Removexattr removes the attribute associated with the given path. func Removexattr(path, name string) error { if err := removexattr(path, name, 0); err != nil { return &XAttrError{"removexattr", path, name, err} diff --git a/vendor/src/github.com/pkg/xattr/xattr_freebsd.go b/vendor/src/github.com/pkg/xattr/xattr_freebsd.go index 66cf0066b..5173cd2a4 100644 --- a/vendor/src/github.com/pkg/xattr/xattr_freebsd.go +++ b/vendor/src/github.com/pkg/xattr/xattr_freebsd.go @@ -10,40 +10,46 @@ const ( EXTATTR_NAMESPACE_USER = 1 ) -// Retrieve extended attribute data associated with path. +// Getxattr retrieves extended attribute data associated with path. func Getxattr(path, name string) ([]byte, error) { // find size. size, err := extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, nil, 0) if err != nil { return nil, &XAttrError{"extattr_get_file", path, name, err} } - buf := make([]byte, size) - // Read into buffer of that size. - read, err := extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, &buf[0], size) - if err != nil { - return nil, &XAttrError{"extattr_get_file", path, name, err} + if size > 0 { + buf := make([]byte, size) + // Read into buffer of that size. + read, err := extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, &buf[0], size) + if err != nil { + return nil, &XAttrError{"extattr_get_file", path, name, err} + } + return buf[:read], nil } - return buf[:read], nil + return []byte{}, nil } -// Retrieves a list of names of extended attributes associated with the -// given path in the file system. +// Listxattr retrieves a list of names of extended attributes associated +// with the given path in the file system. func Listxattr(path string) ([]string, error) { // find size. size, err := extattr_list_file(path, EXTATTR_NAMESPACE_USER, nil, 0) if err != nil { return nil, &XAttrError{"extattr_list_file", path, "", err} } - buf := make([]byte, size) - // Read into buffer of that size. - read, err := extattr_list_file(path, EXTATTR_NAMESPACE_USER, &buf[0], size) - if err != nil { - return nil, &XAttrError{"extattr_list_file", path, "", err} + if size > 0 { + buf := make([]byte, size) + // Read into buffer of that size. + read, err := extattr_list_file(path, EXTATTR_NAMESPACE_USER, &buf[0], size) + if err != nil { + return nil, &XAttrError{"extattr_list_file", path, "", err} + } + return attrListToStrings(buf[:read]), nil } - return attrListToStrings(buf[:read]), nil + return []string{}, nil } -// Associates name and data together as an attribute of path. +// Setxattr associates name and data together as an attribute of path. func Setxattr(path, name string, data []byte) error { written, err := extattr_set_file(path, EXTATTR_NAMESPACE_USER, name, &data[0], len(data)) if err != nil { @@ -55,7 +61,7 @@ func Setxattr(path, name string, data []byte) error { return nil } -// Remove the attribute. +// Removexattr removes the attribute associated with the given path. func Removexattr(path, name string) error { if err := extattr_delete_file(path, EXTATTR_NAMESPACE_USER, name); err != nil { return &XAttrError{"extattr_delete_file", path, name, err} @@ -63,7 +69,7 @@ func Removexattr(path, name string) error { return nil } -// Convert 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 // of the attribute name, followed by the attribute name. // The name is _not_ terminated by NUL. diff --git a/vendor/src/github.com/pkg/xattr/xattr_linux.go b/vendor/src/github.com/pkg/xattr/xattr_linux.go index b180d12ab..73973c16a 100644 --- a/vendor/src/github.com/pkg/xattr/xattr_linux.go +++ b/vendor/src/github.com/pkg/xattr/xattr_linux.go @@ -4,40 +4,46 @@ package xattr import "syscall" -// Retrieve extended attribute data associated with path. +// Getxattr retrieves extended attribute data associated with path. func Getxattr(path, name string) ([]byte, error) { // find size. size, err := syscall.Getxattr(path, name, nil) if err != nil { return nil, &XAttrError{"getxattr", path, name, err} } - data := make([]byte, size) - // Read into buffer of that size. - read, err := syscall.Getxattr(path, name, data) - if err != nil { - return nil, &XAttrError{"getxattr", path, name, err} + if size > 0 { + data := make([]byte, size) + // Read into buffer of that size. + read, err := syscall.Getxattr(path, name, data) + if err != nil { + return nil, &XAttrError{"getxattr", path, name, err} + } + return data[:read], nil } - return data[:read], nil + return []byte{}, nil } -// Retrieves a list of names of extended attributes associated with the -// given path in the file system. +// Listxattr retrieves a list of names of extended attributes associated +// with the given path in the file system. func Listxattr(path string) ([]string, error) { // find size. size, err := syscall.Listxattr(path, nil) if err != nil { return nil, &XAttrError{"listxattr", path, "", err} } - buf := make([]byte, size) - // Read into buffer of that size. - read, err := syscall.Listxattr(path, buf) - if err != nil { - return nil, &XAttrError{"listxattr", path, "", err} + if size > 0 { + buf := make([]byte, size) + // Read into buffer of that size. + read, err := syscall.Listxattr(path, buf) + if err != nil { + return nil, &XAttrError{"listxattr", path, "", err} + } + return nullTermToStrings(buf[:read]), nil } - return nullTermToStrings(buf[:read]), nil + return []string{}, nil } -// Associates name and data together as an attribute of path. +// Setxattr associates name and data together as an attribute of path. func Setxattr(path, name string, data []byte) error { if err := syscall.Setxattr(path, name, data, 0); err != nil { return &XAttrError{"setxattr", path, name, err} @@ -45,7 +51,8 @@ func Setxattr(path, name string, data []byte) error { return nil } -// Remove the attribute. +// Removexattr removes the attribute associated +// with the given path. func Removexattr(path, name string) error { if err := syscall.Removexattr(path, name); err != nil { return &XAttrError{"removexattr", path, name, err}