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

Closes #61 Check MD5 regardless of quiet flag value #62

Merged
merged 4 commits into from
Mar 6, 2025

Conversation

enriquemondragon
Copy link
Contributor

Closes #61 Check MD5 regardless of quiet flag value

@e-kotov
Copy link
Owner

e-kotov commented Mar 5, 2025

@enriquemondragon great job on deduplication!

Two points:

  1. There is one new problem introduced. When you run:
x <- java_download(8, quiet = FALSE, force = FALSE)
# or
x <- java_download(8, quiet = FALSE, force = TRUE)
# or any other combination of arguments

And the file does not yet exist, the function will not download the file and no md5 check will be performed.

  1. Regarding the alert in case of failed md5:

For every cli::cli_inform line, I'm checking that quiet == FALSE, except for:

cli::cli_alert_danger("MD5 checksum mismatch. Please try downloading the file again.", .envir = environment())
Because I thought this would be something that the user would like to know, even if the quiet flag was set to TRUE. Let me know what you think!

I would argue that it is actually best to throw an error and stop, rather than just a warning, as broken distribution file will lead to problems during install and use of Java, so it's best to fail.

@enriquemondragon
Copy link
Contributor Author

enriquemondragon commented Mar 6, 2025

@e-kotov thank you!

I explicitly wrote down all the if cases and created a function called download_dist_check_md5 to address deduplication in this new scenario. Both cases seem to work well. I added the function at the beginning of the script, let me know if I should make any improvements.

Edit: I just saw that one test failed, I'll check this

@e-kotov
Copy link
Owner

e-kotov commented Mar 6, 2025

Edit: I just saw that one test failed, I'll check this

yep, it's because of the md5sum and md5sum_expectedm

# Download distribution and check MD5 checksum
  download_dist_check_md5 <- function(url, dest_file, md5sum, md5sum_expectedm, quiet) {

    curl::curl_download(url, dest_file, quiet = FALSE)
    curl::curl_download(url_md5, dest_file_md5, quiet = TRUE)

    if (!quiet) {
      cli::cli_inform("Download completed.", .envir = environment())
    }
    md5sum <- tools::md5sum(dest_file)
    md5sum_expected <- readLines(dest_file_md5, warn = FALSE)

    if (md5sum != md5sum_expected) {
      cli::cli_alert_danger("MD5 checksum mismatch. Please try downloading the file again.", .envir = environment())
      unlink(dest_file)
      return(NULL)
    } else {
      if (!quiet) {
        cli::cli_inform("MD5 checksum verified.", .envir = environment())
      }
    }
  }

perhaps you don't need these args at all as you overwrite them anyway in lines:

md5sum <- tools::md5sum(dest_file)
md5sum_expected <- readLines(dest_file_md5, warn = FALSE)

@enriquemondragon
Copy link
Contributor Author

Thank you, I think this has been corrected. I also removed the redundant args

md5sum_expected <- readLines(dest_file_md5, warn = FALSE)

if (md5sum != md5sum_expected) {
cli::cli_abort("MD5 checksum mismatch. Please try downloading the file again.", .envir = environment())
Copy link
Owner

Choose a reason for hiding this comment

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

@enriquemondragon I replaced the warning with cli_abort, so that the functions stops in case of MD5 check fail. Otherwise, the user may miss the error and unknowingly continue with the corrupted distribution.

@e-kotov e-kotov merged commit 8eacd3f into e-kotov:main Mar 6, 2025
7 checks passed
@e-kotov
Copy link
Owner

e-kotov commented Mar 6, 2025

@enriquemondragon all done now! Great, thanks for your input!

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

Successfully merging this pull request may close these issues.

md5 check is not performed in java_download() when quiet is TRUE
2 participants