func coreDownloadCmd()

in newtmgr/cli/image.go [251:303]


func coreDownloadCmd(cmd *cobra.Command, args []string) {
	if len(args) < 1 {
		nmUsage(cmd, nil)
	}

	tmpName := args[0] + ".tmp"
	file, err := os.OpenFile(tmpName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0660)
	if err != nil {
		nmUsage(cmd, util.NewNewtError(fmt.Sprintf(
			"Cannot open file %s - %s", tmpName, err.Error())))
	}
	defer os.Remove(tmpName)
	defer file.Close()

	s, err := GetSesn()
	if err != nil {
		nmUsage(nil, err)
	}

	c := xact.NewCoreLoadCmd()
	c.SetTxOptions(nmutil.TxOptions())
	c.ProgressCb = func(c *xact.CoreLoadCmd, rsp *nmp.CoreLoadRsp) {
		fmt.Printf("%d\n", rsp.Off)
		if _, err := file.Write(rsp.Data); err != nil {
			nmUsage(nil, util.ChildNewtError(err))
		}
	}

	res, err := c.Run(s)
	if err != nil {
		nmUsage(nil, util.ChildNewtError(err))
	}

	sres := res.(*xact.CoreLoadResult)
	if sres.Status() != 0 {
		fmt.Printf("Error: %d\n", sres.Status())
		return
	}

	if !coreElfify {
		os.Rename(tmpName, args[0])
		fmt.Printf("Done writing core file to %s\n", args[0])
	} else {
		coreConvert, err := core.ConvertFilenames(tmpName, args[0])
		if err != nil {
			nmUsage(nil, err)
			return
		}

		fmt.Printf("Done writing core file to %s; hash=%x\n", args[0],
			coreConvert.ImageHash)
	}
}