From b9735651c8b38e951ed45b9bad42428598319a69 Mon Sep 17 00:00:00 2001 From: "Masih H. Derkani" Date: Thu, 22 Jul 2021 10:02:07 +0100 Subject: [PATCH] Fix test failure on Windows caused by nil `sys` in mock `FileInfo` 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: - https://github.com/ipfs/go-ipfs-files/pull/34 This commit was moved from ipfs/go-ipfs-files@824686023dce36e338919a121b78b4695ab53684 --- files/is_hidden_windows.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/files/is_hidden_windows.go b/files/is_hidden_windows.go index 6f8bd7870..77ea34a70 100644 --- a/files/is_hidden_windows.go +++ b/files/is_hidden_windows.go @@ -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 }