5
5
# ' @param cache_path The destination directory to download the Java distribution to. Defaults to a user-specific data directory.
6
6
# ' @param platform The platform for which to download the Java distribution. Defaults to the current platform.
7
7
# ' @param arch The architecture for which to download the Java distribution. Defaults to the current architecture.
8
+ # ' @param force A logical. Whether the distribution file should be overwritten or not. Defaults to `FALSE`.
8
9
# ' @param temp_dir A logical. Whether the file should be saved in a temporary directory. Defaults to `FALSE`.
9
10
# ' @inheritParams global_quiet_param
10
11
# '
13
14
# '
14
15
# ' @examples
15
16
# ' \dontrun{
16
- # '
17
+ # '
17
18
# ' # download distribution of Java version 17
18
19
# ' java_download(version = "17", temp_dir = TRUE)
19
- # '
20
+ # '
20
21
# ' # download default Java distribution (version 21)
21
22
# ' java_download(temp_dir = TRUE)
22
23
# ' }
@@ -27,9 +28,10 @@ java_download <- function(
27
28
platform = platform_detect()$ os ,
28
29
arch = platform_detect()$ arch ,
29
30
quiet = FALSE ,
31
+ force = FALSE ,
30
32
temp_dir = FALSE
31
33
) {
32
-
34
+
33
35
# override cache_path if temp_dir is set to TRUE
34
36
if (temp_dir ) {
35
37
temp_dir <- tempdir()
@@ -98,11 +100,32 @@ java_download <- function(
98
100
cli :: cli_inform(" Downloading Java {version} ({distribution}) for {platform} {arch} to {dest_file}" , .envir = environment())
99
101
}
100
102
101
- if (file.exists(dest_file )) {
103
+ if (file.exists(dest_file ) & ! force ) {
102
104
if (! quiet ) {
103
105
cli :: cli_inform(" File already exists. Skipping download." , .envir = environment())
104
106
}
105
- } else {
107
+ } else if (file.exists(dest_file ) & force ){
108
+ if (! quiet ) {
109
+ cli :: cli_inform(" Removing existing installation." , .envir = environment())
110
+ }
111
+ file.remove(dest_file )
112
+ curl :: curl_download(url , dest_file , quiet = FALSE )
113
+ curl :: curl_download(url_md5 , dest_file_md5 , quiet = TRUE )
114
+ if (! quiet ) {
115
+ cli :: cli_inform(" Download completed." , .envir = environment())
116
+
117
+ md5sum <- tools :: md5sum(dest_file )
118
+ md5sum_expected <- readLines(dest_file_md5 , warn = FALSE )
119
+
120
+ if (md5sum != md5sum_expected ) {
121
+ cli :: cli_alert_danger(" MD5 checksum mismatch. Please try downloading the file again." , .envir = environment())
122
+ unlink(dest_file )
123
+ return (NULL )
124
+ } else {
125
+ cli :: cli_inform(" MD5 checksum verified." , .envir = environment())
126
+ }
127
+ }
128
+ } else if (! file.exists(dest_file )){
106
129
curl :: curl_download(url , dest_file , quiet = FALSE )
107
130
curl :: curl_download(url_md5 , dest_file_md5 , quiet = TRUE )
108
131
if (! quiet ) {
0 commit comments