Ensure dir before files ordering when scanning

This commit is contained in:
Jakob Borg 2015-08-13 13:01:50 +02:00
parent 681306b7a1
commit 99736e5066
2 changed files with 4 additions and 4 deletions

View File

@ -97,7 +97,7 @@ func (w *Walker) Walk() (chan protocol.FileInfo, error) {
newParallelHasher(w.Dir, w.BlockSize, w.Hashers, hashedFiles, files) newParallelHasher(w.Dir, w.BlockSize, w.Hashers, hashedFiles, files)
go func() { go func() {
hashFiles := w.walkAndHashFiles(files) hashFiles := w.walkAndHashFiles(files, hashedFiles)
if len(w.Subs) == 0 { if len(w.Subs) == 0 {
filepath.Walk(w.Dir, hashFiles) filepath.Walk(w.Dir, hashFiles)
} else { } else {
@ -111,7 +111,7 @@ func (w *Walker) Walk() (chan protocol.FileInfo, error) {
return hashedFiles, nil return hashedFiles, nil
} }
func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFunc { func (w *Walker) walkAndHashFiles(fchan, dchan chan protocol.FileInfo) filepath.WalkFunc {
now := time.Now() now := time.Now()
return func(p string, info os.FileInfo, err error) error { return func(p string, info os.FileInfo, err error) error {
// Return value used when we are returning early and don't want to // Return value used when we are returning early and don't want to
@ -311,7 +311,7 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun
if debug { if debug {
l.Debugln("dir:", p, f) l.Debugln("dir:", p, f)
} }
fchan <- f dchan <- f
return nil return nil
} }

View File

@ -274,7 +274,7 @@ func TestNormalization(t *testing.T) {
func TestIssue1507(t *testing.T) { func TestIssue1507(t *testing.T) {
w := Walker{} w := Walker{}
c := make(chan protocol.FileInfo, 100) c := make(chan protocol.FileInfo, 100)
fn := w.walkAndHashFiles(c) fn := w.walkAndHashFiles(c, c)
fn("", nil, protocol.ErrClosed) fn("", nil, protocol.ErrClosed)
} }