"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
test changenotify: add command to help debugging changenotify
Nick Craig-Wood4a9469a3dc24
diff --git a/cmd/all/all.go b/cmd/all/all.goindex 3d3f09b3f..63442520f 100644--- a/cmd/all/all.go+++ b/cmd/all/all.go@@ -54,6 +54,7 @@ import (_ "github.com/rclone/rclone/cmd/size"_ "github.com/rclone/rclone/cmd/sync"_ "github.com/rclone/rclone/cmd/test"+ _ "github.com/rclone/rclone/cmd/test/changenotify"_ "github.com/rclone/rclone/cmd/test/histogram"_ "github.com/rclone/rclone/cmd/test/info"_ "github.com/rclone/rclone/cmd/test/makefiles"diff --git a/cmd/test/changenotify/changenotify.go b/cmd/test/changenotify/changenotify.gonew file mode 100644index 000000000..7e79fa941--- /dev/null+++ b/cmd/test/changenotify/changenotify.go@@ -0,0 +1,54 @@+// Package changenotify tests rclone's changenotify support+package changenotify++import (+ "context"+ "errors"+ "time"++ "github.com/rclone/rclone/cmd"+ "github.com/rclone/rclone/cmd/test"+ "github.com/rclone/rclone/fs"+ "github.com/rclone/rclone/fs/config/flags"+ "github.com/spf13/cobra"+)++var (+ pollInterval = 10 * time.Second+)++func init() {+ test.Command.AddCommand(commandDefinition)+ cmdFlags := commandDefinition.Flags()+ flags.DurationVarP(cmdFlags, &pollInterval, "poll-interval", "", pollInterval, "Time to wait between polling for changes.")+}++var commandDefinition = &cobra.Command{+ Use: "changenotify remote:",+ Short: `Log any change notify requests for the remote passed in.`,+ RunE: func(command *cobra.Command, args []string) error {+ cmd.CheckArgs(1, 1, command, args)+ f := cmd.NewFsSrc(args)+ ctx := context.Background()++ // Start polling function+ features := f.Features()+ if do := features.ChangeNotify; do != nil {+ pollChan := make(chan time.Duration)+ do(ctx, changeNotify, pollChan)+ pollChan <- pollInterval+ fs.Logf(nil, "Waiting for changes, polling every %v", pollInterval)+ } else {+ return errors.New("poll-interval is not supported by this remote")+ }+ select {}+ },+}++// changeNotify invalidates the directory cache for the relativePath+// passed in.+//+// if entryType is a directory it invalidates the parent of the directory too.+func changeNotify(relativePath string, entryType fs.EntryType) {+ fs.Logf(nil, "%q: %v", relativePath, entryType)+}