-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add arguments to 'ipfs pin ls' #2208
Conversation
if typeStr == "direct" || typeStr == "all" { | ||
for _, k := range n.Pinning.DirectKeys() { | ||
|
||
if (argCount > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[style] I would just inline len(req.Arguments())
here instead of declaring an extra variable for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do.
A few comments there, and also make sure to run |
Ok, I will push something cleaned up using |
86bbe5f
to
b36bf37
Compare
Done! |
The Travis CI build failure is the usual "no output received for 10 minutes". |
@@ -1,30 +0,0 @@ | |||
#!/bin/sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious why this test is no longer needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was not a test. It was a script used only by t0081.
Now we can do the same thing with ipfs pin ls <arg>...
so this script is not needed any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh ok i see it now.
comments above, LGTM otherwise |
b36bf37
to
aada69c
Compare
Ok, here is a new version. I think all the comments have been taken into account. |
The Travis CI an Circle CI failures are timeouts: "command make test_sharness_expensive took more than 10 minutes since last output" |
keys, err = pinLsKeys(req.Arguments(), typeStr, req.Context(), n) | ||
} else { | ||
if !typeStrFound { | ||
typeStr = "recursive" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the default for typeStr
should be the same in both cases (either "all"
or "recursive"
) i fear that having them be different will confuse users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it would be more logical for the default to be the same in both cases, but when there are args it is natural to have the default be "all" and setting it to "all" when there are no args is a bit backward incompatible, so I preferred to avoid it.
Now if you are ok for the default being "all" in both case I can change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when there are args it is natural to have the default be "all"
yeah.
setting it to "all" when there are no args is a bit backward incompatible
yeah... :(
i think ipfs pin ls
makes sense to default to all, too. we can put a notice and make sure to put it in the changelog. it would be nice to have a "incompatible changes" section that people could see easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I change the default to "all" and put something about that in the changelog.
Looking at CHANGELOG.md on GitHub, it seems that there is nothing about v0.3.11 and v0.4.0 in it. Are we still supposed to update it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chriscool yes we are.
@whyrusleeping why was the changelog not updated when you released 0.3.11?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbenet a rebased version is now available with a new commit that changes the default to "all" and adds entries to the changelog for v0.4.0.
It is more generic to be able to pass a pin type argument. License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
aada69c
to
29830da
Compare
There is this error with Circle CI:
|
I've never seen that error. weird. cc @whyrusleeping @rht |
that panic is because the error is not checked in that function: ( err = filepath.Walk(pth, func(p string, f os.FileInfo, err error) error {
du += uint64(f.Size())
return nil
}) |
you can probably ignore it, and we can fix it in another PR (file a bug for it). Or you can maybe check the error, but i'm not sure how it propogates, so maybe its really best for another PR |
'is it reproducible?' no, I tested locally and didn't see any err, and so it is not deterministic. Explaining what had possibly happened: between |
if err != nil { | ||
return nil, err | ||
} | ||
err = dag.EnumerateChildren(n.Context(), n.DAG, nd, ks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Listing indirect keys recursively appears only in here, while I think it should be the case in pinLsKeys
's indirect as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, this is much like the ipfs ls
and ipfs refs
/ipfs refs -r
case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pinLsKeys
calls IsPinnedWithType() which does something like the above for indirect keys. See pin/pin.go around line 203.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chriscool IsPinnedWithType()
does have hasChild
, which is recursive. However dag.EnumerateChildren
also adds all the child keys into a key.KeySet
. The keyset is what is needed here for recursive ls. It is orthogonal to this PR, but just to point it out (of the possibility of ipfs pin ls -r $hash
or ipfs pin refs -r
and deduplications).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, then please open another issue to suggest adding the -r flag, and by the way ipfs pin ls
also has a --count
flag but it is not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redirect: #2225
Why is |
switch pinType { | ||
case "direct", "indirect", "recursive", "internal": | ||
default: | ||
pinType = "indirect through " + pinType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, it looks like pinLsKeys
= ipfs resolve | isPinnedWithType
.
I wonder why is this not in IsPinnedWithType
?
gc.GC()
in pin/gc/gc.go
uses a kind of ipfs pin ls --type=all
(in Descendants
and ColoredSet
), so there could be a refactor here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rht if you ask why the switch pinType { ... }
is not part of IsPinnedWithType
then my answer is that it would be inefficient for IsPinnedWithType
users which are internal functions to have to parse "indirect through XXX" if they want to get XXX.
If there are many IsPinnedWithType
users that want "indirect through XXX" then we can add IsPinnedWithTypePretty
that just calls IsPinnedWithType
and does what the switch pinType { ... }
does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About refactoring with pin/gc/gc.go
it does not look simple to me, and as ipfs pin ls --type=all
already existed before this PR, it could have been done before. So it is independent and maybe you can open a new issue to suggest that refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are many IsPinnedWithType users that want "indirect through XXX" then we can add
IsPinnedWithTypePretty
that just callsIsPinnedWithType
and does what the switch pinType { ... } does.
It could be the other way around, e.g. scripts parsing the output of ipfs pin ls
would use IsPinnedWithType
so that rows are mainly space separated.
Issue #2220 should take care of the bug found by the Circle CI run. |
} | ||
if typeStr == "indirect" || typeStr == "all" { | ||
ks := key.NewKeySet() | ||
for _, k := range n.Pinning.RecursiveKeys() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx: https://github.com/ipfs/go-ipfs/pull/2208/files#r50369858, this line until L340 could be replaced with gc.Descendants
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(if you don't mind to put the refactor in this pr; nvm)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in the last commit, thanks for the suggestion.
@rht with the last patch that uses gc.Descendants(), t0080-repo.sh fails so I will remove it. The error is:
|
7e89859
to
29830da
Compare
ic, it is because |
@whyrusleeping think we should merge it. im a bit wary of merging something with a known crash. since it's not really in this code (i.e unrelated) i'll merge this. 0.4.0 people, please update and warn me if you see any crashing at all. maybe we can put effort on finding and solving #2220 |
This makes it possible to pass path arguments to
ipfs pin ls
to know if some specific objects are pinned.To enable that
IsPinnedWithType(key.Key, string) (string, bool, error)
is added to the Pinner interface.The benefits are that
test/bin/ipfs-pin-stat
can be removed, and t0081 is now faster (around 18 seconds now, versus 50 seconds before this PR on my machine).