Merge pull request #412 from filecoin-project/feat/init-fail-cleanup

Clean up after failed storage miner init
This commit is contained in:
Whyrusleeping 2019-10-18 16:08:18 +09:00 committed by GitHub
commit d891589cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,8 @@ package main
import (
"context"
"crypto/rand"
"fmt"
"os"
"github.com/libp2p/go-libp2p-core/crypto"
@ -58,7 +60,8 @@ var initCmd = &cli.Command{
log.Info("Checking if repo exists")
r, err := repo.NewFS(cctx.String(FlagStorageRepo))
repoPath := cctx.String(FlagStorageRepo)
r, err := repo.NewFS(repoPath)
if err != nil {
return err
}
@ -97,6 +100,23 @@ var initCmd = &cli.Command{
return err
}
if err := storageMinerInit(ctx, cctx, api, r); err != nil {
fmt.Printf("ERROR: failed to initialize lotus-storage-miner: %s\n", err)
fmt.Println("Cleaning up after attempt...")
if err := os.RemoveAll(repoPath); err != nil {
fmt.Println("ERROR: failed to clean up failed storage repo: ", err)
}
return fmt.Errorf("storage-miner init failed")
}
// TODO: Point to setting storage price, maybe do it interactively or something
log.Info("Storage miner successfully created, you can now start it with 'lotus-storage-miner run'")
return nil
},
}
func storageMinerInit(ctx context.Context, cctx *cli.Context, api api.FullNode, r repo.Repo) error {
lr, err := r.Lock()
if err != nil {
return err
@ -136,6 +156,8 @@ var initCmd = &cli.Command{
addr = a
}
log.Infof("Created new storage miner: %s", addr)
ds, err := lr.Datastore("/metadata")
if err != nil {
return err
@ -144,11 +166,7 @@ var initCmd = &cli.Command{
return err
}
// TODO: Point to setting storage price, maybe do it interactively or something
log.Info("Storage miner successfully created, you can now start it with 'lotus-storage-miner run'")
return nil
},
}
func makeHostKey(lr repo.LockedRepo) (crypto.PrivKey, error) {