Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added starred files only support for Google Drive backend #3936

Open
wants to merge 5 commits into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -282,6 +282,11 @@ commands (copy, sync, etc), and with all other commands too.`,
Default: false,
Help: "Only show files that are in the trash.\nThis will show trashed files in their original directory structure.",
Advanced: true,
}, {

This comment has been minimized.

Copy link
@golangcibot

golangcibot Feb 5, 2020

File is not goimports-ed (from goimports)

Name: "starred_only",
Default: false,
Help: "Only show files that are starred.",
Advanced: true,
}, {
Name: "formats",
Default: "",
@@ -504,6 +509,7 @@ type Options struct {
SkipChecksumGphotos bool `config:"skip_checksum_gphotos"`
SharedWithMe bool `config:"shared_with_me"`
TrashedOnly bool `config:"trashed_only"`
StarredOnly bool `config:"starred_only"`
Extensions string `config:"formats"`
ExportExtensions string `config:"export_formats"`
ImportExtensions string `config:"import_formats"`
@@ -673,6 +679,7 @@ func (f *Fs) list(ctx context.Context, dirIDs []string, title string, directorie
}
query = append(query, q)
}

// Search with sharedWithMe will always return things listed in "Shared With Me" (without any parents)
// We must not filter with parent when we try list "ROOT" with drive-shared-with-me
// If we need to list file inside those shared folders, we must search it without sharedWithMe
@@ -684,8 +691,16 @@ func (f *Fs) list(ctx context.Context, dirIDs []string, title string, directorie
if parentsQuery.Len() > 1 {
_, _ = parentsQuery.WriteString(" or ")
}
if f.opt.SharedWithMe && dirID == f.rootFolderID {
_, _ = parentsQuery.WriteString("sharedWithMe=true")
if (f.opt.SharedWithMe || f.opt.StarredOnly) && dirID == f.rootFolderID {
if f.opt.SharedWithMe {
_, _ = parentsQuery.WriteString("sharedWithMe=true")
}
if f.opt.StarredOnly {
if f.opt.SharedWithMe {
_, _ = parentsQuery.WriteString(" and ")

This comment has been minimized.

Copy link
@ncw

ncw Feb 6, 2020

Member

I'm not sure this and is correct without brackets - what do you think?

This comment has been minimized.

Copy link
@jmacul2

jmacul2 Feb 6, 2020

Author

It seems to work for me as is....but I'll defer to whatever seems best.

My bigger annoyance is that "starred" and "sharedwithme" seem not to play very well together. "sharedwithme" seems to retain parent/child folder structures, but starred does not. I guess it is more of how I wanted to use it. For example, I had hoped that by "staring" a specific file, it would retain its parent/child folder relationships. But I admit that would not follow how Google has it setup through its UI whereby when you star an item it only shows that item instead of its full file path.

This comment has been minimized.

Copy link
@ncw

ncw Feb 7, 2020

Member

If you want to show the starred files in their correct place then you want something like this

		if f.opt.SharedWithMe && dirID == f.rootFolderID {
			_, _ = parentsQuery.WriteString("sharedWithMe=true")
		} else {
			_, _ = fmt.Fprintf(parentsQuery, "'%s' in parents", dirID)
		}
		if f.opt.StarredOnly {
			if parentsQuery.Len() > 1 {
				_, _ = parentsQuery.WriteString(" and ")
			}
			_, _ = parentsQuery.WriteString("(mimeType='" + driveFolderType + "' or starred=true)")
		}

That will make --shared-with-me incompatible with --starred-only though as it searches in given directories only.

If you wanted starred to work with sharedwith me then you'd want something like (untested)

		if f.opt.SharedWithMe && dirID == f.rootFolderID {
			_, _ = parentsQuery.WriteString("sharedWithMe=true")
			if f.opt.StarredOnly {
				if parentsQuery.Len() > 1 {
					_, _ = parentsQuery.WriteString(" and ")
				}
				_, _ = parentsQuery.WriteString("starred=true")
			}
		} else {
			_, _ = fmt.Fprintf(parentsQuery, "'%s' in parents", dirID)
			if f.opt.StarredOnly {
				if parentsQuery.Len() > 1 {
					_, _ = parentsQuery.WriteString(" and ")
				}
				_, _ = parentsQuery.WriteString("(mimeType='" + driveFolderType + "' or starred=true)")
			}
		}
}
_, _ = parentsQuery.WriteString("starred=true")
}
} else {
_, _ = fmt.Fprintf(parentsQuery, "'%s' in parents", dirID)
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.