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

config: add config/paths to the rc as rclone config paths equivalent

Nick Craig-Woodc482624a6ca5
diff --git a/fs/config/rc.go b/fs/config/rc.go
index 951adefe5..114dcffd1 100644
--- a/fs/config/rc.go
+++ b/fs/config/rc.go
@@ -3,6 +3,7 @@ package config
import (
"context"
"errors"
+ "os"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/rc"
@@ -242,3 +243,38 @@ func rcSetPath(ctx context.Context, in rc.Params) (out rc.Params, err error) {
err = SetConfigPath(path)
return nil, err
}
+
+func init() {
+ rc.Add(rc.Call{
+ Path: "config/paths",
+ Fn: rcPaths,
+ Title: "Reads the config file path and other important paths.",
+ AuthRequired: true,
+ Help: `
+Returns a JSON object with the following keys:
+
+- config: path to config file
+- cache: path to root of cache directory
+- temp: path to root of temporary directory
+
+Eg
+
+ {
+ "cache": "/home/USER/.cache/rclone",
+ "config": "/home/USER/.rclone.conf",
+ "temp": "/tmp"
+ }
+
+See the [config paths](/commands/rclone_config_paths/) command for more information on the above.
+`,
+ })
+}
+
+// Set the config file path
+func rcPaths(ctx context.Context, in rc.Params) (out rc.Params, err error) {
+ return rc.Params{
+ "config": GetConfigPath(),
+ "cache": GetCacheDir(),
+ "temp": os.TempDir(),
+ }, nil
+}
diff --git a/fs/config/rc_test.go b/fs/config/rc_test.go
index ac5a60ca3..891b9bcbc 100644
--- a/fs/config/rc_test.go
+++ b/fs/config/rc_test.go
@@ -177,3 +177,14 @@ func TestRcSetPath(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, oldPath, config.GetConfigPath())
}
+
+func TestRcPaths(t *testing.T) {
+ call := rc.Calls.Get("config/paths")
+ assert.NotNil(t, call)
+ out, err := call.Fn(context.Background(), nil)
+ require.NoError(t, err)
+
+ assert.Equal(t, config.GetConfigPath(), out["config"])
+ assert.Equal(t, config.GetCacheDir(), out["cache"])
+ assert.Equal(t, os.TempDir(), out["temp"])
+}