Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmds/pin: use coreapi/pin #5843

Merged
merged 3 commits into from
Jan 29, 2019
Merged

Conversation

overbool
Copy link
Contributor

@overbool overbool commented Dec 13, 2018

Related: #5717 (comment)
License: MIT
Signed-off-by: Overbool [email protected]

@overbool overbool force-pushed the refactor/coreapi/pin-rm branch 3 times, most recently from a39a699 to 07b7fc6 Compare December 13, 2018 15:55
Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

Thanks! First pass, but looks fairly good.

core/coreapi/interface/options/pin.go Show resolved Hide resolved
core/coreapi/pin.go Outdated Show resolved Hide resolved
core/commands/pin.go Outdated Show resolved Hide resolved
@overbool overbool force-pushed the refactor/coreapi/pin-rm branch 3 times, most recently from a41cecd to 31712ff Compare December 15, 2018 03:25
@magik6k magik6k self-requested a review December 17, 2018 00:29
Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

After those 3 should be good

core/commands/pin.go Outdated Show resolved Hide resolved
core/coreapi/interface/options/pin.go Outdated Show resolved Hide resolved
core/commands/pin.go Outdated Show resolved Hide resolved
@overbool overbool force-pushed the refactor/coreapi/pin-rm branch 5 times, most recently from 2d50260 to 2956bd0 Compare December 21, 2018 04:41
@Stebalien Stebalien requested a review from magik6k January 5, 2019 21:53
@magik6k
Copy link
Member

magik6k commented Jan 7, 2019

There are some pin-related tests failing - https://ci.ipfs.team/blue/organizations/jenkins/IPFS%2Fgo-ipfs/detail/PR-5843/19/tests

Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

Code looks good, not sure about the failing tests

@ghost ghost assigned Stebalien Jan 8, 2019
@ghost ghost added the status/in-progress In progress label Jan 8, 2019
@Stebalien
Copy link
Member

Unfortunately, it looks like the commands library was duck-typing structs with an Error field as an error. Fixed by renaming it to Errors.

In the past, errors/non-errors were indistinguishable without duck-typing (in some cases). We've now fixed that so the client should only interpret something as an error if:

  1. The command returns a non-200 status.
  2. The command returns the error in a trailing header.

However, we're still ducktyping for backwards compatibility for the moment.

@Stebalien
Copy link
Member

Stebalien commented Jan 8, 2019

Ah, nevermind, that wasn't the issue. The issue is that the error type can't be serialized. The type just needs to change to map[string]string.

(I've removed my commit)

@Stebalien Stebalien added the need/author-input Needs input from the original author label Jan 9, 2019
@magik6k magik6k added the topic/core-api Topic core-api label Jan 15, 2019
@magik6k magik6k mentioned this pull request Jan 15, 2019
51 tasks
@overbool overbool force-pushed the refactor/coreapi/pin-rm branch 2 times, most recently from 53e260d to 8d4de98 Compare January 16, 2019 18:31
@overbool
Copy link
Contributor Author

@magik6k @Stebalien
I don't know much about the difference between Encoders and PostRun.
Should we replace Encoders with PostRun (like blockRmCmd) about this: https://github.com/ipfs/go-ipfs/blob/b36037a3a5ca71108d1d4673f4925f8b5b813d0c/core/commands/pin.go#L225-L230

@magik6k
Copy link
Member

magik6k commented Jan 17, 2019

I don't know much about the difference between Encoders and PostRun.

The difference is that Encoders can run on the server when ?encoding parameter is specified. PostRun only runs on the client side. PostRun also allows to track state more easily and do things after the command has ran. Generally Encoders should be used instead of PostRun where possible.

@overbool overbool changed the title [WIP] cmds/pin: use coreapi/pin cmds/pin: use coreapi/pin Jan 17, 2019
@overbool
Copy link
Contributor Author

@Stebalien @magik6k All tests passed. Could u help me review it again?

@Stebalien Stebalien added the status/blocked Unable to be worked further until needs are met label Jan 17, 2019
@Stebalien
Copy link
Member

Let's wait for #5789 to avoid having to rework that. We should merge it within a few days.

@Stebalien Stebalien removed the status/blocked Unable to be worked further until needs are met label Jan 21, 2019
@Stebalien
Copy link
Member

This is unblocked but will need a rebase.

@Stebalien Stebalien added needs rebase and removed need/author-input Needs input from the original author labels Jan 21, 2019
@overbool
Copy link
Contributor Author

This is unblocked but will need a rebase.

It`s ok.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

We'll need discuss the --force option a bit with the JS team (comments inline).

return nil, err
}

if err := api.Pin().Add(ctx, p, options.Pin.Recursive(recursive)); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This should use rp, not p. If we're using IPNS, there's a chance it may have changed.

if err, ok := out.Error[k]; !ok {
fmt.Fprintf(w, "unpinned %s\n", k)
} else {
fmt.Fprintf(os.Stderr, "cannot unpin %s: %s\n", k, err)
Copy link
Member

Choose a reason for hiding this comment

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

We can't do this in an encoder as encoders are sometimes run server-side. Instead, it should be handled by a PostRun. That is, you can setup a "CLI" PostRun that prints errors to standard error and forwards everything else to the encoder.


id := enc.Encode(rp.Cid())
pins = append(pins, id)
if err := api.Pin().Rm(req.Context, rp, options.Pin.RmRecursive(recursive)); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

@overbool overbool force-pushed the refactor/coreapi/pin-rm branch 2 times, most recently from b10dd5b to 03556a9 Compare January 28, 2019 05:18
@overbool
Copy link
Contributor Author

overbool commented Jan 28, 2019

@Stebalien I think we can add --force option in another pr(#5717). This pr just replace corerepo/pin with coreapi/pin and will keep original feature that will bail out when it encounters an error.

(I had removed the Error map[string]string in this pr).

@magik6k magik6k self-requested a review January 28, 2019 15:49
@Stebalien
Copy link
Member

I think we can add --force option in another pr(#5717).

SGTM.

overbool and others added 3 commits January 29, 2019 11:29
License: MIT
Signed-off-by: Overbool <[email protected]>
License: MIT
Signed-off-by: Overbool <[email protected]>
* Name them. Unfortunately, This makes the *actual* package names clear. I know
  this isn't "idiomatic go" but it's idiomatic go-ipfs.
* Remove the duplicate import.

License: MIT
Signed-off-by: Steven Allen <[email protected]>
@Stebalien Stebalien merged commit f0a26c1 into ipfs:master Jan 29, 2019
@ghost ghost removed the status/in-progress In progress label Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/core-api Topic core-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants