Skip to content

Commit 23a7aa0

Browse files
committed
Remove unpin option from pin.Update
License: MIT Signed-off-by: Iaroslav Gridin <[email protected]>
1 parent 6096f04 commit 23a7aa0

File tree

5 files changed

+10
-36
lines changed

5 files changed

+10
-36
lines changed

core/commands/pin.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,26 +372,18 @@ new pin and removing the old one.
372372
},
373373

374374
Arguments: []cmdkit.Argument{
375-
cmdkit.StringArg("from-path", true, false, "Path to old object."),
375+
cmdkit.StringArg("pinpath", true, false, "Pin path of the old object."),
376376
cmdkit.StringArg("to-path", true, false, "Path to new object to be pinned."),
377377
},
378-
Options: []cmdkit.Option{
379-
cmdkit.BoolOption("unpin", "Remove the old pin.").WithDefault(true),
380-
},
381-
Type: PinOutput{},
378+
Options: []cmdkit.Option{},
379+
Type: PinOutput{},
382380
Run: func(req cmds.Request, res cmds.Response) {
383381
n, err := req.InvocContext().GetNode()
384382
if err != nil {
385383
res.SetError(err, cmdkit.ErrNormal)
386384
return
387385
}
388386

389-
unpin, _, err := req.Option("unpin").Bool()
390-
if err != nil {
391-
res.SetError(err, cmdkit.ErrNormal)
392-
return
393-
}
394-
395387
from := req.Arguments()[0]
396388

397389
to, err := path.ParsePath(req.Arguments()[1])
@@ -411,7 +403,7 @@ new pin and removing the old one.
411403
return
412404
}
413405

414-
err = n.Pinning.Update(req.Context(), from, toc, unpin)
406+
err = n.Pinning.Update(req.Context(), from, toc)
415407
if err != nil {
416408
res.SetError(err, cmdkit.ErrNormal)
417409
return

core/coreapi/interface/options/pin.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type PinLsSettings struct {
1010
}
1111

1212
type PinUpdateSettings struct {
13-
Unpin bool
1413
}
1514

1615
type PinAddOption func(*PinAddSettings) error
@@ -49,9 +48,7 @@ func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
4948
}
5049

5150
func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) {
52-
options := &PinUpdateSettings{
53-
Unpin: true,
54-
}
51+
options := &PinUpdateSettings{}
5552

5653
for _, opt := range opts {
5754
err := opt(options)
@@ -119,12 +116,3 @@ func (pinOpts) pinType(t string) PinLsOption {
119116
return nil
120117
}
121118
}
122-
123-
// Unpin is an option for Pin.Update which specifies whether to remove the old pin.
124-
// Default is true.
125-
func (pinOpts) Unpin(unpin bool) PinUpdateOption {
126-
return func(settings *PinUpdateSettings) error {
127-
settings.Unpin = unpin
128-
return nil
129-
}
130-
}

core/coreapi/interface/pin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type PinAPI interface {
5353

5454
// Update changes one pin to another, skipping checks for matching paths in
5555
// the old tree
56-
Update(ctx context.Context, from Path, to Path, opts ...options.PinUpdateOption) error
56+
Update(ctx context.Context, from string, to Path) error
5757

5858
// Verify verifies the integrity of pinned objects
5959
Verify(context.Context) (<-chan PinStatus, error)

core/coreapi/pin.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,12 @@ func (api *PinAPI) Rm(ctx context.Context, p string) error {
6262
return nil
6363
}
6464

65-
func (api *PinAPI) Update(ctx context.Context, from string, to coreiface.Path, opts ...caopts.PinUpdateOption) error {
66-
settings, err := caopts.PinUpdateOptions(opts...)
67-
if err != nil {
68-
return err
69-
}
70-
65+
func (api *PinAPI) Update(ctx context.Context, from string, to coreiface.Path) error {
7166
tp, err := api.core().ResolvePath(ctx, to)
7267
if err != nil {
7368
return err
7469
}
75-
76-
return api.node.Pinning.Update(ctx, from, tp.Cid(), settings.Unpin)
70+
return api.node.Pinning.Update(ctx, from, tp.Cid())
7771
}
7872

7973
type pinStatus struct {

pin/pin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type Pinner interface {
6565
// Update updates a recursive pin from one cid to another
6666
// this is more efficient than simply pinning the new one and unpinning the
6767
// old one
68-
Update(ctx context.Context, path string, to *cid.Cid, unpin bool) error
68+
Update(ctx context.Context, path string, to *cid.Cid) error
6969

7070
// Check if given cid is pinned with given mode, return pin path
7171
IsPinPresent(cid *cid.Cid, recursive bool) (string, error)
@@ -357,7 +357,7 @@ func (p *pinner) PrefixedPins(prefix string, recursive bool) (map[string]*cid.Ci
357357
// Update updates a recursive pin from one cid to another
358358
// this is more efficient than simply pinning the new one and unpinning the
359359
// old one
360-
func (p *pinner) Update(ctx context.Context, path string, to *cid.Cid, unpin bool) error {
360+
func (p *pinner) Update(ctx context.Context, path string, to *cid.Cid) error {
361361

362362
c, err := p.GetPin(path, true)
363363
if err != nil {

0 commit comments

Comments
 (0)