2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

Remove unnecessary context.WithCancel calls

The gopts.ctx is cancelled when the main() method of restic exits.
This commit is contained in:
Michael Eischer 2021-10-31 22:56:57 +01:00
parent 7ce4cb7908
commit d0668b695d
10 changed files with 15 additions and 36 deletions

View File

@ -62,9 +62,7 @@ func runCopy(opts CopyOptions, gopts GlobalOptions, args []string) error {
gopts, secondaryGopts = secondaryGopts, gopts
}
ctx, cancel := context.WithCancel(gopts.ctx)
defer cancel()
ctx := gopts.ctx
srcRepo, err := OpenRepository(gopts)
if err != nil {
return err

View File

@ -326,9 +326,7 @@ func runDiff(opts DiffOptions, gopts GlobalOptions, args []string) error {
return errors.Fatalf("specify two snapshot IDs")
}
ctx, cancel := context.WithCancel(gopts.ctx)
defer cancel()
ctx := gopts.ctx
repo, err := OpenRepository(gopts)
if err != nil {
return err

View File

@ -590,9 +590,7 @@ func runFind(opts FindOptions, gopts GlobalOptions, args []string) error {
return err
}
ctx, cancel := context.WithCancel(gopts.ctx)
defer cancel()
ctx := gopts.ctx
f := &Finder{
repo: repo,
pat: pat,

View File

@ -1,7 +1,6 @@
package main
import (
"context"
"encoding/json"
"io"
@ -122,9 +121,7 @@ func runForget(opts ForgetOptions, gopts GlobalOptions, args []string) error {
}
}
ctx, cancel := context.WithCancel(gopts.ctx)
defer cancel()
ctx := gopts.ctx
var snapshots restic.Snapshots
removeSnIDs := restic.NewIDSet()

View File

@ -202,9 +202,7 @@ func runKey(gopts GlobalOptions, args []string) error {
return errors.Fatal("wrong number of arguments")
}
ctx, cancel := context.WithCancel(gopts.ctx)
defer cancel()
ctx := gopts.ctx
repo, err := OpenRepository(gopts)
if err != nil {
return err

View File

@ -1,7 +1,6 @@
package main
import (
"context"
"encoding/json"
"os"
"strings"
@ -175,9 +174,7 @@ func runLs(opts LsOptions, gopts GlobalOptions, args []string) error {
return err
}
ctx, cancel := context.WithCancel(gopts.ctx)
defer cancel()
ctx := gopts.ctx
var (
printSnapshot func(sn *restic.Snapshot)
printNode func(path string, node *restic.Node)

View File

@ -1,6 +1,8 @@
package main
import (
"context"
"github.com/restic/restic/internal/migrations"
"github.com/restic/restic/internal/restic"
@ -39,8 +41,7 @@ func init() {
f.BoolVarP(&migrateOptions.Force, "force", "f", false, `apply a migration a second time`)
}
func checkMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repository) error {
ctx := gopts.ctx
func checkMigrations(ctx context.Context, repo restic.Repository) error {
Printf("available migrations:\n")
found := false
@ -63,9 +64,7 @@ func checkMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repos
return nil
}
func applyMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repository, args []string) error {
ctx := gopts.ctx
func applyMigrations(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, repo restic.Repository, args []string) error {
var firsterr error
for _, name := range args {
for _, m := range migrations.All {
@ -130,8 +129,8 @@ func runMigrate(opts MigrateOptions, gopts GlobalOptions, args []string) error {
}
if len(args) == 0 {
return checkMigrations(opts, gopts, repo)
return checkMigrations(gopts.ctx, repo)
}
return applyMigrations(opts, gopts, repo, args)
return applyMigrations(gopts.ctx, opts, gopts, repo, args)
}

View File

@ -1,7 +1,6 @@
package main
import (
"context"
"encoding/json"
"fmt"
"io"
@ -71,9 +70,7 @@ func runSnapshots(opts SnapshotOptions, gopts GlobalOptions, args []string) erro
}
}
ctx, cancel := context.WithCancel(gopts.ctx)
defer cancel()
ctx := gopts.ctx
var snapshots restic.Snapshots
for sn := range FindFilteredSnapshots(ctx, repo.Backend(), repo, opts.Hosts, opts.Tags, opts.Paths, args) {
snapshots = append(snapshots, sn)

View File

@ -74,9 +74,7 @@ func runStats(gopts GlobalOptions, args []string) error {
return err
}
ctx, cancel := context.WithCancel(gopts.ctx)
defer cancel()
ctx := gopts.ctx
repo, err := OpenRepository(gopts)
if err != nil {
return err

View File

@ -118,8 +118,7 @@ func runTag(opts TagOptions, gopts GlobalOptions, args []string) error {
}
changeCnt := 0
ctx, cancel := context.WithCancel(gopts.ctx)
defer cancel()
ctx := gopts.ctx
for sn := range FindFilteredSnapshots(ctx, repo.Backend(), repo, opts.Hosts, opts.Tags, opts.Paths, args) {
changed, err := changeTags(ctx, repo, sn, opts.SetTags.Flatten(), opts.AddTags.Flatten(), opts.RemoveTags.Flatten())
if err != nil {