1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-01-21 06:48:35 +00:00
restic/internal/fs/meta_xattr.go
Michael Eischer ea1446f50b fs: prepare fd based metadataHandle
Add the skeleton, but leave filling in the details to later commits.
2024-11-30 19:17:25 +01:00

44 lines
1.1 KiB
Go

//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) {
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)
if err != nil {
if ignoreListError && isListxattrPermissionError(err) {
return nil, nil
}
return nil, err
}
extendedAttrs := make([]restic.ExtendedAttribute, 0, len(xattrs))
for _, attr := range xattrs {
attrVal, err := getxattr(path, attr)
if err != nil {
fmt.Fprintf(os.Stderr, "can not obtain extended attribute %v for %v:\n", attr, path)
continue
}
attr := restic.ExtendedAttribute{
Name: attr,
Value: attrVal,
}
extendedAttrs = append(extendedAttrs, attr)
}
return extendedAttrs, nil
}