Skip to content

Commit 2ea3600

Browse files
committed
WIP fixes
1 parent ada15d0 commit 2ea3600

File tree

9 files changed

+35
-68
lines changed

9 files changed

+35
-68
lines changed

core/commands/dag/dag.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
99
"github.com/ipfs/go-ipfs/core/coredag"
10-
"github.com/ipfs/go-ipfs/pin"
1110

1211
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
1312
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
@@ -72,7 +71,7 @@ into an object of the specified format.
7271
ienc, _ := req.Options["input-enc"].(string)
7372
format, _ := req.Options["format"].(string)
7473
hash, _ := req.Options["hash"].(string)
75-
pinpath, _, err := req.Options["pin"].(string)
74+
pinpath, _ := req.Options["pin"].(string)
7675

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

92-
if dopin {
93-
defer nd.Blockstore.PinLock().Unlock()
94-
}
95-
9691
it := req.Files.Entries()
9792
for it.Next() {
9893
file := files.FileFromEntry(it)
@@ -130,7 +125,7 @@ into an object of the specified format.
130125

131126
if pinpath != "" {
132127
err := cids.ForEach(func(c cid.Cid) error {
133-
return n.Pinning.AddPin(pinpath, c, true)
128+
return nd.Pinning.AddPin(pinpath, c, true)
134129
})
135130

136131
if err != nil {

core/commands/object/object.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,12 @@ And then run:
407407
return err
408408
}
409409

410-
pinpath, _, err := req.Options["pinpath"].(string)
410+
pinpath, _ := req.Options["pinpath"].(string)
411411
if err != nil {
412-
res.SetError(err, cmdkit.ErrNormal)
413-
return
412+
return err
414413
}
415414

416-
pin, _, err := req.Option("pin").Bool()
415+
pin, _ := req.Options["pin"].(bool)
417416
if err != nil {
418417
return err
419418
}

core/commands/pin.go

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,16 @@ var addPinCmd = &cmds.Command{
7878
}
7979

8080
// set direct flag
81-
direct, _, err := req.Option("direct").Bool()
81+
direct, _ := req.Options["direct"].(bool)
8282
showProgress, _ := req.Options[pinProgressOptionName].(bool)
8383

84-
if err := req.ParseBodyArgs(); err != nil {
84+
if err = req.ParseBodyArgs(); err != nil {
8585
return err
8686
}
8787

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

89-
args := req.Arguments()
90-
91-
pinPath, _, err := req.Option("pinpath").String()
92-
if err != nil {
93-
res.SetError(err, cmdkit.ErrNormal)
94-
return
95-
}
96-
97-
toPin := args
90+
toPin := req.Arguments
9891

9992
if !showProgress {
10093
added, err := corerepo.Pin(n.Pinning, api, req.Context, pinPath, toPin, !direct)
@@ -147,7 +140,7 @@ var addPinCmd = &cmds.Command{
147140
Encoders: cmds.EncoderMap{
148141
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *AddPinOutput) error {
149142
direct, found := req.Options["direct"].(bool)
150-
143+
151144
var pintype string
152145
if !direct || !found {
153146
pintype = "recursively"
@@ -219,12 +212,8 @@ collected if needed. By default, removes recursive pins.
219212
}
220213

221214
// set recursive flag
222-
direct, _, err := req.Option("direct").Bool()
215+
direct, _ := req.Options["direct"].(bool)
223216
recursive := !direct
224-
if err != nil {
225-
res.SetError(err, cmdkit.ErrNormal)
226-
return
227-
}
228217

229218
removed, err := corerepo.Unpin(n.Pinning, api, req.Context, req.Arguments, recursive)
230219
if err != nil {
@@ -307,15 +296,9 @@ Example:
307296
return err
308297
}
309298

310-
api, err := cmdenv.GetApi(env, req)
311-
if err != nil {
312-
return err
313-
}
314-
315299
typeStr, _ := req.Options[pinTypeOptionName].(string)
316-
317-
recursive, _, := req.Options["recursive"].(bool)
318-
300+
301+
recursive, _ := req.Options["recursive"].(bool)
319302

320303
switch typeStr {
321304
case "all", "direct", "indirect", "recursive":
@@ -324,19 +307,18 @@ Example:
324307
return err
325308
}
326309

327-
args := req.Arguments()
328310
prefix := ""
329311
if len(req.Arguments) == 1 {
330312
prefix = req.Arguments[0]
331313
}
332314

333-
keys, err := pinLsAll(req.Context(), typeStr, prefix, recursive, n)
315+
keys, err := pinLsAll(req.Context, typeStr, prefix, recursive, n)
334316

335317
if err != nil {
336318
return err
337319
}
338320

339-
return cmds.EmitOnce(res, &RefKeyList{Keys: keys})
321+
return cmds.EmitOnce(res, keys)
340322
},
341323
Type: RefKeyList{},
342324
Encoders: cmds.EncoderMap{
@@ -380,21 +362,20 @@ new pin and removing the old one.
380362
api, err := cmdenv.GetApi(env, req)
381363
if err != nil {
382364
return err
383-
from := req.Arguments[0]
365+
}
384366

367+
from := req.Arguments[0]
385368

386-
err = api.Pin().Update(req.Context(), from, to)
369+
to, err := iface.ParsePath(req.Arguments[1])
387370
if err != nil {
388371
return err
389372
}
390373

391-
to, err := iface.ParsePath(req.Arguments[1])
374+
err = api.Pin().Update(req.Context, from, to)
392375
if err != nil {
393376
return err
394377
}
395378

396-
397-
398379
return cmds.EmitOnce(res, &PinOutput{Pins: []string{from, to.String()}})
399380
},
400381
Encoders: cmds.EncoderMap{

core/commands/urlstore.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
99
filestore "github.com/ipfs/go-ipfs/filestore"
10-
pin "github.com/ipfs/go-ipfs/pin"
1110

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

93-
if dopin {
94-
// Take the pinlock
95-
defer n.Blockstore.PinLock().Unlock()
96-
}
97-
9893
chk := chunk.NewSizeSplitter(hres.Body, chunk.DefaultBlockSize)
9994
prefix := cid.NewPrefixV1(cid.DagProtobuf, mh.SHA2_256)
10095
dbp := &ihelper.DagBuilderParams{
@@ -116,10 +111,11 @@ time.
116111
return err
117112
}
118113

114+
pinPath, _ := req.Options["pinpath"].(string)
115+
119116
c := root.Cid()
120117
if dopin {
121-
n.Pinning.PinWithMode(c, pin.Recursive)
122-
if err := n.Pinning.Flush(); err != nil {
118+
if err := n.Pinning.AddPin(pinPath, c, true); err != nil {
123119
return err
124120
}
125121
}

core/coreapi/interface/tests/unixfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ func (tp *provider) TestAddPinned(t *testing.T) {
549549
t.Error(err)
550550
}
551551

552-
pins, err := api.Pin().Ls(ctx)
552+
pins, err := api.Pin().Ls(ctx, "", options.Pin.RecursiveList(true))
553553
if len(pins) != 1 {
554554
t.Fatalf("expected 1 pin, got %d", len(pins))
555555
}

core/coreapi/object.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,13 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj
116116
return nil, err
117117
}
118118

119-
if options.Pin {
120-
defer api.blockstore.PinLock().Unlock()
121-
}
122-
123119
err = api.dag.Add(ctx, dagnode)
124120
if err != nil {
125121
return nil, err
126122
}
127123

128124
if options.Pin {
129-
err = api.pinning.AddPin(options.PinPath, dagnode.Cid(), pin.Recursive)
125+
err = api.pinning.AddPin(options.PinPath, dagnode.Cid(), true)
130126
if err != nil {
131127
return nil, err
132128
}

core/coreapi/pin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func (api *PinAPI) Verify(ctx context.Context) (<-chan coreiface.PinStatus, erro
116116

117117
var checkPin func(root cid.Cid, pinPath string) *pinStatus
118118
checkPin = func(root cid.Cid, pinPath string) *pinStatus {
119-
key := root.String()
120-
if status, ok := visited[key]; ok
119+
status, ok := visited[root]
120+
if ok {
121121
return status
122122
}
123123

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

132-
status := &pinStatus{ok: true}
132+
status = &pinStatus{ok: true}
133133
for _, lnk := range links {
134134
res := checkPin(lnk.Cid, pinPath)
135135
if !res.ok {

core/corerepo/pinning.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ package corerepo
1616
import (
1717
"context"
1818
"fmt"
19-
"github.com/ipfs/go-ipfs/pin"
2019

2120
"github.com/ipfs/go-ipfs/core/coreapi/interface"
21+
"github.com/ipfs/go-ipfs/pin"
2222

2323
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
2424
)
2525

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

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

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

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

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

7676
for i, p := range pinPaths {
77-
err := n.Pinning.Unpin(p, recursive)
77+
err := pinning.Unpin(p, recursive)
7878
if err != nil {
7979
return nil, err
8080
}

test/sharness/t0085-pins.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ test_pins() {
4747

4848
test_expect_success "test pin ls hash" '
4949
echo $HASH_B | test_must_fail grep /ipfs && # just to be sure
50-
ipfs pin ls $HASH_B > ls_hash_out &&
51-
echo "$HASH_B recursive" > ls_hash_exp &&
50+
ipfs pin ls default/$HASH_B > ls_hash_out &&
51+
echo "$HASH_B recursive default/$HASH_B" > ls_hash_exp &&
5252
test_cmp ls_hash_exp ls_hash_out
5353
'
5454

0 commit comments

Comments
 (0)