2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-29 23:20:49 +00:00
restic/internal/restic/node_xattr.go

44 lines
1.1 KiB
Go
Raw Normal View History

//go:build darwin || freebsd || linux || solaris
// +build darwin freebsd linux solaris
package restic
import (
"syscall"
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/errors"
"github.com/pkg/xattr"
)
// Getxattr retrieves extended attribute data associated with path.
func Getxattr(path, name string) ([]byte, error) {
2017-04-18 19:39:55 +00:00
b, e := xattr.Get(path, name)
if err, ok := e.(*xattr.Error); ok &&
(err.Err == syscall.ENOTSUP || err.Err == xattr.ENOATTR) {
return nil, nil
}
return b, errors.Wrap(e, "Getxattr")
}
// Listxattr retrieves a list of names of extended attributes associated with the
// given path in the file system.
func Listxattr(path string) ([]string, error) {
2017-04-18 19:39:55 +00:00
s, e := xattr.List(path)
if err, ok := e.(*xattr.Error); ok &&
(err.Err == syscall.ENOTSUP || err.Err == xattr.ENOATTR) {
return nil, nil
}
return s, errors.Wrap(e, "Listxattr")
}
// Setxattr associates name and data together as an attribute of path.
func Setxattr(path, name string, data []byte) error {
2017-04-18 19:39:55 +00:00
e := xattr.Set(path, name, data)
if err, ok := e.(*xattr.Error); ok &&
(err.Err == syscall.ENOTSUP || err.Err == xattr.ENOATTR) {
return nil
}
return errors.Wrap(e, "Setxattr")
}