Add missing return to fix failing test

This commit is contained in:
aneesh-n 2024-06-05 22:40:21 -06:00
parent 7a48c9ebd7
commit 2101dfe448
No known key found for this signature in database
GPG Key ID: 6F5A52831C046F44

View File

@ -88,16 +88,13 @@ func (node Node) restoreExtendedAttributes(path string) (err error) {
// fill extended attributes in the node. This also includes the Generic attributes for windows. // fill extended attributes in the node. This also includes the Generic attributes for windows.
func (node *Node) fillExtendedAttributes(path string, _ bool) (err error) { func (node *Node) fillExtendedAttributes(path string, _ bool) (err error) {
var fileHandle windows.Handle var fileHandle windows.Handle
fileHandle, err = getFileHandleForEA(node.Type, path) if fileHandle, err = getFileHandleForEA(node.Type, path); fileHandle == 0 {
return nil
}
if err != nil { if err != nil {
return errors.Errorf("get EA failed while opening file handle for path %v, with: %v", path, err) return errors.Errorf("get EA failed while opening file handle for path %v, with: %v", path, err)
} }
defer func() { defer closeFileHandle(fileHandle, path) // Replaced inline defer with named function call
err := windows.CloseHandle(fileHandle)
if err != nil {
debug.Log("Error closing file handle for %s: %v\n", path, err)
}
}()
//Get the windows Extended Attributes using the file handle //Get the windows Extended Attributes using the file handle
var extAtts []fs.ExtendedAttribute var extAtts []fs.ExtendedAttribute
extAtts, err = fs.GetFileEA(fileHandle) extAtts, err = fs.GetFileEA(fileHandle)
@ -138,20 +135,26 @@ func getFileHandleForEA(nodeType, path string) (handle windows.Handle, err error
return handle, err return handle, err
} }
// closeFileHandle safely closes a file handle and logs any errors.
func closeFileHandle(fileHandle windows.Handle, path string) {
err := windows.CloseHandle(fileHandle)
if err != nil {
debug.Log("Error closing file handle for %s: %v\n", path, err)
}
}
// restoreExtendedAttributes handles restore of the Windows Extended Attributes to the specified path. // restoreExtendedAttributes handles restore of the Windows Extended Attributes to the specified path.
// The Windows API requires setting of all the Extended Attributes in one call. // The Windows API requires setting of all the Extended Attributes in one call.
func restoreExtendedAttributes(nodeType, path string, eas []fs.ExtendedAttribute) (err error) { func restoreExtendedAttributes(nodeType, path string, eas []fs.ExtendedAttribute) (err error) {
var fileHandle windows.Handle var fileHandle windows.Handle
fileHandle, err = getFileHandleForEA(nodeType, path) if fileHandle, err = getFileHandleForEA(nodeType, path); fileHandle == 0 {
return nil
}
if err != nil { if err != nil {
return errors.Errorf("set EA failed while opening file handle for path %v, with: %v", path, err) return errors.Errorf("set EA failed while opening file handle for path %v, with: %v", path, err)
} }
defer func() { defer closeFileHandle(fileHandle, path) // Replaced inline defer with named function call
err := windows.CloseHandle(fileHandle)
if err != nil {
debug.Log("Error closing file handle for %s: %v\n", path, err)
}
}()
if err = fs.SetFileEA(fileHandle, eas); err != nil { if err = fs.SetFileEA(fileHandle, eas); err != nil {
return errors.Errorf("set EA failed for path %v, with: %v", path, err) return errors.Errorf("set EA failed for path %v, with: %v", path, err)
} }