Skip to content

Get a file during bootstrap to a temp location first. #33288

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

Merged
merged 4 commits into from
May 9, 2016

Conversation

cyplo
Copy link
Contributor

@cyplo cyplo commented Apr 30, 2016

When downloading a file in the bootstrap phase - get it to a temp
location first. Verify it there and only if downloaded properly move it
to the cache directory.

This should prevent make being stuck if the download was interrupted
or otherwise corrupted, as per discussion in #32834

The temporary files are deleted in case of an exception.

I was looking for some unit/integration tests around this and couldn't find any - presumably because this is being tested by just Travis launching it ? Let me know if it would be good to try to write tests around this. Thanks !

When downloading a file in the bootstrap phase - get it to a temp
location first. Verify it there and only if downloaded properly move it
to the `cache` directory.

This should prevent `make` being stuck if the download was interrupted
or otherwise corrupted.

The temporary files are deleted in case of an exception.
@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@cyplo
Copy link
Contributor Author

cyplo commented Apr 30, 2016

r? @alexcrichton

@cyplo
Copy link
Contributor Author

cyplo commented Apr 30, 2016

@caipre: could you take a look as well ? this is the one we've discussed in #32834 Thanks !

temp_path = temp_file.name
sha_file = tempfile.NamedTemporaryFile(suffix=".sha256", delete=True)
sha_path = sha_file.name
download(sha_path, sha_url, temp_path, url, verbose)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it might be worth reducing number of parameters here and invoking download twice instead, to show that we indeed download 2 files here ?

Make download() receive less parameters and use it explicitly 2 times
in get().
@cyplo cyplo changed the title Get a file during bootstrap to a temp location. Get a file during bootstrap to a temp location first. Apr 30, 2016
run(["curl", "-o", _path, _url], verbose=verbose)
print("verifying " + path)
with open(path, "rb") as f:
temp_file = tempfile.NamedTemporaryFile(delete=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be using with ... as temp_file:.

@cyplo
Copy link
Contributor Author

cyplo commented Apr 30, 2016

Very cool, thanks a lot @rkruppe, will look into fixing the things you've mentioned :)

run(["curl", "-o", path, url], verbose=verbose)


def verify(sha_path, temp_path, verbose):
Copy link
Contributor

@caipre caipre Apr 30, 2016

Choose a reason for hiding this comment

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

The second parameter here isn't required to be a temporary file, so I think just path is a better name.
Personally, I think ordering the parameters as def verify(path, sha_path, verbose) would feel more natural, but that's not a big deal.

@cyplo
Copy link
Contributor Author

cyplo commented May 8, 2016

Thanks again for the review @rkruppe and @caipre ! I tried to make this more robust and protect against exceptions, could you take a look now ?

@hanna-kruppe
Copy link
Contributor

LGTM 👍

@cyplo
Copy link
Contributor Author

cyplo commented May 8, 2016

Cool, thanks ! @alexcrichton could you take a look ?

@alexcrichton
Copy link
Member

@bors: r+ 6bce110

Thanks @cyplo!

@bors
Copy link
Collaborator

bors commented May 8, 2016

⌛ Testing commit 6bce110 with merge 6974800...

bors added a commit that referenced this pull request May 8, 2016
Get a file during bootstrap to a temp location first.

When downloading a file in the bootstrap phase - get it to a temp
location first. Verify it there and only if downloaded properly move it
to the `cache` directory.

This should prevent `make` being stuck if the download was interrupted
or otherwise corrupted, as per discussion in #32834

The temporary files are deleted in case of an exception.

I was looking for some unit/integration tests around this and couldn't find any - presumably because this is being tested by just Travis launching it ? Let me know if it would be good to try to write tests around this. Thanks !
@bors bors merged commit 6bce110 into rust-lang:master May 9, 2016
@cyplo cyplo deleted the 32834_retry_download branch May 9, 2016 08:01
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.

8 participants