Make redeclare cmd work
- Fix an issue where `lotus-miner storage redeclare --all` required an argument - Actually implement the logic to redeclare a single sectors in a single storage path
This commit is contained in:
parent
a0ebd8bb16
commit
f671654bdd
@ -235,14 +235,19 @@ var storageRedeclareCmd = &cli.Command{
|
||||
defer closer()
|
||||
ctx := lcli.ReqContext(cctx)
|
||||
|
||||
if cctx.NArg() != 1 {
|
||||
return lcli.IncorrectNumArgs(cctx)
|
||||
// check if no argument and no --id or --all flag is provided
|
||||
if cctx.NArg() == 0 && !cctx.IsSet("id") && !cctx.Bool("all") {
|
||||
return xerrors.Errorf("You must specify a storage path, or --id, or --all")
|
||||
}
|
||||
|
||||
if cctx.IsSet("id") && cctx.Bool("all") {
|
||||
return xerrors.Errorf("--id and --all can't be passed at the same time")
|
||||
}
|
||||
|
||||
if cctx.Bool("all") && cctx.NArg() > 0 {
|
||||
return xerrors.Errorf("No additional arguments are expected when --all is set")
|
||||
}
|
||||
|
||||
if cctx.IsSet("id") {
|
||||
id := storiface.ID(cctx.String("id"))
|
||||
return minerApi.StorageRedeclareLocal(ctx, &id, cctx.Bool("drop-missing"))
|
||||
@ -252,7 +257,24 @@ var storageRedeclareCmd = &cli.Command{
|
||||
return minerApi.StorageRedeclareLocal(ctx, nil, cctx.Bool("drop-missing"))
|
||||
}
|
||||
|
||||
return xerrors.Errorf("either --all or --id must be specified")
|
||||
// As no --id or --all flag is set, we can assume the argument is a path.
|
||||
path := cctx.Args().First()
|
||||
metaFilePath := filepath.Join(path, "sectorstore.json")
|
||||
|
||||
var meta storiface.LocalStorageMeta
|
||||
metaFile, err := os.Open(metaFilePath)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("Failed to open meta file: %w", err)
|
||||
}
|
||||
defer metaFile.Close()
|
||||
|
||||
err = json.NewDecoder(metaFile).Decode(&meta)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("Failed to decode meta file: %w", err)
|
||||
}
|
||||
|
||||
id := meta.ID
|
||||
return minerApi.StorageRedeclareLocal(ctx, &id, cctx.Bool("drop-missing"))
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user