github.com/advanderveer/restic@v0.8.1-0.20171209104529-42a8c19aaea6/internal/restic/node_xattr.go (about)

     1  // +build !openbsd
     2  // +build !windows
     3  
     4  package restic
     5  
     6  import (
     7  	"syscall"
     8  
     9  	"github.com/restic/restic/internal/errors"
    10  
    11  	"github.com/pkg/xattr"
    12  )
    13  
    14  // Getxattr retrieves extended attribute data associated with path.
    15  func Getxattr(path, name string) ([]byte, error) {
    16  	b, e := xattr.Get(path, name)
    17  	if err, ok := e.(*xattr.Error); ok && err.Err == syscall.ENOTSUP {
    18  		return nil, nil
    19  	}
    20  	return b, errors.Wrap(e, "Getxattr")
    21  }
    22  
    23  // Listxattr retrieves a list of names of extended attributes associated with the
    24  // given path in the file system.
    25  func Listxattr(path string) ([]string, error) {
    26  	s, e := xattr.List(path)
    27  	if err, ok := e.(*xattr.Error); ok && err.Err == syscall.ENOTSUP {
    28  		return nil, nil
    29  	}
    30  	return s, errors.Wrap(e, "Listxattr")
    31  }
    32  
    33  // Setxattr associates name and data together as an attribute of path.
    34  func Setxattr(path, name string, data []byte) error {
    35  	e := xattr.Set(path, name, data)
    36  	if err, ok := e.(*xattr.Error); ok && err.Err == syscall.ENOTSUP {
    37  		return nil
    38  	}
    39  	return errors.Wrap(e, "Setxattr")
    40  }