|
|
|
@ -3,13 +3,11 @@ package main |
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"flag" |
|
|
|
|
"github.com/cheggaaa/pb/v3" |
|
|
|
|
"io" |
|
|
|
|
"log" |
|
|
|
|
"os" |
|
|
|
|
"path" |
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
"github.com/cheggaaa/pb/v3" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type TopLevel struct { |
|
|
|
@ -18,8 +16,6 @@ type TopLevel struct { |
|
|
|
|
LeftOutput string |
|
|
|
|
CombinedOutput string |
|
|
|
|
RightOutput string |
|
|
|
|
OpenHandles chan int |
|
|
|
|
OpenDirectories chan int |
|
|
|
|
DryRun bool |
|
|
|
|
Bar *pb.ProgressBar |
|
|
|
|
} |
|
|
|
@ -191,10 +187,6 @@ func (s *Step) RemoveInputDirs(child string) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Step) ListChildren() []string { |
|
|
|
|
s.OpenHandles <- 1 |
|
|
|
|
defer func() { |
|
|
|
|
<-s.OpenHandles |
|
|
|
|
}() |
|
|
|
|
leftInPath := s.InputPath("", LEFT) |
|
|
|
|
rightInPath := s.InputPath("", RIGHT) |
|
|
|
|
results := make(map[string]bool) |
|
|
|
@ -220,10 +212,6 @@ func (s *Step) ListChildren() []string { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Step) AreFilesIdentical(child string) bool { |
|
|
|
|
s.OpenHandles <- 1 |
|
|
|
|
defer func() { |
|
|
|
|
<-s.OpenHandles |
|
|
|
|
}() |
|
|
|
|
leftInPath := s.InputPath(child, LEFT) |
|
|
|
|
rightInPath := s.InputPath(child, RIGHT) |
|
|
|
|
leftInfo, err := os.Stat(leftInPath) |
|
|
|
@ -290,8 +278,6 @@ func (s *Step) AreFilesIdentical(child string) bool { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Step) Walk() { |
|
|
|
|
wg := sync.WaitGroup{} |
|
|
|
|
|
|
|
|
|
children := s.ListChildren() |
|
|
|
|
s.Bar.AddTotal(int64(len(children))) |
|
|
|
|
for _, child := range children { |
|
|
|
@ -330,11 +316,6 @@ func (s *Step) Walk() { |
|
|
|
|
switch rightState { |
|
|
|
|
case FILE: |
|
|
|
|
if leftState == FILE { |
|
|
|
|
wg.Add(1) |
|
|
|
|
go func(child string) { |
|
|
|
|
defer func() { |
|
|
|
|
wg.Done() |
|
|
|
|
}() |
|
|
|
|
if s.AreFilesIdentical(child) { |
|
|
|
|
s.Combine(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
@ -342,20 +323,12 @@ func (s *Step) Walk() { |
|
|
|
|
s.Separate(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
} |
|
|
|
|
}(child) |
|
|
|
|
} else { |
|
|
|
|
s.Separate(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
} |
|
|
|
|
case DIRECTORY: |
|
|
|
|
if leftState == DIRECTORY { |
|
|
|
|
s.OpenDirectories <- 1 |
|
|
|
|
wg.Add(1) |
|
|
|
|
go func(child string) { |
|
|
|
|
defer func() { |
|
|
|
|
wg.Done() |
|
|
|
|
<-s.OpenDirectories |
|
|
|
|
}() |
|
|
|
|
substep := Step{ |
|
|
|
|
TopLevel: s.TopLevel, |
|
|
|
|
Subpath: path.Join(s.Subpath, child), |
|
|
|
@ -364,9 +337,7 @@ func (s *Step) Walk() { |
|
|
|
|
substep.Walk() |
|
|
|
|
s.RemoveInputDirs(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
}(child) |
|
|
|
|
} else { |
|
|
|
|
wg.Add(1) |
|
|
|
|
s.Separate(child) |
|
|
|
|
s.Bar.Increment() |
|
|
|
|
} |
|
|
|
@ -374,14 +345,10 @@ func (s *Step) Walk() { |
|
|
|
|
panic("Unexpected state") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wg.Wait() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
settings := TopLevel{ |
|
|
|
|
OpenHandles: make(chan int, 450), |
|
|
|
|
OpenDirectories: make(chan int, 1000), |
|
|
|
|
Bar: pb.StartNew(1), |
|
|
|
|
} |
|
|
|
|
flag.StringVar(&settings.LeftInput, |
|
|
|
|