Merge pull request #412 from filecoin-project/feat/init-fail-cleanup
Clean up after failed storage miner init
This commit is contained in:
commit
d891589cef
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user