Skip to content

Commit

Permalink
Fix test failure on Windows caused by nil sys in mock FileInfo
Browse files Browse the repository at this point in the history
Fix test failure caused by `panic` when checking if a file is hidden in
Windows. The hidden check uses `FileInfo.Sys()`. In tests the object is
a mock and that call returns `nil`. Regardless of mocking, we should
check for `nil` since according to docs that function can return `nil`.

Run `go mod tidy`.

Relates to:
- ipfs/go-ipfs-files#34


This commit was moved from ipfs/go-ipfs-files@8246860
  • Loading branch information
masih committed Jul 22, 2021
1 parent 1c18dbc commit b973565
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion files/is_hidden_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ func isHidden(fi os.FileInfo) bool {
return true
}

wi, ok := fi.Sys().(*windows.Win32FileAttributeData)
sys := fi.Sys()
if sys == nil {
return false
}
wi, ok := sys.(*windows.Win32FileAttributeData)
if !ok {
return false
}
Expand Down

0 comments on commit b973565

Please sign in to comment.