diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index bd56d1182..0324468a3 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -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 diff --git a/cmd/restic/cmd_diff.go b/cmd/restic/cmd_diff.go index 5fdd28d97..76b377928 100644 --- a/cmd/restic/cmd_diff.go +++ b/cmd/restic/cmd_diff.go @@ -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 diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 5f1c07ab2..96c11e655 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -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, diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index 29d3c81ff..da7681867 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -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() diff --git a/cmd/restic/cmd_key.go b/cmd/restic/cmd_key.go index 69c2542b7..ac64078f3 100644 --- a/cmd/restic/cmd_key.go +++ b/cmd/restic/cmd_key.go @@ -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 diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index df7fd7b18..ddd02e65d 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -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) diff --git a/cmd/restic/cmd_migrate.go b/cmd/restic/cmd_migrate.go index b0a5319ea..85ebc2e99 100644 --- a/cmd/restic/cmd_migrate.go +++ b/cmd/restic/cmd_migrate.go @@ -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) } diff --git a/cmd/restic/cmd_snapshots.go b/cmd/restic/cmd_snapshots.go index 80a205dcf..b394a89af 100644 --- a/cmd/restic/cmd_snapshots.go +++ b/cmd/restic/cmd_snapshots.go @@ -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) diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index d845cb223..dbc16f91e 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -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 diff --git a/cmd/restic/cmd_tag.go b/cmd/restic/cmd_tag.go index 7a2561235..cd52e7241 100644 --- a/cmd/restic/cmd_tag.go +++ b/cmd/restic/cmd_tag.go @@ -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 {