From 2e1e8f764e160246d0b5d41e705cdceeeba69284 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sun, 22 Mar 2015 14:06:29 +0000 Subject: [PATCH] Fix crash on walker error (fixes #1507) --- internal/scanner/walk.go | 3 ++- internal/scanner/walk_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/scanner/walk.go b/internal/scanner/walk.go index 522b24d06..5ea670757 100644 --- a/internal/scanner/walk.go +++ b/internal/scanner/walk.go @@ -111,7 +111,8 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun // Return value used when we are returning early and don't want to // process the item. For directories, this means do-not-descend. var skip error // nil - if info.IsDir() { + // info nil when error is not nil + if info != nil && info.IsDir() { skip = filepath.SkipDir } diff --git a/internal/scanner/walk_test.go b/internal/scanner/walk_test.go index e6fe1cae7..36370d945 100644 --- a/internal/scanner/walk_test.go +++ b/internal/scanner/walk_test.go @@ -259,6 +259,14 @@ func TestNormalization(t *testing.T) { } } +func TestIssue1507(t *testing.T) { + w := Walker{} + c := make(chan protocol.FileInfo, 100) + fn := w.walkAndHashFiles(c) + + fn("", nil, protocol.ErrClosed) +} + func walkDir(dir string) ([]protocol.FileInfo, error) { w := Walker{ Dir: dir,