From c482624a6ca5f2fff78bd97767bc7ca7427a50e9 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 17 Jan 2024 10:36:17 +0000 Subject: [PATCH] config: add config/paths to the rc as rclone config paths equivalent Fixes #7568 --- fs/config/rc.go | 36 ++++++++++++++++++++++++++++++++++++ fs/config/rc_test.go | 11 +++++++++++ 2 files changed, 47 insertions(+) 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"]) +}