1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-22 15:57:07 +00:00

internal/restic: Handle EINVAL for xattr on Solaris

Also make the errors a bit less verbose by not prepending the operation,
since pkg/xattr already does that. Old errors looked like

    Listxattr: xattr.list /myfiles/.zfs/snapshot: invalid argument
This commit is contained in:
greatroar 2022-08-01 12:42:56 +02:00
parent b9fa6e05bd
commit ad6ac680af

View file

@ -13,31 +13,39 @@ import (
// Getxattr retrieves extended attribute data associated with path.
func Getxattr(path, name string) ([]byte, error) {
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")
b, err := xattr.Get(path, name)
return b, handleXattrErr(err)
}
// Listxattr retrieves a list of names of extended attributes associated with the
// given path in the file system.
func Listxattr(path string) ([]string, error) {
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")
l, err := xattr.List(path)
return l, handleXattrErr(err)
}
// Setxattr associates name and data together as an attribute of path.
func Setxattr(path, name string, data []byte) error {
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")
return handleXattrErr(xattr.Set(path, name, data))
}
func handleXattrErr(err error) error {
switch e := err.(type) {
case nil:
return nil
case *xattr.Error:
// On Solaris, xattr not being supported on a file is signaled
// by EINVAL (https://github.com/pkg/xattr/issues/67).
// On Linux, xattr calls on files in an SMB/CIFS mount can return
// ENOATTR instead of ENOTSUP.
switch e.Err {
case syscall.EINVAL, syscall.ENOTSUP, xattr.ENOATTR:
return nil
}
return errors.WithStack(e)
default:
return errors.WithStack(e)
}
}