drive: add support for multipart document extensions

This commit is contained in:
Fabian Möller 2018-08-21 12:54:12 +02:00 committed by Nick Craig-Wood
parent 70b30d5ca4
commit 80b25daac7

View File

@ -477,7 +477,7 @@ func (f *Fs) list(dirIDs []string, title string, directoriesOnly bool, filesOnly
_ = parentsQuery.WriteByte(')') _ = parentsQuery.WriteByte(')')
query = append(query, parentsQuery.String()) query = append(query, parentsQuery.String())
} }
stem := "" var stems []string
if title != "" { if title != "" {
// Escaping the backslash isn't documented but seems to work // Escaping the backslash isn't documented but seems to work
searchTitle := strings.Replace(title, `\`, `\\`, -1) searchTitle := strings.Replace(title, `\`, `\\`, -1)
@ -485,16 +485,21 @@ func (f *Fs) list(dirIDs []string, title string, directoriesOnly bool, filesOnly
// Convert to / for search // Convert to / for search
searchTitle = strings.Replace(searchTitle, "", "/", -1) searchTitle = strings.Replace(searchTitle, "", "/", -1)
handleGdocs := !directoriesOnly && !f.opt.SkipGdocs var titleQuery bytes.Buffer
// if the search title contains an extension and the extension is in the export extensions add a search _, _ = fmt.Fprintf(&titleQuery, "(name='%s'", searchTitle)
// for the filename without the extension. if !directoriesOnly && !f.opt.SkipGdocs {
// assume that export extensions don't contain escape sequences and only have one part (not .tar.gz) // If the search title has an extension that is in the export extensions add a search
if ext := path.Ext(searchTitle); handleGdocs && len(ext) > 0 && containsString(f.exportExtensions, ext) { // for the filename without the extension.
stem = title[:len(title)-len(ext)] // Assume that export extensions don't contain escape sequences.
query = append(query, fmt.Sprintf("(name='%s' or name='%s')", searchTitle, searchTitle[:len(searchTitle)-len(ext)])) for _, ext := range f.exportExtensions {
} else { if strings.HasSuffix(searchTitle, ext) {
query = append(query, fmt.Sprintf("name='%s'", searchTitle)) stems = append(stems, title[:len(title)-len(ext)])
_, _ = fmt.Fprintf(&titleQuery, " or name='%s'", searchTitle[:len(searchTitle)-len(ext)])
}
}
} }
_ = titleQuery.WriteByte(')')
query = append(query, titleQuery.String())
} }
if directoriesOnly { if directoriesOnly {
query = append(query, fmt.Sprintf("mimeType='%s'", driveFolderType)) query = append(query, fmt.Sprintf("mimeType='%s'", driveFolderType))
@ -546,7 +551,14 @@ OUTER:
// the `=` operator is case insensitive. // the `=` operator is case insensitive.
if title != "" && title != item.Name { if title != "" && title != item.Name {
if stem == "" || stem != item.Name { found := false
for _, stem := range stems {
if stem == item.Name {
found = true
break
}
}
if !found {
continue continue
} }
_, exportName, _, _ := f.findExportFormat(item) _, exportName, _, _ := f.findExportFormat(item)