Commit b165db47 authored by tavit ohanian's avatar tavit ohanian

Merge branch 'port-2021-05-11'

parents 4e52143e 496386f7
......@@ -13,6 +13,7 @@ import (
ld "gitlab.dms3.io/dms3/go-ld-format"
logging "gitlab.dms3.io/dms3/go-log"
dag "gitlab.dms3.io/dms3/go-merkledag"
loggables "gitlab.dms3.io/p2p/go-p2p-loggables"
)
var log = logging.Logger("pathresolv")
......@@ -150,19 +151,27 @@ func ResolveSingle(ctx context.Context, ds ld.NodeGetter, nd ld.Node, names []st
// It uses the first path component as a hash (key) of the first node, then
// resolves all other components walking the links, with ResolveLinks.
func (r *Resolver) ResolvePathComponents(ctx context.Context, fpath path.Path) ([]ld.Node, error) {
evt := log.EventBegin(ctx, "resolvePathComponents", logging.LoggableMap{"fpath": fpath})
defer evt.Done()
m := loggables.DeferredMap{}
m["fpath"] = fpath
log.Infow("resolvePathComponents", m["fpath"])
// evt := log.EventBegin(ctx, "resolvePathComponents", logging.LoggableMap{"fpath": fpath})
// defer evt.Done()
h, parts, err := path.SplitAbsPath(fpath)
if err != nil {
evt.Append(logging.LoggableMap{"error": err.Error()})
m["error"] = err.Error()
log.Infow("error", m["error"])
// evt.Append(logging.LoggableMap{"error": err.Error()})
return nil, err
}
log.Debug("resolve dag get")
nd, err := r.DAG.Get(ctx, h)
if err != nil {
evt.Append(logging.LoggableMap{"error": err.Error()})
m["error"] = err.Error()
log.Infow("error", m["error"])
// evt.Append(logging.LoggableMap{"error": err.Error()})
return nil, err
}
......@@ -177,9 +186,12 @@ func (r *Resolver) ResolvePathComponents(ctx context.Context, fpath path.Path) (
// ResolveLinks(nd, []string{"foo", "bar", "baz"})
// would retrieve "baz" in ("bar" in ("foo" in nd.Links).Links).Links
func (r *Resolver) ResolveLinks(ctx context.Context, ndd ld.Node, names []string) ([]ld.Node, error) {
m := loggables.DeferredMap{}
m["names"] = names
evt := log.EventBegin(ctx, "resolveLinks", logging.LoggableMap{"names": names})
defer evt.Done()
log.Infow("resolveLinks", m["names"])
// evt := log.EventBegin(ctx, "resolveLinks", logging.LoggableMap{"names": names})
// defer evt.Done()
result := make([]ld.Node, 0, len(names)+1)
result = append(result, ndd)
nd := ndd // dup arg workaround
......@@ -192,16 +204,22 @@ func (r *Resolver) ResolveLinks(ctx context.Context, ndd ld.Node, names []string
lnk, rest, err := r.ResolveOnce(ctx, r.DAG, nd, names)
if err == dag.ErrLinkNotFound {
evt.Append(logging.LoggableMap{"error": err.Error()})
m["error"] = err.Error()
log.Infow("error", m["error"])
// evt.Append(logging.LoggableMap{"error": err.Error()})
return result, ErrNoLink{Name: names[0], Node: nd.Cid()}
} else if err != nil {
evt.Append(logging.LoggableMap{"error": err.Error()})
m["error"] = err.Error()
log.Infow("error", m["error"])
// evt.Append(logging.LoggableMap{"error": err.Error()})
return result, err
}
nextnode, err := lnk.GetNode(ctx, r.DAG)
if err != nil {
evt.Append(logging.LoggableMap{"error": err.Error()})
m["error"] = err.Error()
log.Infow("error", m["error"])
// evt.Append(logging.LoggableMap{"error": err.Error()})
return result, err
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment