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

add error log of download formula.json #13997

Merged

Conversation

hyuraku
Copy link
Contributor

@hyuraku hyuraku commented Oct 12, 2022

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

repair for We need to handle download errors of the formula.json and cask.json files in #13794

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Good work so far!

Comment on lines 764 to 765
exit_code=$?
if [[ ${exit_code} -ne 0 ]]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
exit_code=$?
if [[ ${exit_code} -ne 0 ]]
curl_exit_code=$?
if [[ ${curl_exit_code} -ne 0 ]]

@@ -761,8 +761,11 @@ EOS
--time-cond "${HOMEBREW_CACHE}/api/formula.json" \
--user-agent "${HOMEBREW_USER_AGENT_CURL}" \
"https://formulae.brew.sh/api/formula.json"
# TODO: we probably want to print an error if this fails.
# TODO: set HOMEBREW_UPDATED or HOMEBREW_UPDATE_FAILED
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to set HOMEBREW_UPDATED="1" if the file checksum changes?

@@ -754,16 +754,26 @@ EOS
if [[ -n "${HOMEBREW_INSTALL_FROM_API}" ]]
then
mkdir -p "${HOMEBREW_CACHE}/api"
if [[ -f "${HOMEBREW_CACHE}/api/formula.json" ]]
then
INITIAL_JSON_SHASUM="$(shasum -a 256 "${HOMEBREW_CACHE}"/api/formula.json)"
Copy link
Member

Choose a reason for hiding this comment

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

See vendor-install.sh. Can't rely on shasum being installed, unfortunately. Could consider just using e.g. the file size or something instead? This isn't for security so false-negatives don't matter too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review; I will put the ruby script to check shasum256 instead of shasum.

Copy link
Member

Choose a reason for hiding this comment

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

No, I think you want to do checksums instead of e.g. file sizes I think it's worth splitting out a shasum helper or something that we can use both here and in vendor-install.

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 will compare the file size by ls -s "${HOMEBREW_CACHE}"/api/formula.json)".

Copy link
Member

Choose a reason for hiding this comment

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

@hyuraku actually the best bet would be wc -c "${HOMEBREW_CACHE}"/api/formula.json)"

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Looks great, nice work @hyuraku!

Co-authored-by: Bo Anderson <mail@boanderson.me>
@MikeMcQuaid MikeMcQuaid merged commit 34979a3 into Homebrew:master Oct 14, 2022
Comment on lines +771 to +775
CURRENT_JSON_BYTESIZE="$(wc -c "${HOMEBREW_CACHE}"/api/formula.json)"
if [[ "${INITIAL_JSON_BYTESIZE}" != "${CURRENT_JSON_BYTESIZE}" ]]
then
HOMEBREW_UPDATED="1"
fi
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for this PR, @hyuraku! Looks great!

Sorry for the late comment. Would it make more sense to do this comparison based on the file update time? We pass --remote-time to curl and use this modification time anyway with --time-cond, so it seems reasonable to use that to see whether the file was updated. This removes the (unlikely) edge case where the pre and post files are the same thing

Copy link
Member

Choose a reason for hiding this comment

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

@Rylan12 @hyuraku If we can do this easily: sure!

@github-actions github-actions bot added the outdated PR was locked due to age label Nov 17, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants