"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 relative to vfs/queue-set-expiry
Nick Craig-Woodd4e86f4d8b07
diff --git a/vfs/rc.go b/vfs/rc.goindex 72060984b..5c74e9f91 100644--- a/vfs/rc.go+++ b/vfs/rc.go@@ -514,6 +514,7 @@ This takes the following parameters- |fs| - select the VFS in use (optional)- |id| - a numeric ID as returned from |vfs/queue|- |expiry| - a new expiry time as floating point seconds+- |relative| - if set, expiry is to be treated as relative to the current expiry (optional, boolean)This returns an empty result on success, or an error.@@ -540,9 +541,16 @@ func rcQueueSetExpiry(ctx context.Context, in rc.Params) (out rc.Params, err errif err != nil {return nil, err}+ relative, err := in.GetBool("relative")+ if err != nil && !rc.IsErrParamNotFound(err) {+ return nil, err+ }// Set expiry- expiryTime := time.Now().Add(time.Duration(float64(time.Second) * expiry))- err = vfs.cache.QueueSetExpiry(writeback.Handle(id), expiryTime)+ var refTime time.Time+ if !relative {+ refTime = time.Now()+ }+ err = vfs.cache.QueueSetExpiry(writeback.Handle(id), refTime, time.Duration(float64(time.Second)*expiry))return nil, err}diff --git a/vfs/vfscache/cache.go b/vfs/vfscache/cache.goindex a0af31bd1..a17c79948 100644--- a/vfs/vfscache/cache.go+++ b/vfs/vfscache/cache.go@@ -178,8 +178,11 @@ func (c *Cache) Queue() (out rc.Params) {}// QueueSetExpiry updates the expiry of a single item in the upload queue-func (c *Cache) QueueSetExpiry(id writeback.Handle, expiry time.Time) error {- return c.writeback.SetExpiry(id, expiry)+//+// The expiry time is set to expiry + relative if expiry is passed in,+// otherwise the expiry of the item is used.+func (c *Cache) QueueSetExpiry(id writeback.Handle, expiry time.Time, relative time.Duration) error {+ return c.writeback.SetExpiry(id, expiry, relative)}// createDir creates a directory path, along with any necessary parentsdiff --git a/vfs/vfscache/cache_test.go b/vfs/vfscache/cache_test.goindex 9f8abfa64..327962cf2 100644--- a/vfs/vfscache/cache_test.go+++ b/vfs/vfscache/cache_test.go@@ -748,6 +748,6 @@ func TestCacheQueueSetExpiry(t *testing.T) {// Check this returns the correct error when called so we know// it is plumbed in correctly. The actual tests are done in// writeback.- err := c.QueueSetExpiry(123123, time.Now())+ err := c.QueueSetExpiry(123123, time.Now(), 0)assert.Equal(t, writeback.ErrorIDNotFound, err)}diff --git a/vfs/vfscache/writeback/writeback.go b/vfs/vfscache/writeback/writeback.goindex 6212bfec9..b3c022253 100644--- a/vfs/vfscache/writeback/writeback.go+++ b/vfs/vfscache/writeback/writeback.go@@ -519,8 +519,11 @@ var ErrorIDNotFound = errors.New("id not found in queue")//// id should be as returned from the Queue call//+// The expiry time is set to expiry + relative if expiry is passed in,+// otherwise the expiry of the item is used.+//// If the item isn't found then it will return ErrorIDNotFound-func (wb *WriteBack) SetExpiry(id Handle, expiry time.Time) error {+func (wb *WriteBack) SetExpiry(id Handle, expiry time.Time, relative time.Duration) error {wb.mu.Lock()defer wb.mu.Unlock()@@ -529,6 +532,12 @@ func (wb *WriteBack) SetExpiry(id Handle, expiry time.Time) error {return ErrorIDNotFound}+ // If expiry is not supplied, use expiry of item+ if expiry.IsZero() {+ expiry = wbItem.expiry+ }+ expiry = expiry.Add(relative)+// Update the expiry with the user requested valuewb.items._update(wbItem, expiry)wb._resetTimer()diff --git a/vfs/vfscache/writeback/writeback_test.go b/vfs/vfscache/writeback/writeback_test.goindex 872d19e71..9bbf90f0d 100644--- a/vfs/vfscache/writeback/writeback_test.go+++ b/vfs/vfscache/writeback/writeback_test.go@@ -549,7 +549,7 @@ func TestWriteBackSetExpiry(t *testing.T) {wb, cancel := newTestWriteBack(t)defer cancel()- err := wb.SetExpiry(123123123, time.Now())+ err := wb.SetExpiry(123123123, time.Now(), 0)assert.Equal(t, ErrorIDNotFound, err)pi := newPutItem(t)@@ -569,12 +569,12 @@ func TestWriteBackSetExpiry(t *testing.T) {assert.Less(t, expiry, 1.0)newExpiry := time.Now().Add(100 * time.Second)- require.NoError(t, wb.SetExpiry(wbItem.id, newExpiry))+ require.NoError(t, wb.SetExpiry(wbItem.id, newExpiry, 0))assert.Equal(t, newExpiry, getExpiry())// This starts the transfer- newExpiry = time.Now().Add(-100 * time.Second)- require.NoError(t, wb.SetExpiry(wbItem.id, newExpiry))+ newExpiry = wbItem.expiry.Add(-200 * time.Second)+ require.NoError(t, wb.SetExpiry(wbItem.id, time.Time{}, -200*time.Second))assert.Equal(t, newExpiry, getExpiry())<-pi.started