Fix parallelism

main
Mari 3 years ago
parent be0b9b076c
commit c4c2746ff7
  1. 44
      drive-demuxer.go

@ -298,33 +298,33 @@ func (s *Step) Walk() {
rightState, err := s.CheckState(rightPath) rightState, err := s.CheckState(rightPath)
if err != nil { if err != nil {
wg.Add(1) wg.Add(1)
go func() { go func(rightPath string) {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
log.Printf("Error statting path %s: %s\n", rightPath, err) log.Printf("Error statting path %s: %s\n", rightPath, err)
s.Bar.Increment() s.Bar.Increment()
}() }(rightPath)
continue continue
} else if rightState == UNKNOWN { } else if rightState == UNKNOWN {
wg.Add(1) wg.Add(1)
go func() { go func(rightPath string) {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
log.Printf("Unknown stat value for path %s\n", rightPath) log.Printf("Unknown stat value for path %s\n", rightPath)
s.Bar.Increment() s.Bar.Increment()
}() }(rightPath)
continue continue
} else if rightState == MISSING { } else if rightState == MISSING {
wg.Add(1) wg.Add(1)
go func() { go func(child string) {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
s.SeparateLeft(child) s.SeparateLeft(child)
s.Bar.Increment() s.Bar.Increment()
}() }(child)
continue continue
} }
@ -332,40 +332,40 @@ func (s *Step) Walk() {
leftState, err := s.CheckState(leftPath) leftState, err := s.CheckState(leftPath)
if err != nil { if err != nil {
wg.Add(1) wg.Add(1)
go func() { go func(leftPath string) {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
log.Printf("Error statting path %s: %s\n", leftPath, err) log.Printf("Error statting path %s: %s\n", leftPath, err)
s.Bar.Increment() s.Bar.Increment()
}() }(leftPath)
continue continue
} else if leftState == UNKNOWN { } else if leftState == UNKNOWN {
wg.Add(1) wg.Add(1)
go func() { go func(leftPath string) {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
log.Printf("Unknown stat value for path %s\n", leftPath) log.Printf("Unknown stat value for path %s\n", leftPath)
s.Bar.Increment() s.Bar.Increment()
}() }(leftPath)
continue continue
} else if leftState == MISSING { } else if leftState == MISSING {
wg.Add(1) wg.Add(1)
go func() { go func(child string) {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
s.SeparateRight(child) s.SeparateRight(child)
s.Bar.Increment() s.Bar.Increment()
}() }(child)
continue continue
} }
switch rightState { switch rightState {
case FILE: case FILE:
wg.Add(1) wg.Add(1)
go func() { go func(child string) {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
@ -376,26 +376,32 @@ func (s *Step) Walk() {
s.Separate(child) s.Separate(child)
s.Bar.Increment() s.Bar.Increment()
} }
}() }(child)
case DIRECTORY: case DIRECTORY:
if leftState == DIRECTORY { if leftState == DIRECTORY {
s.MakeCombinedDir(child)
substep := Step{ substep := Step{
TopLevel: s.TopLevel, TopLevel: s.TopLevel,
Subpath: path.Join(s.Subpath, child), Subpath: path.Join(s.Subpath, child),
} }
wg.Add(1) wg.Add(1)
go func() { go func(child string, substep *Step) {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
s.MakeCombinedDir(child)
substep.Walk() substep.Walk()
s.RemoveInputDirs(child) s.RemoveInputDirs(child)
s.Bar.Increment() s.Bar.Increment()
}() }(child, &substep)
} else { } else {
s.Separate(child) wg.Add(1)
s.Bar.Increment() go func(child string) {
defer func() {
wg.Done()
}()
s.Separate(child)
s.Bar.Increment()
}(child)
} }
default: default:
panic("Unexpected state") panic("Unexpected state")

Loading…
Cancel
Save