Skip to content

Commit

Permalink
WIP fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Voker57 committed Jan 7, 2019
1 parent ada15d0 commit 2ea3600
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 68 deletions.
9 changes: 2 additions & 7 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/ipfs/go-ipfs/core/commands/cmdenv"
"github.com/ipfs/go-ipfs/core/coredag"
"github.com/ipfs/go-ipfs/pin"

cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
Expand Down Expand Up @@ -72,7 +71,7 @@ into an object of the specified format.
ienc, _ := req.Options["input-enc"].(string)
format, _ := req.Options["format"].(string)
hash, _ := req.Options["hash"].(string)
pinpath, _, err := req.Options["pin"].(string)
pinpath, _ := req.Options["pin"].(string)

// mhType tells inputParser which hash should be used. MaxUint64 means 'use
// default hash' (sha256 for cbor, sha1 for git..)
Expand All @@ -89,10 +88,6 @@ into an object of the specified format.
cids := cid.NewSet()
b := ipld.NewBatch(req.Context, nd.DAG)

if dopin {
defer nd.Blockstore.PinLock().Unlock()
}

it := req.Files.Entries()
for it.Next() {
file := files.FileFromEntry(it)
Expand Down Expand Up @@ -130,7 +125,7 @@ into an object of the specified format.

if pinpath != "" {
err := cids.ForEach(func(c cid.Cid) error {
return n.Pinning.AddPin(pinpath, c, true)
return nd.Pinning.AddPin(pinpath, c, true)
})

if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,12 @@ And then run:
return err
}

pinpath, _, err := req.Options["pinpath"].(string)
pinpath, _ := req.Options["pinpath"].(string)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
return err
}

pin, _, err := req.Option("pin").Bool()
pin, _ := req.Options["pin"].(bool)
if err != nil {
return err
}
Expand Down
47 changes: 14 additions & 33 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,16 @@ var addPinCmd = &cmds.Command{
}

// set direct flag
direct, _, err := req.Option("direct").Bool()
direct, _ := req.Options["direct"].(bool)
showProgress, _ := req.Options[pinProgressOptionName].(bool)

if err := req.ParseBodyArgs(); err != nil {
if err = req.ParseBodyArgs(); err != nil {
return err
}

pinPath, _ := req.Options["pinpath"].(string)

args := req.Arguments()

pinPath, _, err := req.Option("pinpath").String()
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}

toPin := args
toPin := req.Arguments

