Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/kubo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e0f4cb35e3ca^
Choose a base ref
...
head repository: ipfs/kubo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 75f267c688bc
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 23, 2016

  1. add helper command for publishing out of files api

    License: MIT
    Signed-off-by: Jeromy <jeromyj@gmail.com>
    whyrusleeping committed Jan 23, 2016

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    e0f4cb3 View commit details
  2. fix 'local' publish/resolve for testing

    License: MIT
    Signed-off-by: Jeromy <jeromyj@gmail.com>
    whyrusleeping committed Jan 23, 2016
    Copy the full SHA
    75f267c View commit details
Showing with 121 additions and 9 deletions.
  1. +103 −8 core/commands/files/files.go
  2. +3 −1 namesys/routing.go
  3. +15 −0 test/sharness/t0250-files-api.sh
111 changes: 103 additions & 8 deletions core/commands/files/files.go
Original file line number Diff line number Diff line change
@@ -13,7 +13,10 @@ import (
core "github.com/ipfs/go-ipfs/core"
dag "github.com/ipfs/go-ipfs/merkledag"
mfs "github.com/ipfs/go-ipfs/mfs"
namesys "github.com/ipfs/go-ipfs/namesys"
ci "github.com/ipfs/go-ipfs/p2p/crypto"
path "github.com/ipfs/go-ipfs/path"
offline "github.com/ipfs/go-ipfs/routing/offline"
ft "github.com/ipfs/go-ipfs/unixfs"

context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
@@ -33,14 +36,15 @@ Files is an API for manipulating ipfs objects as if they were a unix filesystem.
cmds.BoolOption("f", "flush", "flush target and ancestors after write (default: true)"),
},
Subcommands: map[string]*cmds.Command{
"read": FilesReadCmd,
"write": FilesWriteCmd,
"mv": FilesMvCmd,
"cp": FilesCpCmd,
"ls": FilesLsCmd,
"mkdir": FilesMkdirCmd,
"stat": FilesStatCmd,
"rm": FilesRmCmd,
"read": FilesReadCmd,
"write": FilesWriteCmd,
"mv": FilesMvCmd,
"cp": FilesCpCmd,
"ls": FilesLsCmd,
"mkdir": FilesMkdirCmd,
"stat": FilesStatCmd,
"rm": FilesRmCmd,
"publish": FilesPublishCmd,
},
}

@@ -613,6 +617,97 @@ Examples:
},
}

var FilesPublishCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "publish a path to a specified ipns entry",
ShortDescription: `
publish a file to ipns directly out of the files api
$ ipfs files publish /path/to/file
$ ipfs files publish --name=Qma3q5S8Eq1vCc1nSiPYNbSa1f2cH448sxdSnNR9nYoNoL /other/file
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("path", true, false, "path to entry to publish"),
},
Options: []cmds.Option{
cmds.StringOption("n", "name", "ipns name to publish to"),
},
Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

if !nd.OnlineMode() {
err := nd.SetupOfflineRouting()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
}

local, _, _ := req.Option("local").Bool()
var publisher namesys.Publisher
if local {
offroute := offline.NewOfflineRouter(nd.Repo.Datastore(), nd.PrivateKey)
publisher = namesys.NewRoutingPublisher(offroute, nd.Repo.Datastore())
} else {
publisher = nd.Namesys
}

fpath, err := checkPath(req.Arguments()[0])
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

topub, err := mfs.Lookup(nd.FilesRoot, fpath)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

dagnd, err := topub.GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

ndkey, err := dagnd.Key()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

name, found, err := req.Option("name").String()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

if !found {
name = "local"
}

var key ci.PrivKey
switch name {
case "local":
key = nd.PrivateKey
default:
res.SetError(fmt.Errorf("keys other than your nodes ID key are not currently supported."), cmds.ErrNormal)
return
}

err = publisher.Publish(req.Context(), key, path.FromKey(ndkey))
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
},
}

var FilesRmCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "remove a file",
4 changes: 3 additions & 1 deletion namesys/routing.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package namesys

import (
"fmt"
"strings"
"time"

proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
@@ -117,14 +118,15 @@ func (r *routingResolver) ResolveN(ctx context.Context, name string, depth int)
// resolve SFS-like names.
func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) {
log.Debugf("RoutingResolve: '%s'", name)
name = strings.TrimLeft(name, "/ipns/")

cached, ok := r.cacheGet(name)
if ok {
return cached, nil
}

hash, err := mh.FromB58String(name)
if err != nil {
// name should be a multihash. if it isn't, error out here.
log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
return "", err
}
15 changes: 15 additions & 0 deletions test/sharness/t0250-files-api.sh
Original file line number Diff line number Diff line change
@@ -345,6 +345,21 @@ test_files_api() {
verify_dir_contents /cats/this
'

# test publish
test_expect_success "ipfs name publish works" '
ipfs files publish --local /cats/walrus
'

test_expect_success "ipns record looks good" '
ipfs name resolve --local > record_out
'

test_expect_success "record is correct" '
echo "/ipfs/QmNzVQoBR7wQjSNXFrcJHZ29PMsEDfF6iZB1QEhKD4uZpV" > record_exp &&
test_cmp record_exp record_out
'

# cleanup
test_expect_success "cleanup, remove 'cats'" '
ipfs files rm -r /cats
'