-
-
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
implement an ipfs cat --length flag #4553
Conversation
fixes #4085 License: MIT Signed-off-by: Steven Allen <[email protected]>
License: MIT Signed-off-by: Steven Allen <[email protected]>
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.
Fix codeclimate issue, otherwise LGTM.
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.
Some portability suggestions.
test/sharness/t0040-add-and-cat.sh
Outdated
|
||
test_expect_success "ipfs cat multiple hashes with offset and length looks good" ' | ||
echo " Worlds!" >expected && | ||
echo -n "Hello " >>expected && |
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 use printf "Worlds!\nHello "
.
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.
Note that is you try this in bash on the command line this will fail as '!' has special meaning in bash when history expansion in enabled. This is disabled by default in scripts so it won't cause a problem.
test/sharness/t0040-add-and-cat.sh
Outdated
' | ||
|
||
test_expect_success "ipfs cat with length output looks good" ' | ||
echo -n "Hello Wo" >expected && |
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.
Note the -n
flag is not universally supported by all shells (for example on the mac). It is better to use printf
which is more portable. In this case it will be
printf "Hello Wo" >expected &&
License: MIT Signed-off-by: Steven Allen <[email protected]>
@kevina the code climate issue is a commands error style issue (and is significantly more pervasive). The error I added mimics the existing error so I'd like to leave it that way for now. We should go though these errors and fix them all at once at some point. |
@Stebalien that doesn't bother me if @whyrusleeping is fine with it also. |
@@ -50,7 +51,20 @@ var CatCmd = &cmds.Command{ | |||
return | |||
} | |||
|
|||
readers, length, err := cat(req.Context(), node, req.Arguments(), int64(offset)) | |||
max, found, err := req.Option("length").Int() |
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.
USE int64. THIS COULD OVERFLOW
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 don't see a int64 option in go-ipfs-cmdkit, we could use a uint instead? We could also add a new option if not.
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 was really just giving @Stebalien crap, he was sitting behind me while i reviewed this and pointed out that this should be an int64
fixes #4085
(because we too many open bugs dammit)