Skip to content

Commit

Permalink
Max traversal supported for results + Bug fixes
Browse files Browse the repository at this point in the history
+ Ensuring full relative path resolution.
+ Fixes rakyll#19 for traversal of dirs with more than 100 items
+ Proper comparison for file changes.
  • Loading branch information
Emmanuel Odeke committed Jan 4, 2015
1 parent 0824046 commit d53e003
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 49 deletions.
5 changes: 3 additions & 2 deletions changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/drive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -189,6 +188,9 @@ func preprocessArgs(args []string) ([]string, *config.Context, string) {
}

relPath, err := filepath.Rel(root, p)
if relPath == "." {
relPath = ""
}

exitWithError(err)

Expand Down Expand Up @@ -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)
Expand Down
20 changes: 1 addition & 19 deletions pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand All @@ -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))
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand Down
39 changes: 27 additions & 12 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
15 changes: 2 additions & 13 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d53e003

Please sign in to comment.