mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 23:06:32 +00:00
Merge pull request #3845 from greatroar/solaris-xattr
internal/restic: Handle EINVAL for xattr on Solaris
This commit is contained in:
commit
7d14b1baf1
@ -13,31 +13,39 @@ import (
|
|||||||
|
|
||||||
// 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, err := xattr.Get(path, name)
|
||||||
if err, ok := e.(*xattr.Error); ok &&
|
return b, handleXattrErr(err)
|
||||||
(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
|
// 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)
|
l, err := xattr.List(path)
|
||||||
if err, ok := e.(*xattr.Error); ok &&
|
return l, handleXattrErr(err)
|
||||||
(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.
|
// 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)
|
return handleXattrErr(xattr.Set(path, name, data))
|
||||||
if err, ok := e.(*xattr.Error); ok &&
|
}
|
||||||
(err.Err == syscall.ENOTSUP || err.Err == xattr.ENOATTR) {
|
|
||||||
|
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 nil
|
||||||
}
|
}
|
||||||
return errors.Wrap(e, "Setxattr")
|
return errors.WithStack(e)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return errors.WithStack(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user