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

Fixes #7568
This commit is contained in:
Nick Craig-Wood 2024-01-17 10:36:17 +00:00
parent 17fea90ac9
commit c482624a6c
2 changed files with 47 additions and 0 deletions

View File

@ -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
}

View File

@ -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"])
}