|
|
|
@ -8,6 +8,8 @@ import ( |
|
|
|
|
"os" |
|
|
|
|
"path" |
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
"github.com/cheggaaa/pb/v3" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type TopLevel struct { |
|
|
|
@ -18,6 +20,7 @@ type TopLevel struct { |
|
|
|
|
RightOutput string |
|
|
|
|
OpenHandles chan int |
|
|
|
|
DryRun bool |
|
|
|
|
Bar *pb.ProgressBar |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Step struct { |
|
|
|
@ -116,10 +119,6 @@ func (s *Step) SeparateRight(child string) { |
|
|
|
|
rightInPath := s.InputPath(child, RIGHT) |
|
|
|
|
rightOutPath := s.OutputPath(child, RIGHT) |
|
|
|
|
|
|
|
|
|
if s.DryRun { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rightBase := path.Dir(rightOutPath) |
|
|
|
|
err := os.MkdirAll(rightBase, 0755) |
|
|
|
|
if err != nil { |
|
|
|
@ -136,10 +135,6 @@ func (s *Step) Combine(child string) { |
|
|
|
|
rightInPath := s.InputPath(child, RIGHT) |
|
|
|
|
combinedOutPath := s.OutputPath(child, COMBINED) |
|
|
|
|
|
|
|
|
|
if s.DryRun { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
combinedBase := path.Dir(combinedOutPath) |
|
|
|
|
err := os.MkdirAll(combinedBase, 0755) |
|
|
|
|
if err != nil { |
|
|
|
@ -279,17 +274,22 @@ func (s *Step) AreFilesIdentical(child string) bool { |
|
|
|
|
func (s *Step) Walk() { |
|
|
|
|
wg := sync.WaitGroup{} |
|
|
|
|
|
|
|
|
|
for _, child := range s.ListChildren() { |
|
|
|
|
children := s.ListChildren() |
|
|
|
|
s.Bar.AddTotal(int64(len(children))) |
|
|
|
|
for _, child := range children { |
|
|
|
|
rightPath := s.InputPath(child, RIGHT) |
|
|
|
|
rightState, err := s.CheckState(rightPath) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("Error statting path %s: %s\n", rightPath, err) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
continue |
|
|
|
|
} else if rightState == UNKNOWN { |
|
|
|
|
log.Printf("Unknown stat value for path %s\n", rightPath) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
continue |
|
|
|
|
} else if rightState == MISSING { |
|
|
|
|
s.SeparateLeft(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -297,12 +297,15 @@ func (s *Step) Walk() { |
|
|
|
|
leftState, err := s.CheckState(leftPath) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("Error statting path %s: %s\n", leftPath, err) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
continue |
|
|
|
|
} else if leftState == UNKNOWN { |
|
|
|
|
log.Printf("Unknown stat value for path %s\n", leftPath) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
continue |
|
|
|
|
} else if leftState == MISSING { |
|
|
|
|
s.SeparateRight(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -310,8 +313,10 @@ func (s *Step) Walk() { |
|
|
|
|
case FILE: |
|
|
|
|
if leftState == FILE && s.AreFilesIdentical(child) { |
|
|
|
|
s.Combine(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
} else { |
|
|
|
|
s.Separate(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
} |
|
|
|
|
case DIRECTORY: |
|
|
|
|
if leftState == DIRECTORY { |
|
|
|
@ -329,9 +334,11 @@ func (s *Step) Walk() { |
|
|
|
|
s.OpenHandles <- 1 |
|
|
|
|
substep.Walk() |
|
|
|
|
s.RemoveInputDirs(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
}() |
|
|
|
|
} else { |
|
|
|
|
s.Separate(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
} |
|
|
|
|
default: |
|
|
|
|
panic("Unexpected state") |
|
|
|
@ -343,7 +350,8 @@ func (s *Step) Walk() { |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
settings := TopLevel{ |
|
|
|
|
OpenHandles: make(chan int, 300), |
|
|
|
|
OpenHandles: make(chan int, 450), |
|
|
|
|
Bar: pb.StartNew(1), |
|
|
|
|
} |
|
|
|
|
flag.StringVar(&settings.LeftInput, |
|
|
|
|
"left-input", "./input/left", "The name of the left side of the input.") |
|
|
|
@ -362,4 +370,5 @@ func main() { |
|
|
|
|
TopLevel: &settings, |
|
|
|
|
Subpath: "", |
|
|
|
|
}).Walk() |
|
|
|
|
settings.Bar.Increment() |
|
|
|
|
} |
|
|
|
|