Further repair parallelism

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

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

Loading…
Cancel
Save