if !showProgress {
added, err := corerepo.Pin(n.Pinning, api, req.Context, pinPath, toPin, !direct)
Expand Down Expand Up @@ -147,7 +140,7 @@ var addPinCmd = &cmds.Command{
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *AddPinOutput) error {
direct, found := req.Options["direct"].(bool)

var pintype string
if !direct || !found {
pintype = "recursively"
Expand Down Expand Up @@ -219,12 +212,8 @@ collected if needed. By default, removes recursive pins.
}

// set recursive flag
direct, _, err := req.Option("direct").Bool()
direct, _ := req.Options["direct"].(bool)
recursive := !direct
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}

removed, err := corerepo.Unpin(n.Pinning, api, req.Context, req.Arguments, recursive)
if err != nil {
Expand Down Expand Up @@ -307,15 +296,9 @@ Example:
return err
}

api, err := cmdenv.GetApi(env, req)
if err != nil {
return err
}

typeStr, _ := req.Options[pinTypeOptionName].(string)

recursive, _, := req.Options["recursive"].(bool)


recursive, _ := req.Options["recursive"].(bool)

switch typeStr {
case "all", "direct", "indirect", "recursive":
Expand All @@ -324,19 +307,18 @@ Example:
return err
}

args := req.Arguments()
prefix := ""
if len(req.Arguments) == 1 {
prefix = req.Arguments[0]
}

keys, err := pinLsAll(req.Context(), typeStr, prefix, recursive, n)
keys, err := pinLsAll(req.Context, typeStr, prefix, recursive, n)

if err != nil {
return err
}

return cmds.EmitOnce(res, &RefKeyList{Keys: keys})
return cmds.EmitOnce(res, keys)
},
Type: RefKeyList{},
Encoders: cmds.EncoderMap{
Expand Down Expand Up @@ -380,21 +362,20 @@ new pin and removing the old one.
api, err := cmdenv.GetApi(env, req)
if err != nil {
return err
from := req.Arguments[0]
}

from := req.Arguments[0]

err = api.Pin().Update(req.Context(), from, to)
to, err := iface.ParsePath(req.Arguments[1])
if err != nil {
return err
}

to, err := iface.ParsePath(req.Arguments[1])
err = api.Pin().Update(req.Context, from, to)
if err != nil {
return err
}



return cmds.EmitOnce(res, &PinOutput{Pins: []string{from, to.String()}})
},
Encoders: cmds.EncoderMap{
Expand Down
12 changes: 4 additions & 8 deletions core/commands/urlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
filestore "github.com/ipfs/go-ipfs/filestore"
pin "github.com/ipfs/go-ipfs/pin"

chunk "gx/ipfs/QmR4QQVkBZsZENRjYFVi8dEtPL3daZRNKk24m4r6WKJHNm/go-ipfs-chunker"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
Expand Down Expand Up @@ -48,6 +47,7 @@ time.
Options: []cmdkit.Option{
cmdkit.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
cmdkit.StringOption("pinpath", "P", "Pin object under this path.").WithDefault("added/"),
},
Arguments: []cmdkit.Argument{
cmdkit.StringArg("url", true, false, "URL to add to IPFS"),
Expand Down Expand Up @@ -90,11 +90,6 @@ time.
return fmt.Errorf("expected code 200, got: %d", hres.StatusCode)
}

if dopin {
// Take the pinlock
defer n.Blockstore.PinLock().Unlock()
}

chk := chunk.NewSizeSplitter(hres.Body, chunk.DefaultBlockSize)
prefix := cid.NewPrefixV1(cid.DagProtobuf, mh.SHA2_256)
dbp := &ihelper.DagBuilderParams{
Expand All @@ -116,10 +111,11 @@ time.
return err
}

pinPath, _ := req.Options["pinpath"].(string)

c := root.Cid()
if dopin {
n.Pinning.PinWithMode(c, pin.Recursive)
if err := n.Pinning.Flush(); err != nil {
if err := n.Pinning.AddPin(pinPath, c, true); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/interface/tests/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (tp *provider) TestAddPinned(t *testing.T) {
t.Error(err)
}

pins, err := api.Pin().Ls(ctx)
pins, err := api.Pin().Ls(ctx, "", options.Pin.RecursiveList(true))
if len(pins) != 1 {
t.Fatalf("expected 1 pin, got %d", len(pins))
}
Expand Down
6 changes: 1 addition & 5 deletions core/coreapi/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,13 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj
return nil, err
}

if options.Pin {
defer api.blockstore.PinLock().Unlock()
}

err = api.dag.Add(ctx, dagnode)
if err != nil {
return nil, err
}

if options.Pin {
err = api.pinning.AddPin(options.PinPath, dagnode.Cid(), pin.Recursive)
err = api.pinning.AddPin(options.PinPath, dagnode.Cid(), true)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions core/coreapi/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (api *PinAPI) Verify(ctx context.Context) (<-chan coreiface.PinStatus, erro

var checkPin func(root cid.Cid, pinPath string) *pinStatus
checkPin = func(root cid.Cid, pinPath string) *pinStatus {
key := root.String()
if status, ok := visited[key]; ok
status, ok := visited[root]
if ok {
return status
}

Expand All @@ -129,7 +129,7 @@ func (api *PinAPI) Verify(ctx context.Context) (<-chan coreiface.PinStatus, erro
return status
}

status := &pinStatus{ok: true}
status = &pinStatus{ok: true}
for _, lnk := range links {
res := checkPin(lnk.Cid, pinPath)
if !res.ok {
Expand Down
10 changes: 5 additions & 5 deletions core/corerepo/pinning.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package corerepo
import (
"context"
"fmt"
"github.com/ipfs/go-ipfs/pin"

"github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/pin"

"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
)

func Pin(n *core.IpfsNode, api iface.CoreAPI, ctx context.Context, pinpath string, paths []string, recursive bool) ([]cid.Cid, error) {
func Pin(pinning pin.Pinner, api iface.CoreAPI, ctx context.Context, pinpath string, paths []string, recursive bool) ([]cid.Cid, error) {
out := make([]cid.Cid, len(paths))

for i, fpath := range paths {
Expand All @@ -46,7 +46,7 @@ func Pin(n *core.IpfsNode, api iface.CoreAPI, ctx context.Context, pinpath strin
return out, nil
}

func UnpinPaths(n *core.IpfsNode, api iface.CoreAPI, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
func UnpinPaths(pinning pin.Pinner, api iface.CoreAPI, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
unpinned := make([]cid.Cid, len(paths))

for i, p := range paths {
Expand All @@ -70,11 +70,11 @@ func UnpinPaths(n *core.IpfsNode, api iface.CoreAPI, ctx context.Context, paths
return unpinned, nil
}

func Unpin(n *core.IpfsNode, api iface.CoreAPI, ctx context.Context, pinPaths []string, recursive bool) ([]string, error) {
func Unpin(pinning pin.Pinner, api iface.CoreAPI, ctx context.Context, pinPaths []string, recursive bool) ([]string, error) {
unpinned := make([]string, len(pinPaths))

for i, p := range pinPaths {
err := n.Pinning.Unpin(p, recursive)
err := pinning.Unpin(p, recursive)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions test/sharness/t0085-pins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ test_pins() {

test_expect_success "test pin ls hash" '
echo $HASH_B | test_must_fail grep /ipfs && # just to be sure
ipfs pin ls $HASH_B > ls_hash_out &&
echo "$HASH_B recursive" > ls_hash_exp &&
ipfs pin ls default/$HASH_B > ls_hash_out &&
echo "$HASH_B recursive default/$HASH_B" > ls_hash_exp &&
test_cmp ls_hash_exp ls_hash_out
'

Expand Down

1 comment on commit 2ea3600

@GitCop
Copy link

@GitCop GitCop commented on 2ea3600 Jan 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

We ask for a few features in the commit message for Open Source licensing hygiene and commit message clarity.
git commit --amend can often help you quickly improve the commit message.
Guidelines and a script are available to help in the long run.
Your feedback on GitCop is welcome on this issue.


This message was auto-generated by https://gitcop.com

Please sign in to comment.