mirror of
https://github.com/rclone/rclone.git
synced 2025-01-22 23:49:30 +08:00
rc: add relative to vfs/queue-set-expiry
This commit is contained in:
parent
6091a0362b
commit
d4e86f4d8b
12
vfs/rc.go
12
vfs/rc.go
|
@ -514,6 +514,7 @@ This takes the following parameters
|
||||||
- |fs| - select the VFS in use (optional)
|
- |fs| - select the VFS in use (optional)
|
||||||
- |id| - a numeric ID as returned from |vfs/queue|
|
- |id| - a numeric ID as returned from |vfs/queue|
|
||||||
- |expiry| - a new expiry time as floating point seconds
|
- |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.
|
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 err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
relative, err := in.GetBool("relative")
|
||||||
|
if err != nil && !rc.IsErrParamNotFound(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Set expiry
|
// Set expiry
|
||||||
expiryTime := time.Now().Add(time.Duration(float64(time.Second) * expiry))
|
var refTime time.Time
|
||||||
err = vfs.cache.QueueSetExpiry(writeback.Handle(id), expiryTime)
|
if !relative {
|
||||||
|
refTime = time.Now()
|
||||||
|
}
|
||||||
|
err = vfs.cache.QueueSetExpiry(writeback.Handle(id), refTime, time.Duration(float64(time.Second)*expiry))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,8 +178,11 @@ func (c *Cache) Queue() (out rc.Params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueueSetExpiry updates the expiry of a single item in the upload queue
|
// 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 parents
|
// createDir creates a directory path, along with any necessary parents
|
||||||
|
|
|
@ -748,6 +748,6 @@ func TestCacheQueueSetExpiry(t *testing.T) {
|
||||||
// Check this returns the correct error when called so we know
|
// Check this returns the correct error when called so we know
|
||||||
// it is plumbed in correctly. The actual tests are done in
|
// it is plumbed in correctly. The actual tests are done in
|
||||||
// writeback.
|
// writeback.
|
||||||
err := c.QueueSetExpiry(123123, time.Now())
|
err := c.QueueSetExpiry(123123, time.Now(), 0)
|
||||||
assert.Equal(t, writeback.ErrorIDNotFound, err)
|
assert.Equal(t, writeback.ErrorIDNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -519,8 +519,11 @@ var ErrorIDNotFound = errors.New("id not found in queue")
|
||||||
//
|
//
|
||||||
// id should be as returned from the Queue call
|
// 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
|
// 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()
|
wb.mu.Lock()
|
||||||
defer wb.mu.Unlock()
|
defer wb.mu.Unlock()
|
||||||
|
|
||||||
|
@ -529,6 +532,12 @@ func (wb *WriteBack) SetExpiry(id Handle, expiry time.Time) error {
|
||||||
return ErrorIDNotFound
|
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 value
|
// Update the expiry with the user requested value
|
||||||
wb.items._update(wbItem, expiry)
|
wb.items._update(wbItem, expiry)
|
||||||
wb._resetTimer()
|
wb._resetTimer()
|
||||||
|
|
|
@ -549,7 +549,7 @@ func TestWriteBackSetExpiry(t *testing.T) {
|
||||||
wb, cancel := newTestWriteBack(t)
|
wb, cancel := newTestWriteBack(t)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
err := wb.SetExpiry(123123123, time.Now())
|
err := wb.SetExpiry(123123123, time.Now(), 0)
|
||||||
assert.Equal(t, ErrorIDNotFound, err)
|
assert.Equal(t, ErrorIDNotFound, err)
|
||||||
|
|
||||||
pi := newPutItem(t)
|
pi := newPutItem(t)
|
||||||
|
@ -569,12 +569,12 @@ func TestWriteBackSetExpiry(t *testing.T) {
|
||||||
assert.Less(t, expiry, 1.0)
|
assert.Less(t, expiry, 1.0)
|
||||||
|
|
||||||
newExpiry := time.Now().Add(100 * time.Second)
|
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())
|
assert.Equal(t, newExpiry, getExpiry())
|
||||||
|
|
||||||
// This starts the transfer
|
// This starts the transfer
|
||||||
newExpiry = time.Now().Add(-100 * time.Second)
|
newExpiry = wbItem.expiry.Add(-200 * time.Second)
|
||||||
require.NoError(t, wb.SetExpiry(wbItem.id, newExpiry))
|
require.NoError(t, wb.SetExpiry(wbItem.id, time.Time{}, -200*time.Second))
|
||||||
assert.Equal(t, newExpiry, getExpiry())
|
assert.Equal(t, newExpiry, getExpiry())
|
||||||
|
|
||||||
<-pi.started
|
<-pi.started
|
||||||
|
|
Loading…
Reference in New Issue
Block a user