2024-11-03 14:09:59 +00:00
|
|
|
//go:build darwin || freebsd || linux || solaris
|
|
|
|
// +build darwin freebsd linux solaris
|
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/restic/restic/internal/debug"
|
|
|
|
"github.com/restic/restic/internal/restic"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (p *pathMetadataHandle) Xattr(ignoreListError bool) ([]restic.ExtendedAttribute, error) {
|
2024-11-03 15:32:57 +00:00
|
|
|
return xattrFromPath(p.Name(), ignoreListError)
|
|
|
|
}
|
|
|
|
|
|
|
|
func xattrFromPath(path string, ignoreListError bool) ([]restic.ExtendedAttribute, error) {
|
|
|
|
xattrs, err := listxattr(path)
|
|
|
|
debug.Log("fillExtendedAttributes(%v) %v %v", path, xattrs, err)
|
2024-11-03 14:09:59 +00:00
|
|
|
if err != nil {
|
|
|
|
if ignoreListError && isListxattrPermissionError(err) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
extendedAttrs := make([]restic.ExtendedAttribute, 0, len(xattrs))
|
|
|
|
for _, attr := range xattrs {
|
2024-11-03 15:32:57 +00:00
|
|
|
attrVal, err := getxattr(path, attr)
|
2024-11-03 14:09:59 +00:00
|
|
|
if err != nil {
|
2024-11-03 15:32:57 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "can not obtain extended attribute %v for %v:\n", attr, path)
|
2024-11-03 14:09:59 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
attr := restic.ExtendedAttribute{
|
|
|
|
Name: attr,
|
|
|
|
Value: attrVal,
|
|
|
|
}
|
|
|
|
|
|
|
|
extendedAttrs = append(extendedAttrs, attr)
|
|
|
|
}
|
|
|
|
|
|
|
|
return extendedAttrs, nil
|
|
|
|
}
|