mirror of
https://github.com/restic/restic.git
synced 2025-08-13 22:57:44 +00:00
bugfix: have --{cpu,mem,...}-profile
work even if Restic exits with error code (#5373)
* bugfix: write pprof file for `--{cpu,mem,...}-profile` even on error code Before this, if `restic backup --cpu-profile dir/ backup-dir/` couldn't read some of the input files (e.g. they weren't readable by the user restic was running under), the `cpu.pprof` file it outputs would be empty. https://github.com/spf13/cobra/issues/1893 * drop changelog as it's not relevant for end users --------- Co-authored-by: Michael Eischer <michael.eischer@fau.de>
This commit is contained in:
@@ -30,14 +30,12 @@ func registerProfiling(cmd *cobra.Command) {
|
||||
return profiler.Start(profiler.opts)
|
||||
}
|
||||
|
||||
origPostRun := cmd.PersistentPostRunE
|
||||
cmd.PersistentPostRunE = func(cmd *cobra.Command, args []string) error {
|
||||
// Once https://github.com/spf13/cobra/issues/1893 is fixed,
|
||||
// this could use PersistentPostRunE instead of OnFinalize,
|
||||
// reverting https://github.com/restic/restic/pull/5373.
|
||||
cobra.OnFinalize(func() {
|
||||
profiler.Stop()
|
||||
if origPostRun != nil {
|
||||
return origPostRun(cmd, args)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
|
||||
profiler.opts.AddFlags(cmd.PersistentFlags())
|
||||
}
|
||||
|
Reference in New Issue
Block a user