Exemple #1
0
func startSealedCopy(cmd *seal.Command, c *gcli.Context) {

	// Yes, currently the post-verification is only implemented in the CLI ...
	// Testing needs to do similar things to set it up ...
	if cmd.Verify {
		// Setup a aggregation result handler which tracks produced indices
		var indices []string
		cmdDone := make(chan bool)

		handler := cli.MakeLogHandler(cmd.LogLevel())
		aggHandler := api.IndexTrackingResultHandlerAdapter(&indices, handler)

		// and run ourselves
		err := api.StartEngine(cmd, aggHandler)
		// Make sure we don't keep logging while verification is going with its own handler
		close(cmdDone)

		if err == nil && len(indices) == 0 {
			panic("Unexpectedly I didn't see a single seal index without error")
		} else if len(indices) > 0 {
			// no matter whether we have an error, try to verify what's there
			select {
			case <-cmd.Done:
				// this does nothing, most importantly, it doesn't run verify, as we don't run it
				// after cancellation. It's arguable whether we migth want to do that anyway
				// as the index is valid !
			default:
				{
					// prepare and run a verify command
					verifycmd, err := verify.NewCommand(indices, c.GlobalInt(cli.StreamsPerInputDeviceFlagName))
					if err == nil {
						err = api.StartEngine(verifycmd, handler)
					}
				}
			}
		}

		// Finally, exit with appropriate error code
		if err != nil {
			os.Exit(1)
		}
	} else {
		// copy without verify
		cli.RunAction(cmd, c)
	}
}
Exemple #2
0
// Runs a standard runner from within the cli, dealing with errors accoringly
func RunAction(cmd api.Runner, c *cli.Context) {
	handler := MakeLogHandler(cmd.LogLevel())
	err := api.StartEngine(cmd, handler)
	nerr := CliFinishApp(c)
	if err != nil || nerr != nil {
		os.Exit(1)
	}
}