1
mirror of https://github.com/rclone/rclone synced 2024-11-23 00:06:55 +01:00

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
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 ###
Drive has quite a lot of rate limiting. This causes rclone to be

View File

@ -43,8 +43,9 @@ const (
// Globals
var (
// Flags
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.")
driveFullList = pflag.BoolP("drive-full-list", "", true, "Use a full listing for directory list. More data but usually quicker.")
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.
// 1<<18 is the minimum size supported by the Google uploader, and there is no maximum.
chunkSize = fs.SizeSuffix(256 * 1024)
@ -400,6 +401,16 @@ func (f *Fs) listDirRecursive(dirID string, path string, out fs.ObjectsChan) err
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/"
//
// 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 != "" {
path = directory + "/" + path
}
if *driveAuthOwnerOnly && !isAuthOwned(item) {
return
}
if item.MimeType == driveFolderType {
// Put the directory into the dircache
f.dirCache.Put(path, item.Id)