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

Better combo curl/wget handling #452

Merged
merged 8 commits into from
Jul 7, 2014
Merged

Better combo curl/wget handling #452

merged 8 commits into from
Jul 7, 2014

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Jul 5, 2014

Fixes #451

@ljharb
Copy link
Member Author

ljharb commented Jul 5, 2014

@koenpunt: mind taking a look at this?

@koenpunt
Copy link
Contributor

koenpunt commented Jul 7, 2014

Looks fine, but maybe we should rename nvm_curl to something like nvm_download?

@ljharb
Copy link
Member Author

ljharb commented Jul 7, 2014

Good idea.

Unfortunately, this doesn't work :-/ it seems the curl options we use can't be cleanly passed to wget.

@ljharb
Copy link
Member Author

ljharb commented Jul 7, 2014

The other option is to just remove wget support everywhere.

@@ -391,16 +405,16 @@ nvm() {
tmpdir="$NVM_DIR/src"
local tmptarball
tmptarball="$tmpdir/node-$VERSION.tar.gz"
if [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
if [ "`nvm_curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

The unsupported arguments are --progress-bar, which is the default for wget so we can just strip that, and -L (follow location) is also the default in wget so we can strip that as well, and -C (continue transfer) has an equal in wget: -c:

nvm_curl() {
    ARGS="$* "
    ARGS=${ARGS/--progress-bar /}
    ARGS=${ARGS/-L /}
    ARGS=${ARGS/-s /-q }
    ARGS=${ARGS/-o /-O }
    ARGS=${ARGS/-C /-c }
    wget "$ARGS"
}

And then there is -I, but we can replace that for a version comparison, as it seems like that since version 0.5.1 they all end up in a subdirectory on http://nodejs.org/dist anyway:

[ $(nvm_normalize_version "$VERSION") -ge $(nvm_normalize_version "0.5.1") ]

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I think for now I'll just strip the -I check (making the wget less efficient), and we can change the logic in another PR.

@ljharb
Copy link
Member Author

ljharb commented Jul 7, 2014

I tested both curl and wget manually here, and it all works.

ARGS=${ARGS/--progress-bar /--progress=bar }
ARGS=${ARGS/-L /}
ARGS=${ARGS/-I /}
ARGS=${ARGS/-s /-qO- }
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look like the correct replacement.. -qO- means silent and output to stdout.

Copy link
Member Author

Choose a reason for hiding this comment

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

which part? (i'll take out the echo, oops)

Copy link
Member Author

Choose a reason for hiding this comment

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

in curl, -s silences the output but still prints the data to stdout. in wget, -q silences the output but does not print to stdout - to keep the same semantics, -qO- will silence output and print data to stdout in wget.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add -o - to the commands that need it would be a solution. From the manual:

-o, --output
Write output to instead of stdout.
....
Specifying the output as '-' (a single dash) will force the output to be done to stdout.

ARGS=${ARGS/--progress-bar /--progress=bar }
ARGS=${ARGS/-L /}
ARGS=${ARGS/-I /}
ARGS=${ARGS/-s /-qO- }
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

ljharb added a commit that referenced this pull request Jul 7, 2014
@ljharb ljharb merged commit cf5bfec into master Jul 7, 2014
@mgol
Copy link
Contributor

mgol commented Jul 7, 2014

So it wasn't renamed to nvm_download after all?

@mgol
Copy link
Contributor

mgol commented Jul 7, 2014

Anyway, huge props for it!

@ljharb
Copy link
Member Author

ljharb commented Jul 7, 2014

Oops :-) I'll do that in a followup. Still not in a release tag, so nobody should be using it unless they're testing nvm itself.

ljharb added a commit that referenced this pull request Jul 7, 2014
@koenpunt
Copy link
Contributor

koenpunt commented Jul 7, 2014

I thought of that, but nvm_curl is not so bad, because we're emulating curl after all.

imho nvm_download should be dedicated to downloading files.

And I think we should extract the checksum verification into its own method.

@ljharb
Copy link
Member Author

ljharb commented Jul 7, 2014

@koenpunt i'll be happy to accept PRs for those :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't provide wget install instructions
3 participants