From 4b0fcaed456675f6e7cb276be94421d92a09def9 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 10 Apr 2020 11:44:15 +0200 Subject: [PATCH] unlock: use proper context for locks cleanup The list operation used by RemoveStaleLocks or RemoveAllLocks will already be canceled by the passed in context. Therefore we can also just cancel the remove operation as the unlock command won't process all lock files anyways. --- internal/restic/lock.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/restic/lock.go b/internal/restic/lock.go index 28807ce69..7047bb52d 100644 --- a/internal/restic/lock.go +++ b/internal/restic/lock.go @@ -284,7 +284,7 @@ func RemoveStaleLocks(ctx context.Context, repo Repository) error { } if lock.Stale() { - return repo.Backend().Remove(context.TODO(), Handle{Type: LockFile, Name: id.String()}) + return repo.Backend().Remove(ctx, Handle{Type: LockFile, Name: id.String()}) } return nil @@ -294,6 +294,6 @@ func RemoveStaleLocks(ctx context.Context, repo Repository) error { // RemoveAllLocks removes all locks forcefully. func RemoveAllLocks(ctx context.Context, repo Repository) error { return repo.List(ctx, LockFile, func(id ID, size int64) error { - return repo.Backend().Remove(context.TODO(), Handle{Type: LockFile, Name: id.String()}) + return repo.Backend().Remove(ctx, Handle{Type: LockFile, Name: id.String()}) }) }