drive: add --drive-auth-owner-only to only consider files owned by the user.

This commit is contained in:
Björn Harrtell 2016-01-02 19:47:05 +01:00 committed by Nick Craig-Wood
parent 1ce3673006
commit 78edafcaac
2 changed files with 21 additions and 2 deletions

View file

@ -127,6 +127,11 @@ File size cutoff for switching to chunked upload. Default is 256kB.
Send files to the trash instead of deleting permanently. Defaults to Send files to the trash instead of deleting permanently. Defaults to
off, namely deleting files permanently. off, namely deleting files permanently.
#### --drive-auth-owner-only ####
Only consider files owned by the authenticated user. Requires
that --drive-full-list=true (default).
### Limitations ### ### Limitations ###
Drive has quite a lot of rate limiting. This causes rclone to be Drive has quite a lot of rate limiting. This causes rclone to be

View file

@ -43,8 +43,9 @@ const (
// Globals // Globals
var ( var (
// Flags // Flags
driveFullList = pflag.BoolP("drive-full-list", "", true, "Use a full listing for directory list. More data but usually quicker.") driveFullList = pflag.BoolP("drive-full-list", "", true, "Use a full listing for directory list. More data but usually quicker.")
driveUseTrash = pflag.BoolP("drive-use-trash", "", false, "Send files to the trash instead of deleting permanently.") driveAuthOwnerOnly = pflag.BoolP("drive-auth-owner-only", "", false, "Only consider files owned by the authenticated user. Requires drive-full-list.")
driveUseTrash = pflag.BoolP("drive-use-trash", "", false, "Send files to the trash instead of deleting permanently.")
// chunkSize is the size of the chunks created during a resumable upload and should be a power of two. // chunkSize is the size of the chunks created during a resumable upload and should be a power of two.
// 1<<18 is the minimum size supported by the Google uploader, and there is no maximum. // 1<<18 is the minimum size supported by the Google uploader, and there is no maximum.
chunkSize = fs.SizeSuffix(256 * 1024) chunkSize = fs.SizeSuffix(256 * 1024)
@ -400,6 +401,16 @@ func (f *Fs) listDirRecursive(dirID string, path string, out fs.ObjectsChan) err
return nil return nil
} }
// isAuthOwned checks if any of the item owners is the authenticated owner
func isAuthOwned(item *drive.File) bool {
for _, owner := range item.Owners {
if owner.IsAuthenticatedUser {
return true
}
}
return false
}
// Path should be directory path either "" or "path/" // Path should be directory path either "" or "path/"
// //
// List the directory using a full listing and filtering out unwanted // List the directory using a full listing and filtering out unwanted
@ -420,6 +431,9 @@ func (f *Fs) listDirFull(dirID string, path string, out fs.ObjectsChan) error {
if directory != "" { if directory != "" {
path = directory + "/" + path path = directory + "/" + path
} }
if *driveAuthOwnerOnly && !isAuthOwned(item) {
return
}
if item.MimeType == driveFolderType { if item.MimeType == driveFolderType {
// Put the directory into the dircache // Put the directory into the dircache
f.dirCache.Put(path, item.Id) f.dirCache.Put(path, item.Id)