client: API/Command to drop imports
This commit is contained in:
parent
7175b1dd65
commit
18fc3337ff
@ -190,7 +190,9 @@ type FullNode interface {
|
|||||||
// retrieval markets as a client
|
// retrieval markets as a client
|
||||||
|
|
||||||
// ClientImport imports file under the specified path into filestore.
|
// ClientImport imports file under the specified path into filestore.
|
||||||
ClientImport(ctx context.Context, ref FileRef) (cid.Cid, error)
|
ClientImport(ctx context.Context, ref FileRef) (*ImportRes, error)
|
||||||
|
// ClientRemoveImport removes file import
|
||||||
|
ClientRemoveImport(ctx context.Context, importID int64) error
|
||||||
// ClientStartDeal proposes a deal with a miner.
|
// ClientStartDeal proposes a deal with a miner.
|
||||||
ClientStartDeal(ctx context.Context, params *StartDealParams) (*cid.Cid, error)
|
ClientStartDeal(ctx context.Context, params *StartDealParams) (*cid.Cid, error)
|
||||||
// ClientGetDealInfo returns the latest information about a given deal.
|
// ClientGetDealInfo returns the latest information about a given deal.
|
||||||
@ -354,6 +356,11 @@ type MinerSectors struct {
|
|||||||
Pset uint64
|
Pset uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ImportRes struct {
|
||||||
|
Root cid.Cid
|
||||||
|
ImportID int64
|
||||||
|
}
|
||||||
|
|
||||||
type Import struct {
|
type Import struct {
|
||||||
Key int64
|
Key int64
|
||||||
Err string
|
Err string
|
||||||
|
@ -109,8 +109,9 @@ type FullNodeStruct struct {
|
|||||||
WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"`
|
WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"`
|
||||||
WalletDelete func(context.Context, address.Address) error `perm:"write"`
|
WalletDelete func(context.Context, address.Address) error `perm:"write"`
|
||||||
|
|
||||||
ClientImport func(ctx context.Context, ref api.FileRef) (cid.Cid, error) `perm:"admin"`
|
ClientImport func(ctx context.Context, ref api.FileRef) (*api.ImportRes, error) `perm:"admin"`
|
||||||
ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"`
|
ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"`
|
||||||
|
ClientRemoveImport func(ctx context.Context, importID int64) error `perm:"admin"`
|
||||||
ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"`
|
ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"`
|
||||||
ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"`
|
ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"`
|
||||||
ClientMinerQueryOffer func(ctx context.Context, root cid.Cid, miner address.Address) (api.QueryOffer, error) `perm:"read"`
|
ClientMinerQueryOffer func(ctx context.Context, root cid.Cid, miner address.Address) (api.QueryOffer, error) `perm:"read"`
|
||||||
@ -340,7 +341,11 @@ func (c *FullNodeStruct) ClientListImports(ctx context.Context) ([]api.Import, e
|
|||||||
return c.Internal.ClientListImports(ctx)
|
return c.Internal.ClientListImports(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) ClientImport(ctx context.Context, ref api.FileRef) (cid.Cid, error) {
|
func (c *FullNodeStruct) ClientRemoveImport(ctx context.Context, importID int64) error {
|
||||||
|
return c.Internal.ClientRemoveImport(ctx, importID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) ClientImport(ctx context.Context, ref api.FileRef) (*api.ImportRes, error) {
|
||||||
return c.Internal.ClientImport(ctx, ref)
|
return c.Internal.ClientImport(ctx, ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ var clientCmd = &cli.Command{
|
|||||||
Usage: "Make deals, store data, retrieve data",
|
Usage: "Make deals, store data, retrieve data",
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
clientImportCmd,
|
clientImportCmd,
|
||||||
|
clientDropCmd,
|
||||||
clientCommPCmd,
|
clientCommPCmd,
|
||||||
clientLocalCmd,
|
clientLocalCmd,
|
||||||
clientDealCmd,
|
clientDealCmd,
|
||||||
@ -75,6 +77,11 @@ var clientImportCmd = &cli.Command{
|
|||||||
Name: "car",
|
Name: "car",
|
||||||
Usage: "import from a car file instead of a regular file",
|
Usage: "import from a car file instead of a regular file",
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "quiet",
|
||||||
|
Aliases: []string{"q"},
|
||||||
|
Usage: "Output root CID only",
|
||||||
|
},
|
||||||
&CidBaseFlag,
|
&CidBaseFlag,
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
@ -103,7 +110,46 @@ var clientImportCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(encoder.Encode(c))
|
if !cctx.Bool("quiet") {
|
||||||
|
fmt.Printf("Import %d, Root ", c.ImportID)
|
||||||
|
}
|
||||||
|
fmt.Println(encoder.Encode(c.Root))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var clientDropCmd = &cli.Command{
|
||||||
|
Name: "drop",
|
||||||
|
Usage: "Remove import",
|
||||||
|
ArgsUsage: "[import ID...]",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
if !cctx.Args().Present() {
|
||||||
|
return xerrors.Errorf("no imports specified")
|
||||||
|
}
|
||||||
|
|
||||||
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
var ids []int64
|
||||||
|
for i, s := range cctx.Args().Slice() {
|
||||||
|
id, err := strconv.ParseInt(s, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("parsing %d-th import ID: %w", i, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, id := range ids {
|
||||||
|
if err := api.ClientRemoveImport(ctx, id); err != nil {
|
||||||
|
return xerrors.Errorf("removing import %d: %w", id, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -203,6 +249,10 @@ var clientLocalCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(list, func(i, j int) bool {
|
||||||
|
return list[i].Key < list[j].Key
|
||||||
|
})
|
||||||
|
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
cidStr := "<nil>"
|
cidStr := "<nil>"
|
||||||
if v.Root != nil {
|
if v.Root != nil {
|
||||||
|
@ -262,29 +262,36 @@ func (a *API) makeRetrievalQuery(ctx context.Context, rp rm.RetrievalPeer, paylo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) ClientImport(ctx context.Context, ref api.FileRef) (cid.Cid, error) {
|
func (a *API) ClientImport(ctx context.Context, ref api.FileRef) (*api.ImportRes, error) {
|
||||||
id, st, err := a.imgr().NewStore()
|
id, st, err := a.imgr().NewStore()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := a.imgr().AddLabel(id, importmgr.LSource, "import"); err != nil {
|
if err := a.imgr().AddLabel(id, importmgr.LSource, "import"); err != nil {
|
||||||
return cid.Undef, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.imgr().AddLabel(id, importmgr.LFileName, ref.Path); err != nil {
|
if err := a.imgr().AddLabel(id, importmgr.LFileName, ref.Path); err != nil {
|
||||||
return cid.Undef, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nd, err := a.clientImport(ctx, ref, st)
|
nd, err := a.clientImport(ctx, ref, st)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.imgr().AddLabel(id, importmgr.LRootCid, nd.String()); err != nil {
|
if err := a.imgr().AddLabel(id, importmgr.LRootCid, nd.String()); err != nil {
|
||||||
return cid.Undef, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nd, nil
|
return &api.ImportRes{
|
||||||
|
Root: nd,
|
||||||
|
ImportID: id,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) ClientRemoveImport(ctx context.Context, importID int64) error {
|
||||||
|
return a.imgr().Remove(importID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) ClientImportLocal(ctx context.Context, f io.Reader) (cid.Cid, error) {
|
func (a *API) ClientImportLocal(ctx context.Context, f io.Reader) (cid.Cid, error) {
|
||||||
|
@ -226,6 +226,8 @@ func (fsr *fsLockedRepo) DeleteDatastore(ns string) error {
|
|||||||
return xerrors.Errorf("no multi-datastore with at index (namespace %s)", ns)
|
return xerrors.Errorf("no multi-datastore with at index (namespace %s)", ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete(mds, idx)
|
||||||
|
|
||||||
if err := ds.Close(); err != nil {
|
if err := ds.Close(); err != nil {
|
||||||
return xerrors.Errorf("closing datastore: %w", err)
|
return xerrors.Errorf("closing datastore: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -99,5 +99,14 @@ func (m *Mgr) Info(id int64) (*StoreMeta, error) {
|
|||||||
return &sm, nil
|
return &sm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// m.Info
|
func (m *Mgr) Remove(id int64) error {
|
||||||
// m.Delete
|
if err := m.mds.Delete(id); err != nil {
|
||||||
|
return xerrors.Errorf("removing import: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := m.ds.Delete(datastore.NewKey(fmt.Sprintf("%d", id))); err != nil {
|
||||||
|
return xerrors.Errorf("removing import metadata: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user