"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 add short parameter to core/stats to not return transferring and checking
Nick Craig-Woode47f59e1f9a4
diff --git a/fs/accounting/stats.go b/fs/accounting/stats.goindex 88686e6c5..c50ef77b0 100644--- a/fs/accounting/stats.go+++ b/fs/accounting/stats.go@@ -92,7 +92,9 @@ func NewStats(ctx context.Context) *StatsInfo {}// RemoteStats returns stats for rc-func (s *StatsInfo) RemoteStats() (out rc.Params, err error) {+//+// If short is true then the transfers and checkers won't be added.+func (s *StatsInfo) RemoteStats(short bool) (out rc.Params, err error) {// NB if adding values here - make sure you update the docs in// stats_groups.go@@ -128,10 +130,10 @@ func (s *StatsInfo) RemoteStats() (out rc.Params, err error) {}s.mu.RUnlock()- if !s.checking.empty() {+ if !short && !s.checking.empty() {out["checking"] = s.checking.remotes()}- if !s.transferring.empty() {+ if !short && !s.transferring.empty() {out["transferring"] = s.transferring.rcStats(s.inProgress)}if s.errors > 0 {@@ -561,7 +563,7 @@ func (s *StatsInfo) Transferred() []TransferSnapshot {// Log outputs the StatsInfo to the logfunc (s *StatsInfo) Log() {if s.ci.UseJSONLog {- out, _ := s.RemoteStats()+ out, _ := s.RemoteStats(false)fs.LogLevelPrintf(s.ci.StatsLogLevel, nil, "%v%v\n", s, fs.LogValueHide("stats", out))} else {fs.LogLevelPrintf(s.ci.StatsLogLevel, nil, "%v\n", s)diff --git a/fs/accounting/stats_groups.go b/fs/accounting/stats_groups.goindex 5f8e44d17..13236aa52 100644--- a/fs/accounting/stats_groups.go+++ b/fs/accounting/stats_groups.go@@ -56,11 +56,13 @@ func rcRemoteStats(ctx context.Context, in rc.Params) (rc.Params, error) {if rc.NotErrParamNotFound(err) {return rc.Params{}, err}+ short, _ := in.GetBool("short")+if group != "" {- return StatsGroup(ctx, group).RemoteStats()+ return StatsGroup(ctx, group).RemoteStats(short)}- return groups.sum(ctx).RemoteStats()+ return groups.sum(ctx).RemoteStats(short)}func init() {@@ -78,7 +80,8 @@ returned.Parameters-- group - name of the stats group (string)+- group - name of the stats group (string, optional)+- short - if true will not return the transferring and checking arrays (boolean, optional)Returns the following values:diff --git a/fs/accounting/stats_groups_test.go b/fs/accounting/stats_groups_test.goindex 4a0cd8628..e0d156672 100644--- a/fs/accounting/stats_groups_test.go+++ b/fs/accounting/stats_groups_test.go@@ -2,6 +2,7 @@ package accountingimport ("context"+ "encoding/json""fmt""runtime""testing"@@ -10,6 +11,7 @@ import ("github.com/rclone/rclone/fs""github.com/rclone/rclone/fs/fserrors""github.com/rclone/rclone/fs/rc"+ "github.com/rclone/rclone/fstest/mockobject""github.com/rclone/rclone/fstest/testy""github.com/stretchr/testify/assert""github.com/stretchr/testify/require"@@ -141,14 +143,35 @@ func TestStatsGroupOperations(t *testing.T) {})t.Run("core/stats", func(t *testing.T) {+ tr := Stats(ctx).NewCheckingTransfer(mockobject.New("core-check"), "deleting")+ // defer tr.Done(ctx, nil)+ _ = tr // don't finish the transfer so we don't mess up the other tests+ tr2 := Stats(ctx).NewTransfer(mockobject.New("core-transfer"), nil)+ //defer tr2.Done(ctx, nil)+ _ = tr2 // don't finish the transfer so we don't mess up the other tests+call := rc.Calls.Get("core/stats")require.NotNil(t, call)- gotNoGroup, err := call.Fn(ctx, rc.Params{})++ got, err := call.Fn(ctx, rc.Params{})require.NoError(t, err)- gotGroup, err := call.Fn(ctx, rc.Params{"group": "test-group"})+ assert.Equal(t, int64(42), got["deletes"])+ data, err := json.Marshal(got["transferring"])+ require.NoError(t, err)+ assert.Contains(t, string(data), "core-transfer")+ data, err = json.Marshal(got["checking"])+ require.NoError(t, err)+ assert.Contains(t, string(data), "core-check")++ got, err = call.Fn(ctx, rc.Params{"short": true})+ require.NoError(t, err)+ assert.Equal(t, int64(42), got["deletes"])+ assert.Nil(t, got["transferring"])+ assert.Nil(t, got["checking"])++ got, err = call.Fn(ctx, rc.Params{"group": "test-group"})require.NoError(t, err)- assert.Equal(t, int64(42), gotNoGroup["deletes"])- assert.Equal(t, int64(1), gotGroup["deletes"])+ assert.Equal(t, int64(1), got["deletes"])})t.Run("core/transferred", func(t *testing.T) {diff --git a/fs/accounting/stats_test.go b/fs/accounting/stats_test.goindex a6378d065..6fcc09837 100644--- a/fs/accounting/stats_test.go+++ b/fs/accounting/stats_test.go@@ -265,7 +265,7 @@ func TestRemoteStats(t *testing.T) {}s.AddTransfer(tr1)time.Sleep(time.Millisecond)- rs, err := s.RemoteStats()+ rs, err := s.RemoteStats(false)require.NoError(t, err)assert.Equal(t, float64(10), rs["transferTime"])