aboutsummaryrefslogtreecommitdiffstats
path: root/drive/sync.go
diff options
context:
space:
mode:
authorPetter Rasmussen2016-02-07 14:34:48 +0100
committerPetter Rasmussen2016-02-07 14:35:00 +0100
commitc45e61e6406c188bcad432233a6eb25b4307a536 (patch)
tree69ec8eff240681b62cdff99e3ed063e27b3e044e /drive/sync.go
parent68dccc08494aff71945735c8cf4e4158fc939254 (diff)
downloadgdrive-c45e61e6406c188bcad432233a6eb25b4307a536.tar.bz2
Add sync list recursive command
Diffstat (limited to 'drive/sync.go')
-rw-r--r--drive/sync.go38
1 files changed, 31 insertions, 7 deletions
diff --git a/drive/sync.go b/drive/sync.go
index 3117e84..c0d5add 100644
--- a/drive/sync.go
+++ b/drive/sync.go
@@ -4,6 +4,7 @@ import (
"time"
"fmt"
"os"
+ "strings"
"path/filepath"
"github.com/soniakeys/graph"
"github.com/sabhiram/go-git-ignore"
@@ -24,7 +25,7 @@ func (self *Drive) prepareSyncFiles(localPath string, root *drive.File, cmp File
}()
go func() {
- files, err := self.prepareRemoteFiles(root)
+ files, err := self.prepareRemoteFiles(root, "")
remoteCh <- struct{files []*RemoteFile; err error}{files, err}
}()
@@ -103,10 +104,16 @@ func prepareLocalFiles(root string) ([]*LocalFile, error) {
return files, err
}
-func (self *Drive) listAllFiles(q string, fields []googleapi.Field) ([]*drive.File, error) {
+type listAllFilesArgs struct {
+ query string
+ fields []googleapi.Field
+ sortOrder string
+}
+
+func (self *Drive) listAllFiles(args listAllFilesArgs) ([]*drive.File, error) {
var files []*drive.File
- err := self.service.Files.List().Q(q).Fields(fields...).PageSize(1000).Pages(context.TODO(), func(fl *drive.FileList) error {
+ err := self.service.Files.List().Q(args.query).Fields(args.fields...).OrderBy(args.sortOrder).PageSize(1000).Pages(context.TODO(), func(fl *drive.FileList) error {
files = append(files, fl.Files...)
return nil
})
@@ -114,11 +121,14 @@ func (self *Drive) listAllFiles(q string, fields []googleapi.Field) ([]*drive.Fi
return files, err
}
-func (self *Drive) prepareRemoteFiles(rootDir *drive.File) ([]*RemoteFile, error) {
+func (self *Drive) prepareRemoteFiles(rootDir *drive.File, sortOrder string) ([]*RemoteFile, error) {
// Find all files which has rootDir as root
- query := fmt.Sprintf("appProperties has {key='syncRootId' and value='%s'}", rootDir.Id)
- fields := []googleapi.Field{"nextPageToken", "files(id,name,parents,md5Checksum,mimeType)"}
- files, err := self.listAllFiles(query, fields)
+ listArgs := listAllFilesArgs{
+ query: fmt.Sprintf("appProperties has {key='syncRootId' and value='%s'}", rootDir.Id),
+ fields: []googleapi.Field{"nextPageToken", "files(id,name,parents,md5Checksum,mimeType,size,modifiedTime)"},
+ sortOrder: sortOrder,
+ }
+ files, err := self.listAllFiles(listArgs)
if err != nil {
return nil, fmt.Errorf("Failed listing files: %s", err)
}
@@ -477,6 +487,20 @@ func (self byRemotePathLength) Less(i, j int) bool {
return pathLength(self[i].relPath) < pathLength(self[j].relPath)
}
+type byRemotePath []*RemoteFile
+
+func (self byRemotePath) Len() int {
+ return len(self)
+}
+
+func (self byRemotePath) Swap(i, j int) {
+ self[i], self[j] = self[j], self[i]
+}
+
+func (self byRemotePath) Less(i, j int) bool {
+ return strings.ToLower(self[i].relPath) < strings.ToLower(self[j].relPath)
+}
+
type ignoreFunc func(string) bool
func prepareIgnorer(path string) (ignoreFunc, error) {