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

go-get checksum file & guess checksum #136

Merged
merged 43 commits into from
Jan 8, 2019
Merged

go-get checksum file & guess checksum #136

merged 43 commits into from
Jan 8, 2019

Conversation

azr
Copy link
Contributor

@azr azr commented Dec 3, 2018

Hello,

This pr allows to checksum from a file; this should be the last needed feature for packer to be able to use go-getter 🙂

file_url?checksum=file:checksum_url

@azr azr mentioned this pull request Dec 3, 2018
9 tasks
@azr

This comment has been minimized.

@azr azr changed the title go-get checksum file & guess checksum [WIP] go-get checksum file & guess checksum Dec 3, 2018
@azr azr changed the title [WIP] go-get checksum file & guess checksum go-get checksum file & guess checksum Dec 4, 2018
Copy link
Contributor

@vancluever vancluever left a comment

Choose a reason for hiding this comment

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

Hey @azr, this is an interesting concept indeed, but I think we could possibly go about the hash detection in a much less complex way.

BSD formats notwithstanding, the hash should always be at the start of the file, and a hashed checksum is always going to be a static length depending on the algorithm:

You could probably just take the sum, decode it from hex, and then check its size to get the right algorithm, and also pull the right file out accounting for specific the mode modifiers.

I've left some notes regarding recommending a refactoring of the functionality so that both query and file parsing go down two explicit code paths - that should make this easier to read.

Let me know when you've had a chance to update!

@azr
Copy link
Contributor Author

azr commented Dec 13, 2018

Hey @vancluever !
Awesome review, thanks for reviewing ! Derp, I totally didn't think of using the lengths of the hashes. I was too focused tried to have pair functionality with packer 🙂.

@azr
Copy link
Contributor Author

azr commented Dec 14, 2018

Okay, there, this should be done. Tell me what you think
I also added the possibility to checksum without passing the checksum type in the last commit. I totally can revert it if you think it's a bad idea. 🙂 I did it just because it was really simple to do from where I was and it makes usage simpler as you can now just pass checksum=<shasum>

Copy link
Contributor

@vancluever vancluever left a comment

Choose a reason for hiding this comment

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

Hey @azr, looking a lot better, got some new comments to address, but fundamentally this is a great improvement!

checksum.go Outdated
//
// checksumsFromFile will only return checksums for files that match file
// behind src
func checksumFromFile(checksumFile string, src *url.URL) (*fileChecksum, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I think I answered the question that I had from the docs here... we should really try and see how we can ensure that the same getter that is used to fetch the file is used to fetch the checksums. As mentioned, this is important on the HTTP getter where a custom client or additional headers will be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, trying something 🙂 !

Copy link
Contributor

Choose a reason for hiding this comment

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

Just based on what I mentioned here, the client should probably just be passed in as a parameter to save having to apply several breaking changes to the code.

@azr azr force-pushed the dl_checksum branch 4 times, most recently from 81c5385 to c795398 Compare December 20, 2018 13:55
@azr
Copy link
Contributor Author

azr commented Dec 20, 2018

Okay @vancluever I think this is better now, putting everything down methods/funcs had me cornered into a rabbit hole so instead I took a step back and put some code back/up in client.Get.

I also made a get func that is not a member of anything and takes all possible parameters. This allowed me to get the checksum file without breaking any api nor copying any code and it's not too bad !

This makes the body of get pretty long but I think this is for the best.

Tell me what you think 🙂

@azr
Copy link
Contributor Author

azr commented Jan 8, 2019

Hello @vancluever, I updated this pull request to have the checksum create a copy of the client to download the checksum file. Like we decided.


Notes:
I am very glad I split commits by content as this was just a matter of reverting changing path and cherry-picking.

I also marked all convos as resolved for less clogging as this PR got huge. Thanks again for your patience.

"io/ioutil"
)

func tmpFile(dir, pattern string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that in testing references that there is already a tempFile helper (with the "e"). This is a bit confusing and I think that one should be used instead if it's not functionally different. If it's in a test helper file, just move it to a common helper file (ie: this common.go) so that it can be used in non-test code.

Copy link
Contributor

Choose a reason for hiding this comment

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

PS: If it needs to be extended to return errors, that's fine too. Just the point being that we should avoid having two tempfile helpers.

Copy link
Contributor Author

@azr azr Jan 8, 2019

Choose a reason for hiding this comment

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

Okay, I simplified this... By adding a mustString func. I hope this is good 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I can see, there's some other implementation details of tempFile that were missed. I'll have a look over it again and see if I can just manually correct it.

@azr
Copy link
Contributor Author

azr commented Jan 8, 2019

I just rebased this branch on master after #131 was merged 🙂

This reverts commit 7607f9c.

The old test tempFile function is not general purpose and sets up a
static file within a directory created by the tempDir helper. This
functionality needs to be preserved, so the correct plan of action would
be to preserve this functionality while moving the function name to
another, logical name such as tempTestFile.
This renames the internal test tempFile function to tempTestFile.

It also fixes some of the cleanup calls that were added - rather than
deleting the static file created only, it deletes the directory, which
is actually the specific temporary data created.
@vancluever
Copy link
Contributor

Okay, as mentioned, the old test tempFile function needed fixing up still, because the re-implementation did not preserve the old functionality (returning a path for a static file "foo" within a directory created with tempDir).

This has now been corrected (you can see the changes in 6d796ed) and I'm just waiting for Travis to finish before merging.

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.

2 participants