restic: also fix file path when reading windows xattrs

This commit is contained in:
Michael Eischer
2024-06-14 21:15:46 +02:00
parent 267cd62ae4
commit 20a6c526e5
2 changed files with 20 additions and 19 deletions

View File

@@ -103,3 +103,21 @@ func ClearAttribute(path string, attribute uint32) error {
}
return nil
}
// OpenHandleForEA return a file handle for file or dir for setting/getting EAs
func OpenHandleForEA(nodeType, path string) (handle windows.Handle, err error) {
path = fixpath(path)
switch nodeType {
case "file":
utf16Path := windows.StringToUTF16Ptr(path)
fileAccessRightReadWriteEA := (0x8 | 0x10)
handle, err = windows.CreateFile(utf16Path, uint32(fileAccessRightReadWriteEA), 0, nil, windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL, 0)
case "dir":
utf16Path := windows.StringToUTF16Ptr(path)
fileAccessRightReadWriteEA := (0x8 | 0x10)
handle, err = windows.CreateFile(utf16Path, uint32(fileAccessRightReadWriteEA), 0, nil, windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL|windows.FILE_FLAG_BACKUP_SEMANTICS, 0)
default:
return 0, nil
}
return handle, err
}