From 1596d06f8e71219e368ec83d57598439fc7bc45e Mon Sep 17 00:00:00 2001 From: Eric Hamilton Date: Wed, 4 Sep 2019 11:38:35 -0700 Subject: [PATCH] Update Lock.Time in lock.Refresh() --- internal/restic/lock.go | 1 + internal/restic/lock_test.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/internal/restic/lock.go b/internal/restic/lock.go index 3e3a27a6b..142fa4b73 100644 --- a/internal/restic/lock.go +++ b/internal/restic/lock.go @@ -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 diff --git a/internal/restic/lock_test.go b/internal/restic/lock_test.go index daadd479f..09dce3c78 100644 --- a/internal/restic/lock_test.go +++ b/internal/restic/lock_test.go @@ -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()) }