"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
config: convert --cache-dir value to an absolute path
albertonyf3e71f129c71
diff --git a/backend/cache/cache.go b/backend/cache/cache.goindex a20193db5..161df7118 100644--- a/backend/cache/cache.go+++ b/backend/cache/cache.go@@ -143,12 +143,12 @@ oldest chunks until it goes under this value.`,}},}, {Name: "db_path",- Default: filepath.Join(config.CacheDir, "cache-backend"),+ Default: filepath.Join(config.GetCacheDir(), "cache-backend"),Help: "Directory to store file structure metadata DB.\nThe remote name is used as the DB file name.",Advanced: true,}, {Name: "chunk_path",- Default: filepath.Join(config.CacheDir, "cache-backend"),+ Default: filepath.Join(config.GetCacheDir(), "cache-backend"),Help: `Directory to cache chunk files.Path to where partial file data (chunks) are stored locally. The remote@@ -421,8 +421,8 @@ func NewFs(ctx context.Context, name, rootPath string, m configmap.Mapper) (fs.FdbPath := f.opt.DbPathchunkPath := f.opt.ChunkPath// if the dbPath is non default but the chunk path is default, we overwrite the last to follow the same one as dbPath- if dbPath != filepath.Join(config.CacheDir, "cache-backend") &&- chunkPath == filepath.Join(config.CacheDir, "cache-backend") {+ if dbPath != filepath.Join(config.GetCacheDir(), "cache-backend") &&+ chunkPath == filepath.Join(config.GetCacheDir(), "cache-backend") {chunkPath = dbPath}if filepath.Ext(dbPath) != "" {diff --git a/backend/cache/cache_internal_test.go b/backend/cache/cache_internal_test.goindex 87300ec05..281d92af1 100644--- a/backend/cache/cache_internal_test.go+++ b/backend/cache/cache_internal_test.go@@ -926,9 +926,9 @@ func (r *run) newCacheFs(t *testing.T, remote, id string, needRemote, purge bool}}runInstance.rootIsCrypt = rootIsCrypt- runInstance.dbPath = filepath.Join(config.CacheDir, "cache-backend", cacheRemote+".db")- runInstance.chunkPath = filepath.Join(config.CacheDir, "cache-backend", cacheRemote)- runInstance.vfsCachePath = filepath.Join(config.CacheDir, "vfs", remote)+ runInstance.dbPath = filepath.Join(config.GetCacheDir(), "cache-backend", cacheRemote+".db")+ runInstance.chunkPath = filepath.Join(config.GetCacheDir(), "cache-backend", cacheRemote)+ runInstance.vfsCachePath = filepath.Join(config.GetCacheDir(), "vfs", remote)boltDb, err := cache.GetPersistent(runInstance.dbPath, runInstance.chunkPath, &cache.Features{PurgeDb: true})require.NoError(t, err)diff --git a/cmd/config/config.go b/cmd/config/config.goindex 555ac7063..5a28f3aae 100644--- a/cmd/config/config.go+++ b/cmd/config/config.go@@ -80,7 +80,7 @@ var configPathsCommand = &cobra.Command{Run: func(command *cobra.Command, args []string) {cmd.CheckArgs(0, 0, command, args)fmt.Printf("Config file: %s\n", config.GetConfigPath())- fmt.Printf("Cache dir: %s\n", config.CacheDir)+ fmt.Printf("Cache dir: %s\n", config.GetCacheDir())fmt.Printf("Temp dir: %s\n", os.TempDir())},}diff --git a/cmd/serve/docker/docker_test.go b/cmd/serve/docker/docker_test.goindex 169fd6e70..2a2a1ba59 100644--- a/cmd/serve/docker/docker_test.go+++ b/cmd/serve/docker/docker_test.go@@ -63,11 +63,12 @@ func assertVolumeInfo(t *testing.T, v *docker.VolInfo, name, path string) {func TestDockerPluginLogic(t *testing.T) {ctx := context.Background()- oldCacheDir := config.CacheDir+ oldCacheDir := config.GetCacheDir()testDir, testFs := initialise(ctx, t)- config.CacheDir = testDir+ err := config.SetCacheDir(testDir)+ require.NoError(t, err)defer func() {- config.CacheDir = oldCacheDir+ _ = config.SetCacheDir(oldCacheDir)if !t.Failed() {fstest.Purge(testFs)_ = os.RemoveAll(testDir)@@ -304,11 +305,12 @@ func testMountAPI(t *testing.T, sockAddr string) {}ctx := context.Background()- oldCacheDir := config.CacheDir+ oldCacheDir := config.GetCacheDir()testDir, testFs := initialise(ctx, t)- config.CacheDir = testDir+ err := config.SetCacheDir(testDir)+ require.NoError(t, err)defer func() {- config.CacheDir = oldCacheDir+ _ = config.SetCacheDir(oldCacheDir)if !t.Failed() {fstest.Purge(testFs)_ = os.RemoveAll(testDir)diff --git a/cmd/serve/docker/driver.go b/cmd/serve/docker/driver.goindex 14970958f..eb8207f52 100644--- a/cmd/serve/docker/driver.go+++ b/cmd/serve/docker/driver.go@@ -41,11 +41,8 @@ type Driver struct {// NewDriver makes a new docker driverfunc NewDriver(ctx context.Context, root string, mntOpt *mountlib.Options, vfsOpt *vfscommon.Options, dummy, forgetState bool) (*Driver, error) {// setup directories- cacheDir, err := filepath.Abs(config.CacheDir)- if err != nil {- return nil, errors.Wrap(err, "failed to make --cache-dir absolute")- }- err = file.MkdirAll(cacheDir, 0700)+ cacheDir := config.GetCacheDir()+ err := file.MkdirAll(cacheDir, 0700)if err != nil {return nil, errors.Wrapf(err, "failed to create cache directory: %s", cacheDir)}diff --git a/cmd/serve/sftp/server.go b/cmd/serve/sftp/server.goindex 379f48eb5..79446607d 100644--- a/cmd/serve/sftp/server.go+++ b/cmd/serve/sftp/server.go@@ -222,7 +222,7 @@ func (s *server) serve() (err error) {// Load the private key, from the cache if not explicitly configuredkeyPaths := s.opt.HostKeys- cachePath := filepath.Join(config.CacheDir, "serve-sftp")+ cachePath := filepath.Join(config.GetCacheDir(), "serve-sftp")if len(keyPaths) == 0 {keyPaths = []string{filepath.Join(cachePath, "id_rsa"),diff --git a/fs/config/config.go b/fs/config/config.goindex 0e72922d4..5ce802224 100644--- a/fs/config/config.go+++ b/fs/config/config.go@@ -102,17 +102,13 @@ type Storage interface {// Globalvar (- // CacheDir points to the cache directory. Users of this- // should make a subdirectory and use MkdirAll() to create it- // and any parents.- CacheDir = makeCacheDir()-// Password can be used to configure the random password generatorPassword = random.Password)var (configPath string+ cacheDir stringdata StoragedataLoaded bool)@@ -122,6 +118,7 @@ func init() {fs.ConfigFileGet = FileGetFlagfs.ConfigFileSet = SetValueAndSaveconfigPath = makeConfigPath()+ cacheDir = makeCacheDir() // Has fallback to tempDir, so set that firstdata = newDefaultStorage()}@@ -713,6 +710,21 @@ func makeCacheDir() (dir string) {return filepath.Join(dir, "rclone")}+// GetCacheDir returns the default directory for cache+//+// The directory is neither guaranteed to exist nor have accessible permissions.+// Users of this should make a subdirectory and use MkdirAll() to create it+// and any parents.+func GetCacheDir() string {+ return cacheDir+}++// SetCacheDir sets new default directory for cache+func SetCacheDir(path string) (err error) {+ cacheDir, err = filepath.Abs(path)+ return+}+// SetTempDir sets new default directory to use for temporary files.//// Assuming golang's os.TempDir is used to get the directory:diff --git a/fs/config/configflags/configflags.go b/fs/config/configflags/configflags.goindex fbe5a93b1..bb4afbaa6 100644--- a/fs/config/configflags/configflags.go+++ b/fs/config/configflags/configflags.go@@ -24,6 +24,7 @@ var (verbose intquiet boolconfigPath string+ cacheDir stringtempDir stringdumpHeaders booldumpBodies bool@@ -48,7 +49,7 @@ func AddFlags(ci *fs.ConfigInfo, flagSet *pflag.FlagSet) {flags.IntVarP(flagSet, &ci.Checkers, "checkers", "", ci.Checkers, "Number of checkers to run in parallel.")flags.IntVarP(flagSet, &ci.Transfers, "transfers", "", ci.Transfers, "Number of file transfers to run in parallel.")flags.StringVarP(flagSet, &configPath, "config", "", config.GetConfigPath(), "Config file.")- flags.StringVarP(flagSet, &config.CacheDir, "cache-dir", "", config.CacheDir, "Directory rclone will use for caching.")+ flags.StringVarP(flagSet, &cacheDir, "cache-dir", "", config.GetCacheDir(), "Directory rclone will use for caching.")flags.StringVarP(flagSet, &tempDir, "temp-dir", "", os.TempDir(), "Directory rclone will use for temporary files.")flags.BoolVarP(flagSet, &ci.CheckSum, "checksum", "c", ci.CheckSum, "Skip based on checksum (if available) & size, not mod-time & size")flags.BoolVarP(flagSet, &ci.SizeOnly, "size-only", "", ci.SizeOnly, "Skip based on size only, not mod-time or checksum")@@ -281,6 +282,11 @@ func SetFlags(ci *fs.ConfigInfo) {log.Fatalf("--config: Failed to set %q as config path: %v", configPath, err)}+ // Set path to cache dir+ if err := config.SetCacheDir(cacheDir); err != nil {+ log.Fatalf("--cache-dir: Failed to set %q as cache dir: %v", cacheDir, err)+ }+// Set path to temp dirif err := config.SetTempDir(tempDir); err != nil {log.Fatalf("--temp-dir: Failed to set %q as temp dir: %v", tempDir, err)diff --git a/fs/rc/rcserver/rcserver.go b/fs/rc/rcserver/rcserver.goindex cf2a6c126..39498e388 100644--- a/fs/rc/rcserver/rcserver.go+++ b/fs/rc/rcserver/rcserver.go@@ -76,7 +76,7 @@ func newServer(ctx context.Context, opt *rc.Options, mux *http.ServeMux) *Server_ = mime.AddExtensionType(".wasm", "application/wasm")_ = mime.AddExtensionType(".js", "application/javascript")- cachePath := filepath.Join(config.CacheDir, "webgui")+ cachePath := filepath.Join(config.GetCacheDir(), "webgui")extractPath := filepath.Join(cachePath, "current/build")// File handlingif opt.Files != "" {@@ -86,7 +86,7 @@ func newServer(ctx context.Context, opt *rc.Options, mux *http.ServeMux) *Serverfs.Logf(nil, "Serving files from %q", opt.Files)fileHandler = http.FileServer(http.Dir(opt.Files))} else if opt.WebUI {- if err := webgui.CheckAndDownloadWebGUIRelease(opt.WebGUIUpdate, opt.WebGUIForceUpdate, opt.WebGUIFetchURL, config.CacheDir); err != nil {+ if err := webgui.CheckAndDownloadWebGUIRelease(opt.WebGUIUpdate, opt.WebGUIForceUpdate, opt.WebGUIFetchURL, config.GetCacheDir()); err != nil {log.Fatalf("Error while fetching the latest release of Web GUI: %v", err)}if opt.NoAuth {diff --git a/fs/rc/webgui/plugins.go b/fs/rc/webgui/plugins.goindex 67205f033..7bc22be54 100644--- a/fs/rc/webgui/plugins.go+++ b/fs/rc/webgui/plugins.go@@ -89,7 +89,7 @@ func initPluginsOrError() error {initMutex.Lock()defer initMutex.Unlock()if !initSuccess {- cachePath = filepath.Join(config.CacheDir, "webgui")+ cachePath = filepath.Join(config.GetCacheDir(), "webgui")PluginsPath = filepath.Join(cachePath, "plugins")pluginsConfigPath = filepath.Join(PluginsPath, "config")loadedPlugins = newPlugins(availablePluginsJSONPath)diff --git a/vfs/vfscache/cache.go b/vfs/vfscache/cache.goindex c12d5c409..483bdf39c 100644--- a/vfs/vfscache/cache.go+++ b/vfs/vfscache/cache.go@@ -82,10 +82,7 @@ func New(ctx context.Context, fremote fs.Fs, opt *vfscommon.Options, avFn AddVir// Care must be taken when creating OS paths so that the ':' separator following a// drive letter is not encoded (e.g. into unicode fullwidth colon).var err error- parentOSPath := config.CacheDir // Assuming string contains a local path in OS encoding- if parentOSPath, err = filepath.Abs(parentOSPath); err != nil {- return nil, errors.Wrap(err, "failed to make --cache-dir absolute")- }+ parentOSPath := config.GetCacheDir() // Assuming string contains a local absolute path in OS encodingfs.Debugf(nil, "vfs cache: root is %q", parentOSPath)parentPath := fromOSPath(parentOSPath)