Skip to content

Commit

Permalink
putHandler: applied review comments from @whyrusleeping
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henry <[email protected]>
  • Loading branch information
cryptix committed Oct 23, 2015
1 parent 7a231b3 commit eb3d2aa
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ func (i *gatewayHandler) postHandler(w http.ResponseWriter, r *http.Request) {
}

func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
rootPath := path.Path(r.URL.Path)
if err := rootPath.IsValid(); err != nil {
rootPath, err := path.ParsePath(r.URL.Path)
if err != nil {
webError(w, "putHandler: ipfs path not valid", err, http.StatusBadRequest)
return
}
Expand All @@ -292,12 +292,12 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
if rsegs[len(rsegs)-1] == "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" {
newnode = uio.NewEmptyDirectory()
} else {
var err error
newnode, err = i.newDagFromReader(r.Body)
putNode, err := i.newDagFromReader(r.Body)
if err != nil {
webError(w, "putHandler: Could not create DAG from request", err, http.StatusInternalServerError)
return
}
nwnode = putNode
}

var newPath string
Expand All @@ -318,13 +318,10 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
return
}

createfunc := func() *dag.Node {
return uio.NewEmptyDirectory()
}
newPath := filepath.Join(rsegs[2:]...)

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

0 comments on commit eb3d2aa

Please sign in to comment.