-
-
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
Feature: ipfs repo stat
#2430
Feature: ipfs repo stat
#2430
Conversation
License: MIT Signed-off-by: Thomas Gardner <tmg@fastmail.com>
License: MIT Signed-off-by: Thomas Gardner <tmg@fastmail.com>
License: MIT Signed-off-by: Thomas Gardner <tmg@fastmail.com>
ed112fe
to
22cfd42
Compare
fmt.Fprintf(buf, "RepoSize \t %d\n", stat.RepoSize) | ||
fmt.Fprintf(buf, "RepoPath \t %s\n", stat.RepoPath) | ||
|
||
return strings.NewReader(buf.String()), nil |
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 can just do:
return buf, nil
here, all it wants is an io.Reader
which the buffer is
Mind venturing into the wild world of sharness tests? Would be nice to have some coverage on this. |
44594f0
to
20f43fb
Compare
@whyrusleeping added :) |
20f43fb
to
f1c0a86
Compare
test_expect_success "'ipfs repo stat' succeeds" ' | ||
ipfs repo stat > repo-stats && | ||
grep "RepoPath" repo-stats && | ||
grep "RepoSize" repo-stats && |
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 would break this up into more fine grained tests, makes debugging easier later on, maybe do:
- ipfs repo stat
- check that it looks right
- add the file and rerun repo stat
- check that the second stat looks right
where each item there is a separate test_expect_success
f1c0a86
to
b0b9f48
Compare
'ipfs repo stat' is a plumbing command that will scan the local | ||
set of stored objects and print repo statistics. It outputs to stdout: | ||
NumObjects int number of objects in the local repo | ||
RepoSize int size that the repo is currently taking |
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.
Size in bits? ;)
Watching. |
|
ded0e0c
to
5738c4c
Compare
@Kubuxu added as |
LGTM, thanks! |
buf := new(bytes.Buffer) | ||
fmt.Fprintf(buf, "NumObjects \t %d\n", stat.NumObjects) | ||
if human { | ||
fmt.Fprintf(buf, "RepoSize (MiB) \t %d\n", stat.RepoSize/1024) |
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 stat.RepoSize
is bytes as line 106 suggests, you need to devide by 1024^2
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.
Maybe also worth taking sub-MiB sizes into account here -- this might turn out as 0 if it's less than a MiB?
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.
thanks for catching that @lgierth :)
check #c10e329, I've added a clause to print it in bytes if it is less than one MiB. What do you think?
5738c4c
to
c10e329
Compare
LGTM 👍 :) |
Many thanks for the clean up. You might add the [Bash complete] too. [Bash complete] https://github.com/tomgg/go-ipfs/commit/9643b94d7ca9027138ea65e78f7875ad6be259aa |
I'm going to merge this as is, @tomgg if you want to PR in the bash completion please do ( i figure it would take you less time that anyone else since youve done it before) |
Feature: `ipfs repo stat`
🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉 |
Implements #1744
Builds on top of #2289
> ipfs repo stat NumObjects 11 RepoSize 52064 RepoPath /Users/david/.ipfs