diff --git a/changes.go b/changes.go index a8b8962c..e720efa0 100644 --- a/changes.go +++ b/changes.go @@ -146,7 +146,7 @@ func (g *Commands) resolveTrashChangeList(trashed bool, p string, r *File) (cl [ f = g.rem.FindByParentIdTrashed } if r != nil { - if remoteChildren, err = f(r.Id); err != nil { + if remoteChildren, err = f(r.Id, g.opts.Hidden); err != nil { return } } @@ -212,7 +212,8 @@ func (g *Commands) resolveChangeListRecv( var remoteChildren []*File if r != nil { - if remoteChildren, err = g.rem.FindByParentId(r.Id); err != nil { + remoteChildren, err = g.rem.FindByParentId(r.Id, g.opts.Hidden) + if err != nil { return } } diff --git a/cmd/drive/main.go b/cmd/drive/main.go index f8e527fa..7a3f3522 100644 --- a/cmd/drive/main.go +++ b/cmd/drive/main.go @@ -173,11 +173,10 @@ func (cmd *pushCmd) Flags(fs *flag.FlagSet) *flag.FlagSet { func preprocessArgs(args []string) ([]string, *config.Context, string) { var relPaths []string context, path := discoverContext(args) - cwd, _ := os.Getwd() root := context.AbsPathOf("") if len(args) < 1 { - args = []string{cwd} + args = []string{"."} } var err error @@ -189,6 +188,9 @@ func preprocessArgs(args []string) ([]string, *config.Context, string) { } relPath, err := filepath.Rel(root, p) + if relPath == "." { + relPath = "" + } exitWithError(err) @@ -240,6 +242,9 @@ func pushMounted(cmd *pushCmd, args []string) { rest = nonEmptyStrings(rest) context, path := discoverContext(contextArgs) contextAbsPath, err := filepath.Abs(path) + if path == "." { + path = "" + } exitWithError(err) mountPoints, auxSrcs := config.MountPoints(path, contextAbsPath, rest, *cmd.hidden) diff --git a/pull.go b/pull.go index acde5110..ba8882c9 100644 --- a/pull.go +++ b/pull.go @@ -32,11 +32,10 @@ const ( // directory, it recursively pulls from the remote if there are remote changes. // It doesn't check if there are remote changes if isForce is set. func (g *Commands) Pull() (err error) { - root := g.context.AbsPathOf("") var cl []*Change for _, relToRootPath := range g.opts.Sources { fsPath := g.context.AbsPathOf(relToRootPath) - ccl, cErr := lonePull(g, root, relToRootPath, fsPath) + ccl, cErr := g.changeListResolve(relToRootPath, fsPath, false) if cErr == nil && len(ccl) > 0 { cl = append(cl, ccl...) } @@ -50,21 +49,6 @@ func (g *Commands) Pull() (err error) { return } -func lonePull(g *Commands, parent, absPath, path string) (cl []*Change, err error) { - r, err := g.rem.FindByPath(absPath) - if err != nil && err != ErrPathNotExists { - return - } - - var l *File - localinfo, _ := os.Stat(absPath) - if localinfo != nil { - l = NewLocalFile(absPath, localinfo) - } - - return g.resolveChangeListRecv(false, parent, absPath, r, l) -} - func (g *Commands) playPullChangeList(cl []*Change, exports []string) (err error) { var next []*Change g.taskStart(len(cl)) @@ -141,7 +125,6 @@ func (g *Commands) localAdd(wg *sync.WaitGroup, change *Change, exports []string func (g *Commands) localDelete(wg *sync.WaitGroup, change *Change) (err error) { defer g.taskDone() defer wg.Done() - fmt.Println("LD", change.Dest.BlobAt) return os.RemoveAll(change.Dest.BlobAt) } @@ -260,7 +243,6 @@ func (g *Commands) singleDownload(p, id, exportURL string) (err error) { blob, err = g.rem.Download(id, exportURL) if err != nil { - fmt.Println("dl", err) return err } _, err = io.Copy(fo, blob) diff --git a/push.go b/push.go index 1b0a14e5..85cc72f0 100644 --- a/push.go +++ b/push.go @@ -45,7 +45,7 @@ func (g *Commands) Push() (err error) { for _, relToRootPath := range g.opts.Sources { fsPath := g.context.AbsPathOf(relToRootPath) - ccl, cErr := lonePush(g, root, relToRootPath, fsPath) + ccl, cErr := g.changeListResolve(relToRootPath, fsPath, true) if cErr == nil && len(ccl) > 0 { cl = append(cl, ccl...) } diff --git a/remote.go b/remote.go index 1d9ac626..f87d8fa7 100644 --- a/remote.go +++ b/remote.go @@ -154,7 +154,7 @@ func (r *Remote) FindByPathTrashed(p string) (file *File, err error) { return r.findByPathTrashed("root", parts[1:]) } -func (r *Remote) findByParentIdRaw(parentId string, trashed bool) (files []*File, err error) { +func (r *Remote) findByParentIdRaw(parentId string, trashed, hidden bool) (files []*File, err error) { req := r.service.Files.List() // TODO: use field selectors @@ -165,26 +165,41 @@ func (r *Remote) findByParentIdRaw(parentId string, trashed bool) (files []*File expr = fmt.Sprintf("'%s' in parents and trashed=false", parentId) } + pageToken := "" + var results *drive.FileList + // TODO: Support channeling of results as they arrive to avoid long waits for results + req.Q(expr) - results, err := req.Do() - // TODO: handle paging - if err != nil { - return - } - for _, f := range results.Items { - if !strings.HasPrefix(f.Title, ".") { // ignore hidden files + + for { + if pageToken != "" { + req = req.PageToken(pageToken) + } + results, err = req.Do() + if err != nil { + return + } + for _, f := range results.Items { + if !hidden && strings.HasPrefix(f.Title, ".") { // ignore hidden files + continue + } files = append(files, NewRemoteFile(f)) } + + pageToken = results.NextPageToken + if pageToken == "" { + break + } } return } -func (r *Remote) FindByParentId(parentId string) (files []*File, err error) { - return r.findByParentIdRaw(parentId, false) +func (r *Remote) FindByParentId(parentId string, hidden bool) (files []*File, err error) { + return r.findByParentIdRaw(parentId, false, hidden) } -func (r *Remote) FindByParentIdTrashed(parentId string) (files []*File, err error) { - return r.findByParentIdRaw(parentId, true) +func (r *Remote) FindByParentIdTrashed(parentId string, hidden bool) (files []*File, err error) { + return r.findByParentIdRaw(parentId, true, hidden) } func (r *Remote) Trash(id string) error { diff --git a/types.go b/types.go index f7dc15d9..69566aef 100644 --- a/types.go +++ b/types.go @@ -208,20 +208,9 @@ func (c *Change) Op() int { if c.Src.IsDir != c.Dest.IsDir { return OpMod } - if !c.Src.IsDir { - // if it's a regular file, see it it's modified. - // If the first test passes then do an Md5 checksum comparison - if c.Src.Size != c.Dest.Size || !c.Src.ModTime.Equal(c.Dest.ModTime) { - return OpMod - } - - ssum := md5Checksum(c.Src) - dsum := md5Checksum(c.Dest) - - if dsum != ssum { - return OpMod - } + if !c.Src.IsDir && !isSameFile(c.Src, c.Dest) { + return OpMod } return OpNone }