Pass context to lockRepo

This commit is contained in:
Michael Eischer 2020-08-09 13:24:47 +02:00
parent 37a5e2d681
commit 0c9efa9c2a
21 changed files with 30 additions and 30 deletions

View file

@ -496,7 +496,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina
if !gopts.JSON {
p.V("lock repository")
}
lock, err := lockRepo(repo)
lock, err := lockRepo(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -42,7 +42,7 @@ func runCat(gopts GlobalOptions, args []string) error {
return err
}
lock, err := lockRepo(repo)
lock, err := lockRepo(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -158,7 +158,7 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error {
if !gopts.NoLock {
Verbosef("create exclusive lock for repository\n")
lock, err := lockRepoExclusive(repo)
lock, err := lockRepoExclusive(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -65,13 +65,13 @@ func runCopy(opts CopyOptions, gopts GlobalOptions, args []string) error {
return err
}
srcLock, err := lockRepo(srcRepo)
srcLock, err := lockRepo(ctx, srcRepo)
defer unlockRepo(srcLock)
if err != nil {
return err
}
dstLock, err := lockRepo(dstRepo)
dstLock, err := lockRepo(ctx, dstRepo)
defer unlockRepo(dstLock)
if err != nil {
return err

View file

@ -134,7 +134,7 @@ func runDebugDump(gopts GlobalOptions, args []string) error {
}
if !gopts.NoLock {
lock, err := lockRepo(repo)
lock, err := lockRepo(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -332,7 +332,7 @@ func runDiff(opts DiffOptions, gopts GlobalOptions, args []string) error {
}
if !gopts.NoLock {
lock, err := lockRepo(repo)
lock, err := lockRepo(ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -140,7 +140,7 @@ func runDump(opts DumpOptions, gopts GlobalOptions, args []string) error {
}
if !gopts.NoLock {
lock, err := lockRepo(repo)
lock, err := lockRepo(ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -529,7 +529,7 @@ func runFind(opts FindOptions, gopts GlobalOptions, args []string) error {
}
if !gopts.NoLock {
lock, err := lockRepo(repo)
lock, err := lockRepo(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -88,7 +88,7 @@ func runForget(opts ForgetOptions, gopts GlobalOptions, args []string) error {
return err
}
lock, err := lockRepoExclusive(repo)
lock, err := lockRepoExclusive(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -188,7 +188,7 @@ func runKey(gopts GlobalOptions, args []string) error {
switch args[0] {
case "list":
lock, err := lockRepo(repo)
lock, err := lockRepo(ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err
@ -196,7 +196,7 @@ func runKey(gopts GlobalOptions, args []string) error {
return listKeys(ctx, repo, gopts)
case "add":
lock, err := lockRepo(repo)
lock, err := lockRepo(ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err
@ -204,7 +204,7 @@ func runKey(gopts GlobalOptions, args []string) error {
return addKey(gopts, repo)
case "remove":
lock, err := lockRepoExclusive(repo)
lock, err := lockRepoExclusive(ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err
@ -217,7 +217,7 @@ func runKey(gopts GlobalOptions, args []string) error {
return deleteKey(gopts.ctx, repo, id)
case "passwd":
lock, err := lockRepoExclusive(repo)
lock, err := lockRepoExclusive(ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -40,7 +40,7 @@ func runList(cmd *cobra.Command, opts GlobalOptions, args []string) error {
}
if !opts.NoLock {
lock, err := lockRepo(repo)
lock, err := lockRepo(opts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -99,7 +99,7 @@ func runMigrate(opts MigrateOptions, gopts GlobalOptions, args []string) error {
return err
}
lock, err := lockRepoExclusive(repo)
lock, err := lockRepoExclusive(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -91,7 +91,7 @@ func mount(opts MountOptions, gopts GlobalOptions, mountpoint string) error {
}
if !gopts.NoLock {
lock, err := lockRepo(repo)
lock, err := lockRepo(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -50,7 +50,7 @@ func runPrune(gopts GlobalOptions) error {
return err
}
lock, err := lockRepoExclusive(repo)
lock, err := lockRepoExclusive(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -38,7 +38,7 @@ func runRebuildIndex(gopts GlobalOptions) error {
return err
}
lock, err := lockRepoExclusive(repo)
lock, err := lockRepoExclusive(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -43,7 +43,7 @@ func runRecover(gopts GlobalOptions) error {
return err
}
lock, err := lockRepo(repo)
lock, err := lockRepo(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -102,7 +102,7 @@ func runRestore(opts RestoreOptions, gopts GlobalOptions, args []string) error {
}
if !gopts.NoLock {
lock, err := lockRepo(repo)
lock, err := lockRepo(ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -61,7 +61,7 @@ func runSnapshots(opts SnapshotOptions, gopts GlobalOptions, args []string) erro
}
if !gopts.NoLock {
lock, err := lockRepo(repo)
lock, err := lockRepo(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -91,7 +91,7 @@ func runStats(gopts GlobalOptions, args []string) error {
}
if !gopts.NoLock {
lock, err := lockRepo(repo)
lock, err := lockRepo(ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -119,7 +119,7 @@ func runTag(opts TagOptions, gopts GlobalOptions, args []string) error {
if !gopts.NoLock {
Verbosef("create exclusive lock for repository\n")
lock, err := lockRepoExclusive(repo)
lock, err := lockRepoExclusive(gopts.ctx, repo)
defer unlockRepo(lock)
if err != nil {
return err

View file

@ -18,21 +18,21 @@ var globalLocks struct {
sync.Mutex
}
func lockRepo(repo *repository.Repository) (*restic.Lock, error) {
return lockRepository(repo, false)
func lockRepo(ctx context.Context, repo *repository.Repository) (*restic.Lock, error) {
return lockRepository(ctx, repo, false)
}
func lockRepoExclusive(repo *repository.Repository) (*restic.Lock, error) {
return lockRepository(repo, true)
func lockRepoExclusive(ctx context.Context, repo *repository.Repository) (*restic.Lock, error) {
return lockRepository(ctx, repo, true)
}
func lockRepository(repo *repository.Repository, exclusive bool) (*restic.Lock, error) {
func lockRepository(ctx context.Context, repo *repository.Repository, exclusive bool) (*restic.Lock, error) {
lockFn := restic.NewLock
if exclusive {
lockFn = restic.NewExclusiveLock
}
lock, err := lockFn(context.TODO(), repo)
lock, err := lockFn(ctx, repo)
if err != nil {
return nil, errors.WithMessage(err, "unable to create lock in backend")
}