2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-30 08:44:02 +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 gopts, secondaryGopts = secondaryGopts, gopts
} }
ctx, cancel := context.WithCancel(gopts.ctx) ctx := gopts.ctx
defer cancel()
srcRepo, err := OpenRepository(gopts) srcRepo, err := OpenRepository(gopts)
if err != nil { if err != nil {
return err return err

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"context"
"github.com/restic/restic/internal/migrations" "github.com/restic/restic/internal/migrations"
"github.com/restic/restic/internal/restic" "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`) f.BoolVarP(&migrateOptions.Force, "force", "f", false, `apply a migration a second time`)
} }
func checkMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repository) error { func checkMigrations(ctx context.Context, repo restic.Repository) error {
ctx := gopts.ctx
Printf("available migrations:\n") Printf("available migrations:\n")
found := false found := false
@ -63,9 +64,7 @@ func checkMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repos
return nil return nil
} }
func applyMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repository, args []string) error { func applyMigrations(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, repo restic.Repository, args []string) error {
ctx := gopts.ctx
var firsterr error var firsterr error
for _, name := range args { for _, name := range args {
for _, m := range migrations.All { for _, m := range migrations.All {
@ -130,8 +129,8 @@ func runMigrate(opts MigrateOptions, gopts GlobalOptions, args []string) error {
} }
if len(args) == 0 { 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 package main
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@ -71,9 +70,7 @@ func runSnapshots(opts SnapshotOptions, gopts GlobalOptions, args []string) erro
} }
} }
ctx, cancel := context.WithCancel(gopts.ctx) ctx := gopts.ctx
defer cancel()
var snapshots restic.Snapshots var snapshots restic.Snapshots
for sn := range FindFilteredSnapshots(ctx, repo.Backend(), repo, opts.Hosts, opts.Tags, opts.Paths, args) { for sn := range FindFilteredSnapshots(ctx, repo.Backend(), repo, opts.Hosts, opts.Tags, opts.Paths, args) {
snapshots = append(snapshots, sn) snapshots = append(snapshots, sn)

View File

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

View File

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