2017-02-02 11:23:13 +00:00
|
|
|
// +build !openbsd
|
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package restic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
2017-02-16 13:25:56 +00:00
|
|
|
|
2017-07-23 12:21:03 +00:00
|
|
|
"github.com/restic/restic/internal/errors"
|
|
|
|
|
2017-02-16 13:25:56 +00:00
|
|
|
"github.com/pkg/xattr"
|
2017-02-02 11:23:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2017-02-02 11:23:13 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
2017-02-18 10:35:04 +00:00
|
|
|
return b, errors.Wrap(e, "Getxattr")
|
2017-02-02 11:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2017-02-02 11:23:13 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
2017-02-18 10:35:04 +00:00
|
|
|
return s, errors.Wrap(e, "Listxattr")
|
2017-02-02 11:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2017-02-02 11:23:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-02-18 10:35:04 +00:00
|
|
|
return errors.Wrap(e, "Setxattr")
|
2017-02-02 11:23:13 +00:00
|
|
|
}
|