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 <[email protected]>
  • Loading branch information
Voker57 committed Aug 23, 2018
1 parent 8301e84 commit 34977df
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 33 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
14 changes: 1 addition & 13 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 @@ -119,12 +116,3 @@ func (pinOpts) pinType(t string) PinLsOption {
return nil
}
}

// Unpin is an option for Pin.Update which specifies whether to remove the old pin.
// Default is true.
func (pinOpts) Unpin(unpin bool) PinUpdateOption {
return func(settings *PinUpdateSettings) error {
settings.Unpin = unpin
return nil
}
}
2 changes: 1 addition & 1 deletion core/coreapi/interface/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type PinAPI interface {

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

// Verify verifies the integrity of pinned objects
Verify(context.Context) (<-chan PinStatus, error)
Expand Down
10 changes: 2 additions & 8 deletions core/coreapi/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,12 @@ func (api *PinAPI) Rm(ctx context.Context, p string) error {
return nil
}

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

func (api *PinAPI) Update(ctx context.Context, from string, to coreiface.Path) error {
tp, err := api.core().ResolvePath(ctx, to)
if err != nil {
return err
}

return api.node.Pinning.Update(ctx, from, tp.Cid(), settings.Unpin)
return api.node.Pinning.Update(ctx, from, tp.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 @@ -359,7 +359,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 34977df

Please sign in to comment.