Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

drive: fix imports of text files

Nick Craig-Wood9f8e1a1dc554
diff --git a/backend/drive/drive.go b/backend/drive/drive.go
index a268e8b07..f60e0ba2f 100644
--- a/backend/drive/drive.go
+++ b/backend/drive/drive.go
@@ -676,28 +676,33 @@ func isPowerOfTwo(x int64) bool {
}
// add a charset parameter to all text/* MIME types
-func fixMimeType(mimeType string) string {
- mediaType, param, err := mime.ParseMediaType(mimeType)
+func fixMimeType(mimeTypeIn string) string {
+ if mimeTypeIn == "" {
+ return ""
+ }
+ mediaType, param, err := mime.ParseMediaType(mimeTypeIn)
if err != nil {
- return mimeType
+ return mimeTypeIn
}
- if strings.HasPrefix(mimeType, "text/") && param["charset"] == "" {
+ mimeTypeOut := mimeTypeIn
+ if strings.HasPrefix(mediaType, "text/") && param["charset"] == "" {
param["charset"] = "utf-8"
- mimeType = mime.FormatMediaType(mediaType, param)
+ mimeTypeOut = mime.FormatMediaType(mediaType, param)
+ }
+ if mimeTypeOut == "" {
+ panic(errors.Errorf("unable to fix MIME type %q", mimeTypeIn))
}
- return mimeType
+ return mimeTypeOut
}
-func fixMimeTypeMap(m map[string][]string) map[string][]string {
- for _, v := range m {
+func fixMimeTypeMap(in map[string][]string) (out map[string][]string) {
+ out = make(map[string][]string, len(in))
+ for k, v := range in {
for i, mt := range v {
- fixed := fixMimeType(mt)
- if fixed == "" {
- panic(errors.Errorf("unable to fix MIME type %q", mt))
- }
- v[i] = fixed
+ v[i] = fixMimeType(mt)
}
+ out[fixMimeType(k)] = v
}
- return m
+ return out
}
func isInternalMimeType(mimeType string) bool {
return strings.HasPrefix(mimeType, "application/vnd.google-apps.")