fs: Add context to NewFs #3257 #4685

This adds a context.Context parameter to NewFs and related calls.

This is necessary as part of reading config from the context -
backends need to be able to read the global config.
This commit is contained in:
Nick Craig-Wood
2020-11-05 15:18:51 +00:00
parent 30c8b1b84f
commit d846210978
82 changed files with 231 additions and 227 deletions

View File

@@ -7,6 +7,7 @@ package cmd
// would probably mean bringing all the flags in to here? Or define some flagsets in fs...
import (
"context"
"fmt"
"log"
"math/rand"
@@ -88,7 +89,7 @@ func NewFsFile(remote string) (fs.Fs, string) {
err = fs.CountError(err)
log.Fatalf("Failed to create file system for %q: %v", remote, err)
}
f, err := cache.Get(remote)
f, err := cache.Get(context.Background(), remote)
switch err {
case fs.ErrorIsFile:
cache.Pin(f) // pin indefinitely since it was on the CLI
@@ -138,7 +139,7 @@ func NewFsSrc(args []string) fs.Fs {
//
// This must point to a directory
func newFsDir(remote string) fs.Fs {
f, err := cache.Get(remote)
f, err := cache.Get(context.Background(), remote)
if err != nil {
err = fs.CountError(err)
log.Fatalf("Failed to create file system for %q: %v", remote, err)
@@ -192,7 +193,7 @@ func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs
log.Fatalf("%q is a directory", args[1])
}
}
fdst, err := cache.Get(dstRemote)
fdst, err := cache.Get(context.Background(), dstRemote)
switch err {
case fs.ErrorIsFile:
_ = fs.CountError(err)
@@ -400,7 +401,7 @@ func initConfig() {
}
// Start the remote control server if configured
_, err = rcserver.Start(&rcflags.Opt)
_, err = rcserver.Start(context.Background(), &rcflags.Opt)
if err != nil {
log.Fatalf("Failed to start remote control: %v", err)
}