func checkSealedCopy(cmd *seal.Command, c *gcli.Context) error { cmd.Verify = c.Bool(verifyAfterCopy) // have to do init ourselves as we set amount of writers nr, level, filters, err := cli.CheckCommonFlags(c) if err != nil { return err } nw := c.Int(streamsPerOutputDevice) if nw < 1 { return fmt.Errorf("--%v must not be smaller than 1", streamsPerOutputDevice) } return cmd.Init(nr, nw, c.Args(), level, filters) }
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) } }
func checkSeal(cmd *seal.Command, c *gcli.Context) error { cmd.Format = c.String(formatFlag) if len(cmd.Format) > 0 { valid := false for _, name := range codec.Names() { if name == cmd.Format { valid = true break } } if !valid { return fmt.Errorf("Invalid seal format '%s', must be one of %s", cmd.Format, strings.Join(codec.Names(), ", ")) } } if err := cli.CheckCommonFlagsAndInit(cmd, c); err != nil { return err } return nil }