From a4c784b3b7feaa2a00b8d70246c485355483cdb5 Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Sun, 27 Dec 2015 21:23:21 -0700 Subject: [PATCH] propate no-match found `nil` file after find* channel based queries Fixes #536. Updates #528. --- src/changes.go | 11 ++++++----- src/clashes.go | 11 +++++++++-- src/id.go | 1 + src/pull.go | 10 ++++++---- src/push.go | 11 +++++------ src/remote.go | 6 +++++- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/changes.go b/src/changes.go index c8fc87d5..b8a4f99b 100644 --- a/src/changes.go +++ b/src/changes.go @@ -146,17 +146,18 @@ func (g *Commands) changeListResolve(relToRoot, fsPath string, push bool) (cl, c noClashThreshold := uint64(1) for rem := range remotesChan { - if rem != nil && anyMatch(g.opts.IgnoreRegexp, rem.Name) { - return + if rem != nil { + if anyMatch(g.opts.IgnoreRegexp, rem.Name) { + return + } + iterCount++ } - iterCount++ - ccl, cclashes, cErr := g.byRemoteResolve(relToRoot, fsPath, rem, push) cl = append(cl, ccl...) clashes = append(clashes, cclashes...) - if false && cErr != nil { + if cErr != nil { err = reComposeError(err, cErr.Error()) } } diff --git a/src/clashes.go b/src/clashes.go index eda4a92a..545841fb 100644 --- a/src/clashes.go +++ b/src/clashes.go @@ -82,10 +82,16 @@ func findClashesForChildren(g *Commands, parentId, relToRootPath string, depth i memoized[child.Name] = cluster } + separatorPrefix := relToRootPath + if rootLike(separatorPrefix) { + // Avoid a situation where you have Join("/", "/", "a") -> "//a" + separatorPrefix = "" + } + // To preserve the discovery order for _, commonKey := range discoveryOrder { cluster, _ := memoized[commonKey] - fullRelToRootPath := sepJoin(RemoteSeparator, relToRootPath, commonKey) + fullRelToRootPath := sepJoin(RemoteSeparator, separatorPrefix, commonKey) nameClashesPresent := len(cluster) > 1 for _, rem := range cluster { @@ -226,8 +232,9 @@ func autoRenameClashes(g *Commands, clashes []*Change) error { var composedError error + quot := customQuote for _, r := range renames { - message := fmt.Sprintf("Renaming %s %v -> %s\n", r.originalPath, r.change.Src.Id, r.newName) + message := fmt.Sprintf("Renaming %s %s -> %s\n", quot(r.originalPath), quot(r.change.Src.Id), quot(r.newName)) _, err := g.rem.rename(r.change.Src.Id, r.newName) if err == nil { g.log.Log(message) diff --git a/src/id.go b/src/id.go index c5f8b36d..3efcc116 100644 --- a/src/id.go +++ b/src/id.go @@ -66,6 +66,7 @@ func (g *Commands) Id() (err error) { iterCount := uint64(0) for rem := range remotes { if rem == nil { + err = reComposeError(err, fmt.Sprintf("%s does not exist remotely", customQuote(relToRootPath))) continue } diff --git a/src/pull.go b/src/pull.go index b65f2694..a040db73 100644 --- a/src/pull.go +++ b/src/pull.go @@ -284,6 +284,7 @@ func (g *Commands) PullPiped(byId bool) (err error) { matches := resolver(relToRootPath) for rem := range matches { if rem == nil { + err = reComposeError(err, fmt.Sprintf("%s doesnot exist", customQuote(relToRootPath))) continue } @@ -334,17 +335,18 @@ func (g *Commands) pullById() (cl, clashes []*Change, err error) { } func (g *Commands) pullByPath() (cl, clashes []*Change, err error) { - fmt.Println("pullByPath") for _, relToRootPath := range g.opts.Sources { fsPath := g.context.AbsPathOf(relToRootPath) ccl, cclashes, cErr := g.changeListResolve(relToRootPath, fsPath, false) - clashes = append(clashes, cclashes...) - if cErr != nil && cErr != ErrClashesDetected { - return cl, clashes, cErr + if len(cclashes) > 0 { + clashes = append(clashes, cclashes...) } if len(ccl) > 0 { cl = append(cl, ccl...) } + if cErr != nil && cErr != ErrClashesDetected { + err = reComposeError(err, cErr.Error()) + } } if len(clashes) >= 1 { diff --git a/src/push.go b/src/push.go index b5c7b152..d12148e2 100644 --- a/src/push.go +++ b/src/push.go @@ -328,21 +328,20 @@ func (g *Commands) playPushChanges(cl []*Change, opMap *map[Operation]sizeCounte func lonePush(g *Commands, parent, absPath, path string) (cl, clashes []*Change, err error) { remotesChan := g.rem.FindByPathM(absPath) - iterCount := uint64(0) - noClashThreshold := uint64(1) var l *File localinfo, _ := os.Stat(path) if localinfo != nil { l = NewLocalFile(path, localinfo) } + iterCount := uint64(0) + noClashThreshold := uint64(1) + for r := range remotesChan { - if r == nil { - continue + if r != nil { + iterCount++ } - iterCount++ - clr := &changeListResolve{ push: true, dir: parent, diff --git a/src/remote.go b/src/remote.go index 6743828d..7a6cffcc 100644 --- a/src/remote.go +++ b/src/remote.go @@ -299,7 +299,7 @@ func reqDoPage(req *drive.FilesListCall, hidden bool, promptOnPagination bool) c defer close(fileChan) pageToken := "" - for { + for pageIterCount := uint64(0); ; pageIterCount++ { if pageToken != "" { req = req.PageToken(pageToken) } @@ -319,6 +319,10 @@ func reqDoPage(req *drive.FilesListCall, hidden bool, promptOnPagination bool) c } pageToken = results.NextPageToken if pageToken == "" { + if len(results.Items) < 1 && pageIterCount < 1 { + // Item absolutely doesn't exist + fileChan <- nil + } break }