Skip to content

Commit

Permalink
Merge pull request ipfs/kubo#3321 from ipfs/feat/resolver-refactor
Browse files Browse the repository at this point in the history
make path resolver no longer require whole node for construction

This commit was moved from ipfs/kubo@17c629d
  • Loading branch information
whyrusleeping authored Oct 26, 2016
2 parents 3d100b7 + 6d2ca5e commit 8a0bc5e
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions gateway/core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
dag "github.com/ipfs/go-ipfs/merkledag"
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
path "github.com/ipfs/go-ipfs/path"
ft "github.com/ipfs/go-ipfs/unixfs"
uio "github.com/ipfs/go-ipfs/unixfs/io"

humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
Expand Down Expand Up @@ -153,7 +154,13 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
ipnsHostname = true
}

nd, err := core.Resolve(ctx, i.node, path.Path(urlPath))
p, err := path.ParsePath(urlPath)
if err != nil {
webError(w, "Invalid Path Error", err, http.StatusBadRequest)
return
}

nd, err := core.Resolve(ctx, i.node.Namesys, i.node.Resolver, p)
// If node is in offline mode the error code and message should be different
if err == core.ErrNoNamesys && !i.node.OnlineMode() {
w.WriteHeader(http.StatusServiceUnavailable)
Expand Down Expand Up @@ -240,8 +247,14 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
return
}

p, err := path.ParsePath(urlPath + "/index.html")
if err != nil {
internalWebError(w, err)
return
}

// return index page instead.
nd, err := core.Resolve(ctx, i.node, path.Path(urlPath+"/index.html"))
nd, err := core.Resolve(ctx, i.node.Namesys, i.node.Resolver, p)
if err != nil {
internalWebError(w, err)
return
Expand Down Expand Up @@ -356,7 +369,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {

var newnode node.Node
if rsegs[len(rsegs)-1] == "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" {
newnode = uio.NewEmptyDirectory()
newnode = ft.EmptyDirNode()
} else {
putNode, err := i.newDagFromReader(r.Body)
if err != nil {
Expand All @@ -372,7 +385,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
}

var newcid *cid.Cid
rnode, err := core.Resolve(ctx, i.node, rootPath)
rnode, err := core.Resolve(ctx, i.node.Namesys, i.node.Resolver, rootPath)
switch ev := err.(type) {
case path.ErrNoLink:
// ev.Node < node where resolve failed
Expand All @@ -397,7 +410,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
}

e := dagutils.NewDagEditor(pbnd, i.node.DAG)
err = e.InsertNodeAtPath(ctx, newPath, newnode, uio.NewEmptyDirectory)
err = e.InsertNodeAtPath(ctx, newPath, newnode, ft.EmptyDirNode)
if err != nil {
webError(w, "putHandler: InsertNodeAtPath failed", err, http.StatusInternalServerError)
return
Expand Down

0 comments on commit 8a0bc5e

Please sign in to comment.