Skip to content

Commit

Permalink
tools: close channel if we fail during walking
Browse files Browse the repository at this point in the history
If the user runs git lfs track (or almost any command), we'll try to
clean up any temporary files that may be left around.  When doing so, we
walk the temporary directory, looking for any files.

Normally, this works great, but when the user is in a repository that is
owned by another user, the temporary directory may not have been created
and in such a case, our walk may fail.  If so, that's fine, but when we
return an error, we need to be sure to clean up the WaitGroup and close
the channel.  If we don't, the tools.fastWalkCallback routine will hang
waiting for the channel and we won't make any more progress, so the
program will just hang.  Let's defer the Wait call so we always clean up
on the way out.
  • Loading branch information
bk2204 committed Aug 6, 2020
1 parent c2722a3 commit 28696af
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tools/filetools.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,15 @@ func fastWalkWithExcludeFiles(rootDir string) *fastWalker {
}

go func() {
defer w.Wait()

dirFi, err := os.Stat(w.rootDir)
if err != nil {
w.ch <- fastWalkInfo{Err: err}
return
}

w.Walk(true, "", dirFi, excludePaths)
w.Wait()
}()
return w
}
Expand Down

0 comments on commit 28696af

Please sign in to comment.