2022-01-10 13:34:18 +05:30
|
|
|
//go:build darwin || freebsd || linux || solaris
|
|
|
|
// +build darwin freebsd linux solaris
|
2017-02-02 12:23:13 +01:00
|
|
|
|
|
|
|
package restic
|
|
|
|
|
|
|
|
import (
|
2024-02-22 17:31:20 -07:00
|
|
|
"os"
|
2017-02-02 12:23:13 +01:00
|
|
|
"syscall"
|
2017-02-16 14:25:56 +01:00
|
|
|
|
2017-07-23 14:21:03 +02:00
|
|
|
"github.com/restic/restic/internal/errors"
|
|
|
|
|
2017-02-16 14:25:56 +01:00
|
|
|
"github.com/pkg/xattr"
|
2017-02-02 12:23:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Getxattr retrieves extended attribute data associated with path.
|
|
|
|
func Getxattr(path, name string) ([]byte, error) {
|
2023-06-19 14:24:47 -04:00
|
|
|
b, err := xattr.LGet(path, name)
|
2022-08-01 12:42:56 +02:00
|
|
|
return b, handleXattrErr(err)
|
2017-02-02 12:23:13 +01: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) {
|
2023-06-19 14:24:47 -04:00
|
|
|
l, err := xattr.LList(path)
|
2022-08-01 12:42:56 +02:00
|
|
|
return l, handleXattrErr(err)
|
2017-02-02 12:23:13 +01:00
|
|
|
}
|
|
|
|
|
2024-01-31 20:48:03 +01:00
|
|
|
func IsListxattrPermissionError(err error) bool {
|
|
|
|
var xerr *xattr.Error
|
|
|
|
if errors.As(err, &xerr) {
|
|
|
|
return xerr.Op == "xattr.list" && errors.Is(xerr.Err, os.ErrPermission)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-02-02 12:23:13 +01:00
|
|
|
// Setxattr associates name and data together as an attribute of path.
|
|
|
|
func Setxattr(path, name string, data []byte) error {
|
2023-06-19 14:24:47 -04:00
|
|
|
return handleXattrErr(xattr.LSet(path, name, data))
|
2022-08-01 12:42:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func handleXattrErr(err error) error {
|
|
|
|
switch e := err.(type) {
|
|
|
|
case nil:
|
2017-02-02 12:23:13 +01:00
|
|
|
return nil
|
2022-08-01 12:42:56 +02:00
|
|
|
|
|
|
|
case *xattr.Error:
|
|
|
|
// On Linux, xattr calls on files in an SMB/CIFS mount can return
|
|
|
|
// ENOATTR instead of ENOTSUP.
|
|
|
|
switch e.Err {
|
2022-08-21 10:47:05 +02:00
|
|
|
case syscall.ENOTSUP, xattr.ENOATTR:
|
2022-08-01 12:42:56 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return errors.WithStack(e)
|
|
|
|
|
|
|
|
default:
|
|
|
|
return errors.WithStack(e)
|
2017-02-02 12:23:13 +01:00
|
|
|
}
|
|
|
|
}
|
2024-02-22 17:31:20 -07:00
|
|
|
|
|
|
|
// restoreGenericAttributes is no-op.
|
2024-02-22 17:52:26 -07:00
|
|
|
func (node *Node) restoreGenericAttributes(_ string, warn func(msg string)) error {
|
|
|
|
return node.handleAllUnknownGenericAttributesFound(warn)
|
2024-02-22 17:31:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// fillGenericAttributes is a no-op.
|
|
|
|
func (node *Node) fillGenericAttributes(_ string, _ os.FileInfo, _ *statT) (allowExtended bool, err error) {
|
|
|
|
return true, nil
|
|
|
|
}
|