Ejemplo n.º 1
0
func runRestore(ctx context.Context, args []string) (err error) {
	// Extract and parse arguments.
	if len(args) != 2 {
		err = fmt.Errorf("Usage: %s restore dst_dir score", os.Args[0])
		return
	}

	dstDir := args[0]
	score, err := blob.ParseHexScore(args[1])
	if err != nil {
		err = fmt.Errorf("ParseHexScore(%q): %v", args[1], err)
		return
	}

	// Grab dependencies.
	blobStore := getBlobStore(ctx)

	// Make sure the target doesn't exist.
	err = os.RemoveAll(dstDir)
	if err != nil {
		err = fmt.Errorf("os.RemoveAll: %v", err)
		return
	}

	// Create the destination.
	err = os.Mkdir(dstDir, 0700)
	if err != nil {
		err = fmt.Errorf("os.Mkdir: %v", err)
		return
	}

	// Attempt a restore.
	err = restore.Restore(
		ctx,
		dstDir,
		score,
		blobStore,
		log.New(os.Stderr, "Restore progress: ", 0),
	)

	if err != nil {
		err = fmt.Errorf("Restoring: %v", err)
		return
	}

	log.Printf("Successfully restored to %s", dstDir)
	return
}
Ejemplo n.º 2
0
// Parse a node name previously generated by Node.String.
func parseNode(s string) (n Node, err error) {
	var hexScore string

	switch {
	case strings.HasPrefix(s, filePrefix):
		hexScore = strings.TrimPrefix(s, filePrefix)

	case strings.HasPrefix(s, dirPrefix):
		n.Dir = true
		hexScore = strings.TrimPrefix(s, dirPrefix)

	default:
		err = fmt.Errorf("Unknown prefix")
		return
	}

	n.Score, err = blob.ParseHexScore(hexScore)
	if err != nil {
		err = fmt.Errorf("ParseHexScore: %v", err)
		return
	}

	return
}