| 1 |
|
| 2 |
the$curl_valid <- new.env(parent = emptyenv()) |
| 3 |
the$curl_version <- new.env(parent = emptyenv()) |
| 4 |
|
| 5 |
renv_curl_exe <- function() { |
| 6 |
|
| 7 |
curl <- Sys.getenv("RENV_CURL_EXECUTABLE", unset = NA) |
| 8 |
if (is.na(curl)) |
| 9 |
curl <- Sys.which("curl") |
| 10 |
|
| 11 |
if (!nzchar(curl)) |
| 12 |
return(renv_curl_exe_missing(curl)) |
| 13 |
|
| 14 |
renv_curl_validate(curl) |
| 15 |
|
| 16 |
} |
| 17 |
|
| 18 |
renv_curl_validate <- function(curl) { |
| 19 |
|
| 20 |
the$curl_valid[[curl]] <- the$curl_valid[[curl]] %||% { |
| 21 |
renv_curl_validate_impl(curl) |
| 22 |
} |
| 23 |
|
| 24 |
} |
| 25 |
|
| 26 |
renv_curl_validate_impl <- function(curl) { |
| 27 |
|
| 28 |
# make sure we can run this copy of curl |
| 29 |
# note that 'system2()' will give an error if curl isn't runnable at all |
| 30 |
output <- suppressWarnings( |
| 31 |
tryCatch( |
| 32 |
system2( |
| 33 |
command = curl, |
| 34 |
args = "--version", |
| 35 |
stdout = TRUE, |
| 36 |
stderr = TRUE |
| 37 |
), |
| 38 |
error = identity |
| 39 |
) |
| 40 |
) |
| 41 |
|
| 42 |
if (!inherits(output, "error")) { |
| 43 |
status <- attr(output, "status") %||% 0L |
| 44 |
if (status == 0L) |
| 45 |
return(curl) |
| 46 |
} |
| 47 |
|
| 48 |
message <- if (inherits(output, "error")) |
| 49 |
conditionMessage(output) |
| 50 |
else |
| 51 |
output |
| 52 |
|
| 53 |
fmt <- "Error executing '%s --version': is your copy of curl functional?" |
| 54 |
footer <- sprintf(fmt, curl) |
| 55 |
all <- c("", header(paste(curl, "--version"), prefix = "$"), message, "", footer) |
| 56 |
|
| 57 |
defer( |
| 58 |
message(paste(all, collapse = "\n")), |
| 59 |
scope = renv_dynamic_envir() |
| 60 |
) |
| 61 |
|
| 62 |
return(curl) |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
renv_curl_version <- function() { |
| 67 |
|
| 68 |
curl <- renv_curl_exe() |
| 69 |
if (!nzchar(curl)) |
| 70 |
return(numeric_version("0.0.0")) |
| 71 |
|
| 72 |
the$curl_version[[curl]] <- the$curl_version[[curl]] %||% { |
| 73 |
renv_curl_version_impl(curl) |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
renv_curl_version_impl <- function(curl) { |
| 79 |
|
| 80 |
output <- catch(renv_system_exec(curl, args = "--version", success = NULL)) |
| 81 |
if (inherits(output, "error") || length(output) == 0L) |
| 82 |
return(numeric_version("0.0.0")) |
| 83 |
|
| 84 |
# first line is e.g. "curl 8.7.1 (x86_64-apple-darwin24.0) ..." |
| 85 |
m <- regmatches(output[[1L]], regexpr("[0-9]+\\.[0-9]+[0-9.]*", output[[1L]])) |
| 86 |
if (length(m) == 0L) |
| 87 |
return(numeric_version("0.0.0")) |
| 88 |
|
| 89 |
numeric_version(m) |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
renv_curl_exe_missing <- function(curl) { |
| 94 |
|
| 95 |
if (!once()) |
| 96 |
return(invisible(curl)) |
| 97 |
|
| 98 |
parts <- c( |
| 99 |
"curl does not appear to be installed; downloads will fail.", |
| 100 |
"See <https://rstudio.github.io/renv/articles/renv.html#downloads> for more information." |
| 101 |
) |
| 102 |
|
| 103 |
msg <- paste(parts, collapse = "\n") |
| 104 |
warning(msg, call. = FALSE) |
| 105 |
|
| 106 |
invisible(curl) |
| 107 |
|
| 108 |
} |