@@ -32,6 +32,29 @@ java_download <- function(
32
32
temp_dir = FALSE
33
33
) {
34
34
35
+ # Download distribution and check MD5 checksum
36
+ download_dist_check_md5 <- function (url , dest_file , quiet ) {
37
+
38
+ curl :: curl_download(url , dest_file , quiet = FALSE )
39
+ curl :: curl_download(url_md5 , dest_file_md5 , quiet = TRUE )
40
+
41
+ if (! quiet ) {
42
+ cli :: cli_inform(" Download completed." , .envir = environment())
43
+ }
44
+ md5sum <- tools :: md5sum(dest_file )
45
+ md5sum_expected <- readLines(dest_file_md5 , warn = FALSE )
46
+
47
+ if (md5sum != md5sum_expected ) {
48
+ cli :: cli_abort(" MD5 checksum mismatch. Please try downloading the file again." , .envir = environment())
49
+ unlink(dest_file )
50
+ return (NULL )
51
+ } else {
52
+ if (! quiet ) {
53
+ cli :: cli_inform(" MD5 checksum verified." , .envir = environment())
54
+ }
55
+ }
56
+ }
57
+
35
58
# override cache_path if temp_dir is set to TRUE
36
59
if (temp_dir ) {
37
60
temp_dir <- tempdir()
@@ -96,7 +119,6 @@ java_download <- function(
96
119
dest_file <- file.path(cache_path , basename(url ))
97
120
dest_file_md5 <- paste0(file.path(cache_path , basename(url_md5 )), " .md5" )
98
121
99
-
100
122
if (! quiet ) {
101
123
cli :: cli_inform(" Downloading Java {version} ({distribution}) for {platform} {arch} to {dest_file}" , .envir = environment())
102
124
}
@@ -105,44 +127,14 @@ java_download <- function(
105
127
if (! quiet ) {
106
128
cli :: cli_inform(" File already exists. Skipping download." , .envir = environment())
107
129
}
108
- } else if (file.exists(dest_file ) & force ){
130
+ } else if (file.exists(dest_file ) & force ) {
109
131
if (! quiet ) {
110
132
cli :: cli_inform(" Removing existing installation." , .envir = environment())
111
- }
112
- file.remove(dest_file )
113
- curl :: curl_download(url , dest_file , quiet = FALSE )
114
- curl :: curl_download(url_md5 , dest_file_md5 , quiet = TRUE )
115
- if (! quiet ) {
116
- cli :: cli_inform(" Download completed." , .envir = environment())
117
-
118
- md5sum <- tools :: md5sum(dest_file )
119
- md5sum_expected <- readLines(dest_file_md5 , warn = FALSE )
120
-
121
- if (md5sum != md5sum_expected ) {
122
- cli :: cli_alert_danger(" MD5 checksum mismatch. Please try downloading the file again." , .envir = environment())
123
- unlink(dest_file )
124
- return (NULL )
125
- } else {
126
- cli :: cli_inform(" MD5 checksum verified." , .envir = environment())
127
- }
128
- }
129
- } else if (! file.exists(dest_file )){
130
- curl :: curl_download(url , dest_file , quiet = FALSE )
131
- curl :: curl_download(url_md5 , dest_file_md5 , quiet = TRUE )
132
- if (! quiet ) {
133
- cli :: cli_inform(" Download completed." , .envir = environment())
134
-
135
- md5sum <- tools :: md5sum(dest_file )
136
- md5sum_expected <- readLines(dest_file_md5 , warn = FALSE )
137
-
138
- if (md5sum != md5sum_expected ) {
139
- cli :: cli_alert_danger(" MD5 checksum mismatch. Please try downloading the file again." , .envir = environment())
140
- unlink(dest_file )
141
- return (NULL )
142
- } else {
143
- cli :: cli_inform(" MD5 checksum verified." , .envir = environment())
144
133
}
145
- }
134
+ file.remove(dest_file )
135
+ download_dist_check_md5(url , dest_file , quiet )
136
+ } else if (! file.exists(dest_file )) {
137
+ download_dist_check_md5(url , dest_file , quiet )
146
138
}
147
139
148
140
return (dest_file )
0 commit comments