Further repair parallelism

main
Mari 4 years ago
parent c4c2746ff7
commit ec47b8d63a
  1. 64
      drive-demuxer.go

@ -19,6 +19,7 @@ type TopLevel struct {
CombinedOutput string CombinedOutput string
RightOutput string RightOutput string
OpenHandles chan int OpenHandles chan int
OpenDirectories chan int
DryRun bool DryRun bool
Bar *pb.ProgressBar Bar *pb.ProgressBar
} }
@ -297,79 +298,44 @@ func (s *Step) Walk() {
rightPath := s.InputPath(child, RIGHT) rightPath := s.InputPath(child, RIGHT)
rightState, err := s.CheckState(rightPath) rightState, err := s.CheckState(rightPath)
if err != nil { if err != nil {
wg.Add(1)
go func(rightPath string) {
defer func() {
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)
go func(rightPath string) {
defer func() {
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)
go func(child string) {
defer func() {
wg.Done()
}()
s.SeparateLeft(child) s.SeparateLeft(child)
s.Bar.Increment() s.Bar.Increment()
}(child)
continue continue
} }
leftPath := s.InputPath(child, LEFT) leftPath := s.InputPath(child, LEFT)
leftState, err := s.CheckState(leftPath) leftState, err := s.CheckState(leftPath)
if err != nil { if err != nil {
wg.Add(1)
go func(leftPath string) {
defer func() {
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)
go func(leftPath string) {
defer func() {
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)
go func(child string) {
defer func() {
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)
if leftState == FILE {
go func(child string) { go func(child string) {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
if leftState == FILE && s.AreFilesIdentical(child) { if s.AreFilesIdentical(child) {
s.Combine(child) s.Combine(child)
s.Bar.Increment() s.Bar.Increment()
} else { } else {
@ -377,31 +343,32 @@ func (s *Step) Walk() {
s.Bar.Increment() s.Bar.Increment()
} }
}(child) }(child)
} else {
s.Separate(child)
s.Bar.Increment()
}
case DIRECTORY: case DIRECTORY:
if leftState == DIRECTORY { if leftState == DIRECTORY {
substep := Step{ s.OpenDirectories <- 1
TopLevel: s.TopLevel,
Subpath: path.Join(s.Subpath, child),
}
wg.Add(1) wg.Add(1)
go func(child string, substep *Step) { go func(child string) {
defer func() { defer func() {
wg.Done() wg.Done()
<-s.OpenDirectories
}() }()
substep := Step{
TopLevel: s.TopLevel,
Subpath: path.Join(s.Subpath, child),
}
s.MakeCombinedDir(child) s.MakeCombinedDir(child)
substep.Walk() substep.Walk()
s.RemoveInputDirs(child) s.RemoveInputDirs(child)
s.Bar.Increment() s.Bar.Increment()
}(child, &substep) }(child)
} else { } else {
wg.Add(1) wg.Add(1)
go func(child string) {
defer func() {
wg.Done()
}()
s.Separate(child) s.Separate(child)
s.Bar.Increment() s.Bar.Increment()
}(child)
} }
default: default:
panic("Unexpected state") panic("Unexpected state")
@ -414,6 +381,7 @@ func (s *Step) Walk() {
func main() { func main() {
settings := TopLevel{ settings := TopLevel{
OpenHandles: make(chan int, 450), OpenHandles: make(chan int, 450),
OpenDirectories: make(chan int, 1000),
Bar: pb.StartNew(1), Bar: pb.StartNew(1),
} }
flag.StringVar(&settings.LeftInput, flag.StringVar(&settings.LeftInput,

Loading…
Cancel
Save