diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index cb4c25141..286ef51e2 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -57,7 +57,7 @@ Exit status is 3 if some source data could not be read (incomplete snapshot crea }, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - ctx := globalCtx() + ctx := cmd.Context() var wg sync.WaitGroup cancelCtx, cancel := context.WithCancel(ctx) defer func() { diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index c2fedfcd4..16fa968a8 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -25,7 +25,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runCat(globalCtx(), globalOptions, args) + return runCat(cmd.Context(), globalOptions, args) }, } diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index 0b20a5061..692a19ba1 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -35,7 +35,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runCheck(globalCtx(), checkOptions, globalOptions, args) + return runCheck(cmd.Context(), checkOptions, globalOptions, args) }, PreRunE: func(cmd *cobra.Command, args []string) error { return checkFlags(checkOptions) diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index 8acbfc288..08df7e8a7 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -32,7 +32,7 @@ This can be mitigated by the "--copy-chunker-params" option when initializing a new destination repository using the "init" command. `, RunE: func(cmd *cobra.Command, args []string) error { - return runCopy(globalCtx(), copyOptions, globalOptions, args) + return runCopy(cmd.Context(), copyOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index 71bad2dac..38bc30ec8 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -46,7 +46,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runDebugDump(globalCtx(), globalOptions, args) + return runDebugDump(cmd.Context(), globalOptions, args) }, } @@ -193,7 +193,7 @@ var cmdDebugExamine = &cobra.Command{ Short: "Examine a pack file", DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runDebugExamine(globalCtx(), globalOptions, args) + return runDebugExamine(cmd.Context(), globalOptions, args) }, } diff --git a/cmd/restic/cmd_diff.go b/cmd/restic/cmd_diff.go index 967995072..2444e677b 100644 --- a/cmd/restic/cmd_diff.go +++ b/cmd/restic/cmd_diff.go @@ -35,7 +35,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runDiff(globalCtx(), diffOptions, globalOptions, args) + return runDiff(cmd.Context(), diffOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_dump.go b/cmd/restic/cmd_dump.go index f892225cf..508cb5c76 100644 --- a/cmd/restic/cmd_dump.go +++ b/cmd/restic/cmd_dump.go @@ -34,7 +34,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runDump(globalCtx(), dumpOptions, globalOptions, args) + return runDump(cmd.Context(), dumpOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index d47495ed5..8e5f9b604 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -38,7 +38,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runFind(globalCtx(), findOptions, globalOptions, args) + return runFind(cmd.Context(), findOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index 60f454e69..f1aef75e3 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -32,7 +32,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runForget(globalCtx(), forgetOptions, globalOptions, args) + return runForget(cmd.Context(), forgetOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_init.go b/cmd/restic/cmd_init.go index 4922a58b1..f833369ef 100644 --- a/cmd/restic/cmd_init.go +++ b/cmd/restic/cmd_init.go @@ -26,7 +26,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runInit(globalCtx(), initOptions, globalOptions, args) + return runInit(cmd.Context(), initOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_key.go b/cmd/restic/cmd_key.go index b497343e4..52143bbc1 100644 --- a/cmd/restic/cmd_key.go +++ b/cmd/restic/cmd_key.go @@ -28,7 +28,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runKey(globalCtx(), globalOptions, args) + return runKey(cmd.Context(), globalOptions, args) }, } diff --git a/cmd/restic/cmd_list.go b/cmd/restic/cmd_list.go index 9aa713879..81390ecf8 100644 --- a/cmd/restic/cmd_list.go +++ b/cmd/restic/cmd_list.go @@ -23,7 +23,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runList(globalCtx(), cmd, globalOptions, args) + return runList(cmd.Context(), cmd, globalOptions, args) }, } diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index 96465c431..fd9a0ef0d 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -42,7 +42,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runLs(globalCtx(), lsOptions, globalOptions, args) + return runLs(cmd.Context(), lsOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_migrate.go b/cmd/restic/cmd_migrate.go index ffd855b48..6d614be39 100644 --- a/cmd/restic/cmd_migrate.go +++ b/cmd/restic/cmd_migrate.go @@ -24,7 +24,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runMigrate(globalCtx(), migrateOptions, globalOptions, args) + return runMigrate(cmd.Context(), migrateOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index 0bbd1e6d5..95ee7efcf 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -68,7 +68,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runMount(globalCtx(), mountOptions, globalOptions, args) + return runMount(cmd.Context(), mountOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index 01ce0da26..74b0db026 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -34,7 +34,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runPrune(globalCtx(), pruneOptions, globalOptions) + return runPrune(cmd.Context(), pruneOptions, globalOptions) }, } diff --git a/cmd/restic/cmd_rebuild_index.go b/cmd/restic/cmd_rebuild_index.go index cb2917183..15a21df65 100644 --- a/cmd/restic/cmd_rebuild_index.go +++ b/cmd/restic/cmd_rebuild_index.go @@ -24,7 +24,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runRebuildIndex(globalCtx(), rebuildIndexOptions, globalOptions) + return runRebuildIndex(cmd.Context(), rebuildIndexOptions, globalOptions) }, } diff --git a/cmd/restic/cmd_recover.go b/cmd/restic/cmd_recover.go index b296f7b9b..65f4c8750 100644 --- a/cmd/restic/cmd_recover.go +++ b/cmd/restic/cmd_recover.go @@ -27,7 +27,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runRecover(globalCtx(), globalOptions) + return runRecover(cmd.Context(), globalOptions) }, } diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index 6ddec5233..1254174d7 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -31,7 +31,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runRestore(globalCtx(), restoreOptions, globalOptions, args) + return runRestore(cmd.Context(), restoreOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_self_update.go b/cmd/restic/cmd_self_update.go index cc10c4c77..23345a97c 100644 --- a/cmd/restic/cmd_self_update.go +++ b/cmd/restic/cmd_self_update.go @@ -28,7 +28,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runSelfUpdate(globalCtx(), selfUpdateOptions, globalOptions, args) + return runSelfUpdate(cmd.Context(), selfUpdateOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_snapshots.go b/cmd/restic/cmd_snapshots.go index 82561722c..0bfa4d110 100644 --- a/cmd/restic/cmd_snapshots.go +++ b/cmd/restic/cmd_snapshots.go @@ -26,7 +26,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runSnapshots(globalCtx(), snapshotOptions, globalOptions, args) + return runSnapshots(cmd.Context(), snapshotOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index f03026574..d49b0ad34 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -47,7 +47,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runStats(globalCtx(), globalOptions, args) + return runStats(cmd.Context(), globalOptions, args) }, } diff --git a/cmd/restic/cmd_tag.go b/cmd/restic/cmd_tag.go index bf880dafb..222ddd04a 100644 --- a/cmd/restic/cmd_tag.go +++ b/cmd/restic/cmd_tag.go @@ -29,7 +29,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runTag(globalCtx(), tagOptions, globalOptions, args) + return runTag(cmd.Context(), tagOptions, globalOptions, args) }, } diff --git a/cmd/restic/cmd_unlock.go b/cmd/restic/cmd_unlock.go index bcdef18f6..7b449d949 100644 --- a/cmd/restic/cmd_unlock.go +++ b/cmd/restic/cmd_unlock.go @@ -20,7 +20,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runUnlock(globalCtx(), unlockOptions, globalOptions) + return runUnlock(cmd.Context(), unlockOptions, globalOptions) }, } diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 82a4cfcca..fb14934f8 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -145,10 +145,6 @@ func init() { restoreTerminal() } -func globalCtx() context.Context { - return internalGlobalCtx -} - // checkErrno returns nil when err is set to syscall.Errno(0), since this is no // error condition. func checkErrno(err error) error { diff --git a/cmd/restic/main.go b/cmd/restic/main.go index ad3ef89d4..2582a3781 100644 --- a/cmd/restic/main.go +++ b/cmd/restic/main.go @@ -95,7 +95,7 @@ func main() { debug.Log("main %#v", os.Args) debug.Log("restic %s compiled with %v on %v/%v", version, runtime.Version(), runtime.GOOS, runtime.GOARCH) - err := cmdRoot.Execute() + err := cmdRoot.ExecuteContext(internalGlobalCtx) switch { case restic.IsAlreadyLocked(err):