mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +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:
committed by
Michael Eischer
parent
4dbed5f905
commit
4686a12a2d
@@ -30,14 +30,12 @@ func registerProfiling(cmd *cobra.Command) {
|
|||||||
return profiler.Start(profiler.opts)
|
return profiler.Start(profiler.opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
origPostRun := cmd.PersistentPostRunE
|
// Once https://github.com/spf13/cobra/issues/1893 is fixed,
|
||||||
cmd.PersistentPostRunE = func(cmd *cobra.Command, args []string) error {
|
// this could use PersistentPostRunE instead of OnFinalize,
|
||||||
|
// reverting https://github.com/restic/restic/pull/5373.
|
||||||
|
cobra.OnFinalize(func() {
|
||||||
profiler.Stop()
|
profiler.Stop()
|
||||||
if origPostRun != nil {
|
})
|
||||||
return origPostRun(cmd, args)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
profiler.opts.AddFlags(cmd.PersistentFlags())
|
profiler.opts.AddFlags(cmd.PersistentFlags())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user