mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
process directories in parallel in ChangesDirs
This commit lowers the total time spent in ChangesDirs to half during a commit. Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
parent
1d4caadfe2
commit
359f8aca29
1 changed files with 21 additions and 10 deletions
|
@ -3,15 +3,16 @@ package archive
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/pkg/system"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
|
||||||
"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/dotcloud/docker/pkg/system"
|
||||||
|
"github.com/dotcloud/docker/utils"
|
||||||
|
"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ChangeType int
|
type ChangeType int
|
||||||
|
@ -293,13 +294,23 @@ func collectFileInfo(sourceDir string) (*FileInfo, error) {
|
||||||
|
|
||||||
// Compare two directories and generate an array of Change objects describing the changes
|
// Compare two directories and generate an array of Change objects describing the changes
|
||||||
func ChangesDirs(newDir, oldDir string) ([]Change, error) {
|
func ChangesDirs(newDir, oldDir string) ([]Change, error) {
|
||||||
oldRoot, err := collectFileInfo(oldDir)
|
var (
|
||||||
if err != nil {
|
oldRoot, newRoot *FileInfo
|
||||||
return nil, err
|
err1, err2 error
|
||||||
}
|
errs = make(chan error, 2)
|
||||||
newRoot, err := collectFileInfo(newDir)
|
)
|
||||||
if err != nil {
|
go func() {
|
||||||
return nil, err
|
oldRoot, err1 = collectFileInfo(oldDir)
|
||||||
|
errs <- err1
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
|
newRoot, err2 = collectFileInfo(newDir)
|
||||||
|
errs <- err2
|
||||||
|
}()
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
if err := <-errs; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newRoot.Changes(oldRoot), nil
|
return newRoot.Changes(oldRoot), nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue