Skip to content

Commit

Permalink
Remove unpin option from pin.Update
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Iaroslav Gridin <voker57@gmail.com>
  • Loading branch information
Voker57 committed Mar 3, 2018
1 parent 0f2288e commit 9536f12
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
11 changes: 2 additions & 9 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,10 @@ new pin and removing the old one.
},

Arguments: []cmdkit.Argument{
cmdkit.StringArg("from-path", true, false, "Path to old object."),
cmdkit.StringArg("pinpath", true, false, "Pin path of the old object."),
cmdkit.StringArg("to-path", true, false, "Path to new object to be pinned."),
},
Options: []cmdkit.Option{
cmdkit.BoolOption("unpin", "Remove the old pin.").WithDefault(true),
},
Type: PinOutput{},
Run: func(req cmds.Request, res cmds.Response) {
Expand All @@ -386,12 +385,6 @@ new pin and removing the old one.
return
}

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

from := req.Arguments()[0]

to, err := path.ParsePath(req.Arguments()[1])
Expand All @@ -411,7 +404,7 @@ new pin and removing the old one.
return
}

err = n.Pinning.Update(req.Context(), from, toc, unpin)
err = n.Pinning.Update(req.Context(), from, toc)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down
8 changes: 2 additions & 6 deletions core/coreapi/interface/options/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type PinLsSettings struct {
}

type PinUpdateSettings struct {
Unpin bool
}

type PinAddOption func(*PinAddSettings) error
Expand Down Expand Up @@ -49,9 +48,7 @@ func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
}

func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) {
options := &PinUpdateSettings{
Unpin: true,
}
options := &PinUpdateSettings{}

for _, opt := range opts {
err := opt(options)
Expand Down Expand Up @@ -80,8 +77,7 @@ func (api *PinOptions) WithType(t string) PinLsOption {
}

func (api *PinOptions) WithUnpin(unpin bool) PinUpdateOption {
return func(settings *PinUpdateSettings) error {
settings.Unpin = unpin
return func(_ *PinUpdateSettings) error {
return nil
}
}
4 changes: 2 additions & 2 deletions core/coreapi/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func (api *PinAPI) Rm(ctx context.Context, p string) error {
}

func (api *PinAPI) Update(ctx context.Context, from string, to coreiface.Path, opts ...caopts.PinUpdateOption) error {
settings, err := caopts.PinUpdateOptions(opts...)
_, err := caopts.PinUpdateOptions(opts...)
if err != nil {
return err
}

return api.node.Pinning.Update(ctx, from, to.Cid(), settings.Unpin)
return api.node.Pinning.Update(ctx, from, to.Cid())
}

type pinStatus struct {
Expand Down
4 changes: 2 additions & 2 deletions pin/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Pinner interface {
// Update updates a recursive pin from one cid to another
// this is more efficient than simply pinning the new one and unpinning the
// old one
Update(ctx context.Context, path string, to *cid.Cid, unpin bool) error
Update(ctx context.Context, path string, to *cid.Cid) error

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

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

0 comments on commit 9536f12

Please sign in to comment.