1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-24 16:54:00 +00:00

Merge pull request #2391 from kastenhq/refresh-lock-time

Update Lock.Time in lock.Refresh()
This commit is contained in:
rawtaz 2019-11-26 21:44:29 +01:00 committed by GitHub
commit da4473aba6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -221,6 +221,7 @@ func (l *Lock) Stale() bool {
// timestamp. Afterwards the old lock is removed.
func (l *Lock) Refresh(ctx context.Context) error {
debug.Log("refreshing lock %v", l.lockID)
l.Time = time.Now()
id, err := l.createLock(ctx)
if err != nil {
return err

View file

@ -225,6 +225,7 @@ func TestLockRefresh(t *testing.T) {
lock, err := restic.NewLock(context.TODO(), repo)
rtest.OK(t, err)
time0 := lock.Time
var lockID *restic.ID
err = repo.List(context.TODO(), restic.LockFile, func(id restic.ID, size int64) error {
@ -238,6 +239,7 @@ func TestLockRefresh(t *testing.T) {
t.Fatal(err)
}
time.Sleep(time.Millisecond)
rtest.OK(t, lock.Refresh(context.TODO()))
var lockID2 *restic.ID
@ -254,5 +256,9 @@ func TestLockRefresh(t *testing.T) {
rtest.Assert(t, !lockID.Equal(*lockID2),
"expected a new ID after lock refresh, got the same")
lock2, err := restic.LoadLock(context.TODO(), repo, *lockID2)
rtest.OK(t, err)
rtest.Assert(t, lock2.Time.After(time0),
"expected a later timestamp after lock refresh")
rtest.OK(t, lock.Unlock())
}