mirror of
https://github.com/restic/restic.git
synced 2026-11-21 07:05:09 +00:00
Prepare for context bound to lock lifetime
This commit is contained in:
1 parent
985722b102
commit
928914f821
21 files changed
+47
-32
No files matched your search
+5
-5
@@ -19,15 +19,15 @@ var globalLocks struct {
|
||||
sync.Once
|
||||
}
|
||||
|
||||
func lockRepo(ctx context.Context, repo *repository.Repository) (*restic.Lock, error) {
|
||||
func lockRepo(ctx context.Context, repo *repository.Repository) (*restic.Lock, context.Context, error) {
|
||||
return lockRepository(ctx, repo, false)
|
||||
}
|
||||
|
||||
func lockRepoExclusive(ctx context.Context, repo *repository.Repository) (*restic.Lock, error) {
|
||||
func lockRepoExclusive(ctx context.Context, repo *repository.Repository) (*restic.Lock, context.Context, error) {
|
||||
return lockRepository(ctx, repo, true)
|
||||
}
|
||||
|
||||
func lockRepository(ctx context.Context, repo *repository.Repository, exclusive bool) (*restic.Lock, error) {
|
||||
func lockRepository(ctx context.Context, repo *repository.Repository, exclusive bool) (*restic.Lock, context.Context, error) {
|
||||
// make sure that a repository is unlocked properly and after cancel() was
|
||||
// called by the cleanup handler in global.go
|
||||
globalLocks.Do(func() {
|
||||
@@ -41,7 +41,7 @@ func lockRepository(ctx context.Context, repo *repository.Repository, exclusive
|
||||
|
||||
lock, err := lockFn(ctx, repo)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "unable to create lock in backend")
|
||||
return nil, ctx, errors.WithMessage(err, "unable to create lock in backend")
|
||||
}
|
||||
debug.Log("create lock %p (exclusive %v)", lock, exclusive)
|
||||
|
||||
@@ -57,7 +57,7 @@ func lockRepository(ctx context.Context, repo *repository.Repository, exclusive
|
||||
globalLocks.locks = append(globalLocks.locks, lock)
|
||||
globalLocks.Unlock()
|
||||
|
||||
return lock, err
|
||||
return lock, ctx, err
|
||||
}
|
||||
|
||||
var refreshInterval = 5 * time.Minute
|
||||
|
||||
Reference in new issue
Block a user