From c4c2746ff78de9a6be5e46e6ad3bc23cf8c00b88 Mon Sep 17 00:00:00 2001 From: Reya C Date: Sat, 3 Apr 2021 02:46:18 -0400 Subject: [PATCH] Fix parallelism --- drive-demuxer.go | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/drive-demuxer.go b/drive-demuxer.go index e2dde27..71be2b8 100644 --- a/drive-demuxer.go +++ b/drive-demuxer.go @@ -298,33 +298,33 @@ func (s *Step) Walk() { rightState, err := s.CheckState(rightPath) if err != nil { wg.Add(1) - go func() { + go func(rightPath string) { defer func() { wg.Done() }() log.Printf("Error statting path %s: %s\n", rightPath, err) s.Bar.Increment() - }() + }(rightPath) continue } else if rightState == UNKNOWN { wg.Add(1) - go func() { + go func(rightPath string) { defer func() { wg.Done() }() log.Printf("Unknown stat value for path %s\n", rightPath) s.Bar.Increment() - }() + }(rightPath) continue } else if rightState == MISSING { wg.Add(1) - go func() { + go func(child string) { defer func() { wg.Done() }() s.SeparateLeft(child) s.Bar.Increment() - }() + }(child) continue } @@ -332,40 +332,40 @@ func (s *Step) Walk() { leftState, err := s.CheckState(leftPath) if err != nil { wg.Add(1) - go func() { + go func(leftPath string) { defer func() { wg.Done() }() log.Printf("Error statting path %s: %s\n", leftPath, err) s.Bar.Increment() - }() + }(leftPath) continue } else if leftState == UNKNOWN { wg.Add(1) - go func() { + go func(leftPath string) { defer func() { wg.Done() }() log.Printf("Unknown stat value for path %s\n", leftPath) s.Bar.Increment() - }() + }(leftPath) continue } else if leftState == MISSING { wg.Add(1) - go func() { + go func(child string) { defer func() { wg.Done() }() s.SeparateRight(child) s.Bar.Increment() - }() + }(child) continue } switch rightState { case FILE: wg.Add(1) - go func() { + go func(child string) { defer func() { wg.Done() }() @@ -376,26 +376,32 @@ func (s *Step) Walk() { s.Separate(child) s.Bar.Increment() } - }() + }(child) case DIRECTORY: if leftState == DIRECTORY { - s.MakeCombinedDir(child) substep := Step{ TopLevel: s.TopLevel, Subpath: path.Join(s.Subpath, child), } wg.Add(1) - go func() { + go func(child string, substep *Step) { defer func() { wg.Done() }() + s.MakeCombinedDir(child) substep.Walk() s.RemoveInputDirs(child) s.Bar.Increment() - }() + }(child, &substep) } else { - s.Separate(child) - s.Bar.Increment() + wg.Add(1) + go func(child string) { + defer func() { + wg.Done() + }() + s.Separate(child) + s.Bar.Increment() + }(child) } default: panic("Unexpected state")