-
-
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 a --with-local option to ipfs files stat #4638
Conversation
0361d05
to
7538f25
Compare
@whyrusleeping @Stebalien @kevina please have a look. |
I would also like to have @keks look over this if he is available as you are switching over the to new commands library. |
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.
Left one comment.
In addition the file core/commands/files/env.go
is a copy of core/commands/env.go
please remove it.
core/commands/files/files.go
Outdated
CumulativeSize uint64 | ||
Blocks int | ||
Type string | ||
WithLocality bool |
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.
Please add `json:",omitempty"`
after WithLocality so that the API output does not change if the --with-local
option 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.
Someone to weight here ? For me it makes more sense like this. There is no compatibility problem, it's just an extra field. The problem is If WithLocality
is set to false, the field is not present in the api anwser so you need to test if the field is present and if it's set to true. Not the end of the world, but ...
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.
@MichaelMure No, the same struct would be used on both sides. theres no need to check if its set, we just don't want the API to change where its not wanted. @kevina is right 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.
fixed
Part of the problem is the The other solution is to properly make
With a little more effort this could be properly fixed, but I think its best just to move |
"rm": FilesRmCmd, | ||
"flush": FilesFlushCmd, | ||
"chcid": FilesChcidCmd, | ||
"read": lgc.NewCommand(filesReadCmd), |
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.
Alternatively, You could just use the OldSubcommands
map instead of calling legacy.NewCommand
on all of these. I'm not that picky though.
switch fsn.Type() { | ||
case mfs.TDir: | ||
switch d.GetType() { | ||
case ft.TDirectory, ft.THAMTShard: |
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.
why make this change?
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.
d.GetType()
can be of these types so if HAMTSharding
was enabled we could potentially get an unrecognized node type
error here, ya?
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.
@whyrusleeping because we want (or at least I do) support /ipfs/Qmwhatever
. getNodeFromPath
will return an ipld.Node
instead of a mfs.FSNode
.
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.
@frrist indeed. I got that from https://github.com/ipfs/go-ipfs/blob/master/mfs/system.go#L92 where there is the same problem. Would that be a file, directory or else ?
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 they must either be a file or a directory,
Files is an API for manipulating IPFS objects as if they were a unix filesystem. - file.go
The current definition looks good to me, what do ya'll think?
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.
Ideally, MFS would handle /ipfs/
as a "mounted" subdirectory but we can fix that later.
I would really prefer that we not move files.go back up into the "all the commands" directory. But it does make it pretty obnoxious to keep it down there... |
To fix the import cycle we will need to move |
FWIW I never understood why files, object etc. had their own subfolders. Why shouldn't they be in the main command folder? |
Yeah, it was really just because I wanted to try and break things up into smaller bits. I'm okay with having them all in the one folder now. |
I'm okay either way. One reason The disadvantage of having them in there own package is that common code will also need to be in its own package as I did in ae7324a, in case you missed it. |
core/commands/files.go
Outdated
} | ||
withLocal, _ := req.Options["with-local"].(bool) | ||
if !withLocal { | ||
cmds.EmitOnce(res, o) |
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.
you should just be able to use res.Emit(o)
cc @keks
Alright, this LGTM. Will need a rebase. Can I get a +1 from @Stebalien and @kevina ? |
@whyrusleeping @MichaelMure because of the file move you need to be careful when reserving the conflict. Now that I worked out how to fix files.go so it can be in its own package, that might be best. Note that I can take over the p.r. if it would help. |
License: MIT Signed-off-by: Michael Muré <[email protected]>
License: MIT Signed-off-by: Michael Muré <[email protected]>
License: MIT Signed-off-by: Michael Muré <[email protected]>
License: MIT Signed-off-by: Michael Muré <[email protected]>
License: MIT Signed-off-by: Michael Muré <[email protected]>
It is a single file so putting it in its own package is a bit of an overkill. License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
License: MIT Signed-off-by: Michael Muré <[email protected]>
3faf668
to
e0babef
Compare
License: MIT Signed-off-by: Michael Muré <[email protected]>
e0babef
to
30d4eaa
Compare
@whyrusleeping rebase is done. |
I double checked the rebase and it looks good, the conflict was due to a dependency update which I made sure was correct. @MichaelMure you should not need to give me access as I can push directly to your branch since you made a p.r. from it. @whyrusleeping as I said before now that I think about it I am not sure moving [Truth be told I am okay either way, but it seams my comments are being lost in the noise and I am not sure anyone saw by commit that fixed the cycle. I apologize if I making things more complicated than need be.] |
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.
Alright, this LGTM.
@MichaelMure You've tested this with your application right? I wouldnt want to merge this is only to not have it work out right for you.
@whyrusleeping it does works. Good thing is that I didn't even need to change js-ipfs-api. |
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.
LGTM. Not so happy with the naming (--with-local
, WithLocality
, etc.) but I can't come up with better names so... .
switch fsn.Type() { | ||
case mfs.TDir: | ||
switch d.GetType() { | ||
case ft.TDirectory, ft.THAMTShard: |
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.
Ideally, MFS would handle /ipfs/
as a "mounted" subdirectory but we can fix that later.
Thanks for putting up with our indecision @MichaelMure :) |
Ok, new attempt after #4541 and #4596.
This PR add a
--with-local
option toipfs files stat
that compute and display how much of a dag is local.I had a small problem with a the functions defined in
env.go
that are not reachable from a subdir ofcore/commands
so I copied the file for now. I'm not sure how you want to solve that.On a side note, I would be very pleased if any version can make it to the upcoming RC and version.