1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

Add context propagation to rclone

- Change rclone/fs interfaces to accept context.Context
- Update interface implementations to use context.Context
- Change top level usage to propagate context to lover level functions

Context propagation is needed for stopping transfers and passing other
request-scoped values.
This commit is contained in:
Aleksandar Jankovic
2019-06-17 10:34:30 +02:00
committed by Nick Craig-Wood
parent a2c317b46e
commit f78cd1e043
156 changed files with 2570 additions and 2380 deletions

View File

@@ -1,6 +1,7 @@
package fs
import (
"context"
"mime"
"path"
"strings"
@@ -17,10 +18,10 @@ func MimeTypeFromName(remote string) (mimeType string) {
// MimeType returns the MimeType from the object, either by calling
// the MimeTyper interface or using MimeTypeFromName
func MimeType(o ObjectInfo) (mimeType string) {
func MimeType(ctx context.Context, o ObjectInfo) (mimeType string) {
// Read the MimeType from the optional interface if available
if do, ok := o.(MimeTyper); ok {
mimeType = do.MimeType()
mimeType = do.MimeType(ctx)
// Debugf(o, "Read MimeType as %q", mimeType)
if mimeType != "" {
return mimeType
@@ -33,10 +34,10 @@ func MimeType(o ObjectInfo) (mimeType string) {
//
// It returns "inode/directory" for directories, or uses
// MimeType(Object)
func MimeTypeDirEntry(item DirEntry) string {
func MimeTypeDirEntry(ctx context.Context, item DirEntry) string {
switch x := item.(type) {
case Object:
return MimeType(x)
return MimeType(ctx, x)
case Directory:
return "inode/directory"
}