mirror of
https://github.com/restic/restic.git
synced 2025-08-25 23:47:29 +00:00
update nodeRestoreExtendedAttributes() for win
- also other platforms - move xattr include/exclude filter parsing into separate func Signed-off-by: Tesshu Flower <tflower@redhat.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// nodeRestoreExtendedAttributes is a no-op
|
||||
func nodeRestoreExtendedAttributes(_ *restic.Node, _ string) error {
|
||||
func nodeRestoreExtendedAttributes(_ *restic.Node, _ string, _ func(xattrName string) bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -217,8 +217,9 @@ func TestNodeRestoreAt(t *testing.T) {
|
||||
nodePath = filepath.Join(tempdir, test.Name)
|
||||
}
|
||||
rtest.OK(t, NodeCreateAt(&test, nodePath))
|
||||
// Restore metadata, restoring all xattrs
|
||||
rtest.OK(t, NodeRestoreMetadata(&test, nodePath, func(msg string) { rtest.OK(t, fmt.Errorf("Warning triggered for path: %s: %s", nodePath, msg)) },
|
||||
func(_ string) bool { return true } /* restore all xattrs */))
|
||||
func(_ string) bool { return true }))
|
||||
|
||||
fs := &Local{}
|
||||
meta, err := fs.OpenFile(nodePath, O_NOFOLLOW, true)
|
||||
|
@@ -69,15 +69,20 @@ func utimesNano(path string, atime, mtime int64, _ restic.NodeType) error {
|
||||
}
|
||||
|
||||
// restore extended attributes for windows
|
||||
func nodeRestoreExtendedAttributes(node *restic.Node, path string) (err error) {
|
||||
func nodeRestoreExtendedAttributes(node *restic.Node, path string, xattrSelectFilter func(xattrName string) bool) error {
|
||||
count := len(node.ExtendedAttributes)
|
||||
if count > 0 {
|
||||
eas := make([]extendedAttribute, count)
|
||||
for i, attr := range node.ExtendedAttributes {
|
||||
eas[i] = extendedAttribute{Name: attr.Name, Value: attr.Value}
|
||||
eas := []extendedAttribute{}
|
||||
for _, attr := range node.ExtendedAttributes {
|
||||
// Filter for xattrs we want to include/exclude
|
||||
if xattrSelectFilter(attr.Name) {
|
||||
eas = append(eas, extendedAttribute{Name: attr.Name, Value: attr.Value})
|
||||
}
|
||||
}
|
||||
if errExt := restoreExtendedAttributes(node.Type, path, eas); errExt != nil {
|
||||
return errExt
|
||||
if len(eas) > 0 {
|
||||
if errExt := restoreExtendedAttributes(node.Type, path, eas); errExt != nil {
|
||||
return errExt
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@@ -218,7 +218,7 @@ func restoreAndGetNode(t *testing.T, tempDir string, testNode *restic.Node, warn
|
||||
// If warning is not expected, this code should not get triggered.
|
||||
test.OK(t, fmt.Errorf("Warning triggered for path: %s: %s", testPath, msg))
|
||||
}
|
||||
})
|
||||
}, func(_ string) bool { return true })
|
||||
test.OK(t, errors.Wrapf(err, "Failed to restore metadata for: %s", testPath))
|
||||
|
||||
fs := &Local{}
|
||||
|
@@ -26,7 +26,8 @@ func setAndVerifyXattr(t *testing.T, file string, attrs []restic.ExtendedAttribu
|
||||
Type: restic.NodeTypeFile,
|
||||
ExtendedAttributes: attrs,
|
||||
}
|
||||
rtest.OK(t, nodeRestoreExtendedAttributes(node, file, func(_ string) bool { return true } /*restore all xattrs*/))
|
||||
/* restore all xattrs */
|
||||
rtest.OK(t, nodeRestoreExtendedAttributes(node, file, func(_ string) bool { return true }))
|
||||
|
||||
nodeActual := &restic.Node{
|
||||
Type: restic.NodeTypeFile,
|
||||
|
Reference in New Issue
Block a user