@@ -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 , md5sum , md5sum_expectedm , 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_alert_danger(" 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,30 +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 )) {
109
- if (force ) {
110
- if (! quiet ) {
111
- cli :: cli_inform(" Removing existing installation." , .envir = environment())
112
- }
113
- file.remove(dest_file )
114
- curl :: curl_download(url , dest_file , quiet = FALSE )
115
- curl :: curl_download(url_md5 , dest_file_md5 , quiet = TRUE )
116
- }
130
+ } else if (file.exists(dest_file ) & force ) {
117
131
if (! quiet ) {
118
- cli :: cli_inform(" Download completed." , .envir = environment())
119
- }
120
- md5sum <- tools :: md5sum(dest_file )
121
- md5sum_expected <- readLines(dest_file_md5 , warn = FALSE )
122
-
123
- if (md5sum != md5sum_expected ) {
124
- cli :: cli_alert_danger(" MD5 checksum mismatch. Please try downloading the file again." , .envir = environment())
125
- unlink(dest_file )
126
- return (NULL )
127
- } else {
128
- if (! quiet ) {
129
- cli :: cli_inform(" MD5 checksum verified." , .envir = environment())
132
+ cli :: cli_inform(" Removing existing installation." , .envir = environment())
130
133
}
131
- }
134
+ file.remove(dest_file )
135
+ download_dist_check_md5(url , dest_file , md5sum , md5sum_expectedm , quiet )
136
+ } else if (! file.exists(dest_file )) {
137
+ download_dist_check_md5(url , dest_file , md5sum , md5sum_expectedm , quiet )
132
138
}
133
139
134
140
return (dest_file )
0 commit comments