client: Fix import labeling

This commit is contained in:
Łukasz Magiera 2020-07-07 11:38:09 +02:00
parent f59eb94d92
commit 24ed43d541
2 changed files with 13 additions and 6 deletions

View File

@ -264,18 +264,25 @@ 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) (cid.Cid, error) {
id, st, err := a.imgr().NewStore() id, st, err := a.imgr().NewStore()
if err != nil { if err != nil {
return cid.Cid{}, err return cid.Undef, err
} }
if err := a.imgr().AddLabel(id, "source", "import"); err != nil { if err := a.imgr().AddLabel(id, importmgr.LSource, "import"); err != nil {
return cid.Cid{}, err return cid.Undef, err
}
if err := a.imgr().AddLabel(id, importmgr.LFileName, ref.Path); err != nil {
return cid.Undef, 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 cid.Undef, err
} }
if err := a.imgr().AddLabel(id, importmgr.LRootCid, nd.String()); err != nil {
return cid.Undef, err
}
return nd, nil return nd, nil
} }

View File

@ -33,7 +33,7 @@ func New(mds *MultiStore, ds datastore.Batching) *Mgr {
mds: mds, mds: mds,
}, },
ds: namespace.Wrap(ds, datastore.NewKey("/stores")), ds: datastore.NewLogDatastore(namespace.Wrap(ds, datastore.NewKey("/stores")), "storess"),
} }
} }
@ -72,7 +72,7 @@ func (m *Mgr) AddLabel(id int64, key, value string) error { // source, file path
sm.Labels[key] = value sm.Labels[key] = value
meta, err = json.Marshal(&StoreMeta{}) meta, err = json.Marshal(&sm)
if err != nil { if err != nil {
return xerrors.Errorf("marshaling store meta: %w", err) return xerrors.Errorf("marshaling store meta: %w", err)
} }