"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
rc: add core/version and put definitions next to implementations
Nick Craig-Wood1916410316b2
diff --git a/fs/rc/internal.go b/fs/rc/internal.goindex b5e8a1d00..448cd2f95 100644--- a/fs/rc/internal.go+++ b/fs/rc/internal.go@@ -6,29 +6,39 @@ import ("os""runtime"+ "github.com/ncw/rclone/fs"+ "github.com/ncw/rclone/fs/version""github.com/pkg/errors")func init() {Add(Call{- Path: "rc/noop",- Fn: rcNoop,- Title: "Echo the input to the output parameters",+ Path: "rc/noopauth",+ AuthRequired: true,+ Fn: rcNoop,+ Title: "Echo the input to the output parameters requiring auth",Help: `This echoes the input parameters to the output parameters for testingpurposes. It can be used to check that rclone is still alive and tocheck that parameter passing is working properly.`,})Add(Call{- Path: "rc/noopauth",- AuthRequired: true,- Fn: rcNoop,- Title: "Echo the input to the output parameters requiring auth",+ Path: "rc/noop",+ Fn: rcNoop,+ Title: "Echo the input to the output parameters",Help: `This echoes the input parameters to the output parameters for testingpurposes. It can be used to check that rclone is still alive and tocheck that parameter passing is working properly.`,})+}++// Echo the input to the ouput parameters+func rcNoop(in Params) (out Params, err error) {+ return in, nil+}++func init() {Add(Call{Path: "rc/error",Fn: rcError,@@ -37,6 +47,14 @@ check that parameter passing is working properly.`,This returns an error with the input as part of its error string.Useful for testing error handling.`,})+}++// Return an error regardless+func rcError(in Params) (out Params, err error) {+ return nil, errors.Errorf("arbitrary error on input %+v", in)+}++func init() {Add(Call{Path: "rc/list",Fn: rcList,@@ -45,6 +63,16 @@ Useful for testing error handling.`,This lists all the registered remote control commands as a JSON map inthe commands response.`,})+}++// List the registered commands+func rcList(in Params) (out Params, err error) {+ out = make(Params)+ out["commands"] = Calls.List()+ return out, nil+}++func init() {Add(Call{Path: "core/pid",Fn: rcPid,@@ -53,6 +81,16 @@ the commands response.`,This returns PID of current process.Useful for stopping rclone process.`,})+}++// Return PID of current process+func rcPid(in Params) (out Params, err error) {+ out = make(Params)+ out["pid"] = os.Getpid()+ return out, nil+}++func init() {Add(Call{Path: "core/memstats",Fn: rcMemStats,@@ -69,40 +107,6 @@ The most interesting values for most people are:* It is virtual memory so may include unused memory`,})- Add(Call{- Path: "core/gc",- Fn: rcGc,- Title: "Runs a garbage collection.",- Help: `-This tells the go runtime to do a garbage collection run. It isn't-necessary to call this normally, but it can be useful for debugging-memory problems.-`,- })-}--// Echo the input to the ouput parameters-func rcNoop(in Params) (out Params, err error) {- return in, nil-}--// Return an error regardless-func rcError(in Params) (out Params, err error) {- return nil, errors.Errorf("arbitrary error on input %+v", in)-}--// List the registered commands-func rcList(in Params) (out Params, err error) {- out = make(Params)- out["commands"] = Calls.List()- return out, nil-}--// Return PID of current process-func rcPid(in Params) (out Params, err error) {- out = make(Params)- out["pid"] = os.Getpid()- return out, nil}// Return the memory statistics@@ -133,8 +137,57 @@ func rcMemStats(in Params) (out Params, err error) {return out, nil}+func init() {+ Add(Call{+ Path: "core/gc",+ Fn: rcGc,+ Title: "Runs a garbage collection.",+ Help: `+This tells the go runtime to do a garbage collection run. It isn't+necessary to call this normally, but it can be useful for debugging+memory problems.+`,+ })+}+// Do a garbage collection runfunc rcGc(in Params) (out Params, err error) {runtime.GC()return nil, nil}++func init() {+ Add(Call{+ Path: "core/version",+ Fn: rcVersion,+ Title: "Shows the current version of rclone and the go runtime.",+ Help: `+This shows the current version of go and the go runtime+- version - rclone version, eg "v1.44"+- decomposed - version number as [major, minor, patch, subpatch]+ - note patch and subpatch will be 999 for a git compiled version+- isGit - boolean - true if this was compiled from the git version+- os - OS in use as according to Go+- arch - cpu architecture in use according to Go+- goVersion - version of Go runtime in use++`,+ })+}++// Return version info+func rcVersion(in Params) (out Params, err error) {+ decomposed, err := version.New(fs.Version)+ if err != nil {+ return nil, err+ }+ out = Params{+ "version": fs.Version,+ "decomposed": decomposed,+ "isGit": decomposed.IsGit(),+ "os": runtime.GOOS,+ "arch": runtime.GOARCH,+ "goVersion": runtime.Version(),+ }+ return out, nil+}diff --git a/fs/rc/internal_test.go b/fs/rc/internal_test.goindex cf8c39ff2..4cd133ffc 100644--- a/fs/rc/internal_test.go+++ b/fs/rc/internal_test.go@@ -1,8 +1,11 @@package rcimport (+ "runtime""testing"+ "github.com/ncw/rclone/fs"+ "github.com/ncw/rclone/fs/version""github.com/stretchr/testify/assert""github.com/stretchr/testify/require")@@ -74,3 +77,19 @@ func TestCoreGC(t *testing.T) {require.Nil(t, out)assert.Equal(t, Params(nil), out)}++func TestCoreVersion(t *testing.T) {+ call := Calls.Get("core/version")+ assert.NotNil(t, call)+ in := Params{}+ out, err := call.Fn(in)+ require.NoError(t, err)+ require.NotNil(t, out)+ assert.Equal(t, fs.Version, out["version"])+ assert.Equal(t, runtime.GOOS, out["os"])+ assert.Equal(t, runtime.GOARCH, out["arch"])+ assert.Equal(t, runtime.Version(), out["goVersion"])+ _ = out["isGit"].(bool)+ v := out["decomposed"].(version.Version)+ assert.True(t, len(v) >= 2)+}