Continue if extended attribute cannot be read

This commit is contained in:
Alexander Neumann 2017-02-16 14:25:56 +01:00
parent 6df2f9e5ba
commit ef52d15edd
2 changed files with 26 additions and 15 deletions

View file

@ -604,19 +604,29 @@ func (node *Node) fillExtendedAttributes(path string) error {
if node.Type == "symlink" { if node.Type == "symlink" {
return nil return nil
} }
xattrs, err := Listxattr(path) xattrs, err := Listxattr(path)
if err == nil { debug.Log("fillExtendedAttributes(%v) %v %v", path, xattrs, err)
node.ExtendedAttributes = make([]ExtendedAttribute, len(xattrs)) if err != nil {
for i, attr := range xattrs { return err
attrVal, err := Getxattr(path, attr)
if err != nil {
return errors.Errorf("can not obtain extended attribute %v for %v:\n", attr, path)
}
node.ExtendedAttributes[i].Name = attr
node.ExtendedAttributes[i].Value = attrVal
}
} }
return err
node.ExtendedAttributes = make([]ExtendedAttribute, 0, len(xattrs))
for _, attr := range xattrs {
attrVal, err := Getxattr(path, attr)
if err != nil {
fmt.Fprintf(os.Stderr, "can not obtain extended attribute %v for %v:\n", attr, path)
continue
}
attr := ExtendedAttribute{
Name: attr,
Value: attrVal,
}
node.ExtendedAttributes = append(node.ExtendedAttributes, attr)
}
return nil
} }
type statT interface { type statT interface {

View file

@ -4,13 +4,14 @@
package restic package restic
import ( import (
"github.com/ivaxer/go-xattr"
"syscall" "syscall"
"github.com/pkg/xattr"
) )
// Getxattr retrieves extended attribute data associated with path. // Getxattr retrieves extended attribute data associated with path.
func Getxattr(path, name string) ([]byte, error) { func Getxattr(path, name string) ([]byte, error) {
b, e := xattr.Get(path, name) b, e := xattr.Getxattr(path, name)
if e == syscall.ENOTSUP { if e == syscall.ENOTSUP {
return nil, nil return nil, nil
} }
@ -20,7 +21,7 @@ func Getxattr(path, name string) ([]byte, error) {
// Listxattr retrieves a list of names of extended attributes associated with the // Listxattr retrieves a list of names of extended attributes associated with the
// given path in the file system. // given path in the file system.
func Listxattr(path string) ([]string, error) { func Listxattr(path string) ([]string, error) {
s, e := xattr.List(path) s, e := xattr.Listxattr(path)
if e == syscall.ENOTSUP { if e == syscall.ENOTSUP {
return nil, nil return nil, nil
} }
@ -29,7 +30,7 @@ func Listxattr(path string) ([]string, error) {
// Setxattr 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 { func Setxattr(path, name string, data []byte) error {
e := xattr.Set(path, name, data) e := xattr.Setxattr(path, name, data)
if e == syscall.ENOTSUP { if e == syscall.ENOTSUP {
return nil return nil
} }