repository: remove global list of locks

This commit is contained in:
Michael Eischer
2024-02-24 16:45:57 +01:00
parent cbb5f89252
commit e8df50fa3c
3 changed files with 34 additions and 94 deletions
+10 -16
View File
@@ -2,16 +2,10 @@ package main
import (
"context"
"sync"
"github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic"
)
var globalLocks struct {
sync.Once
}
func internalOpenWithLocked(ctx context.Context, gopts GlobalOptions, dryRun bool, exclusive bool) (context.Context, *repository.Repository, func(), error) {
repo, err := OpenRepository(ctx, gopts)
if err != nil {
@@ -20,22 +14,22 @@ func internalOpenWithLocked(ctx context.Context, gopts GlobalOptions, dryRun boo
unlock := func() {}
if !dryRun {
var lock *restic.Lock
// make sure that a repository is unlocked properly and after cancel() was
// called by the cleanup handler in global.go
globalLocks.Do(func() {
AddCleanupHandler(repository.UnlockAll)
})
var lock *repository.Unlocker
lock, ctx, err = repository.Lock(ctx, repo, exclusive, gopts.RetryLock, func(msg string) {
if !gopts.JSON {
Verbosef("%s", msg)
}
}, Warnf)
unlock = func() {
repository.Unlock(lock)
}
unlock = lock.Unlock
// make sure that a repository is unlocked properly and after cancel() was
// called by the cleanup handler in global.go
AddCleanupHandler(func(code int) (int, error) {
lock.Unlock()
return code, nil
})
if err != nil {
return nil, nil, nil, err
}