|
1 | 1 | check_sha256 <- function(file, sum, os = c("linux", "macos", "windows")) {
|
2 | 2 | message("Checking SHA256 for <", file, ">...")
|
3 | 3 |
|
4 |
| - if (match.arg(os) == "linux") { |
5 |
| - out <- system2("sha256sum", args = file, stdout = TRUE) |> |
6 |
| - gsub(r"(\s.*)", "", x = _) |
7 |
| - } else if (match.arg(os) == "macos") { |
8 |
| - out <- system2("shasum", args = c("-a", "256", file), stdout = TRUE) |> |
9 |
| - gsub(r"(\s.*)", "", x = _) |
10 |
| - } else if (match.arg(os) == "windows") { |
11 |
| - out <- system2("certutil", args = c("-hashfile", file, "SHA256"), stdout = TRUE)[2] |
| 4 | + # tools::sha256sum should be available in R >= 4.5 |
| 5 | + if (exists("sha256sum", where = asNamespace("tools"), mode = "function")) { |
| 6 | + out <- tools::sha256sum(file) |
12 | 7 | } else {
|
13 |
| - stop("Unsupported OS: ", os) |
| 8 | + out <- switch(match.arg(os), |
| 9 | + linux = system2("sha256sum", args = file, stdout = TRUE) |> |
| 10 | + gsub(r"(\s.*)", "", x = _), |
| 11 | + macos = system2("shasum", args = c("-a", "256", file), stdout = TRUE) |> |
| 12 | + gsub(r"(\s.*)", "", x = _), |
| 13 | + windows = system2("certutil", args = c("-hashfile", file, "SHA256"), stdout = TRUE)[2], |
| 14 | + stop("Unsupported OS: ", os) |
| 15 | + ) |
14 | 16 | }
|
15 | 17 |
|
16 | 18 | if (out != sum) {
|
@@ -49,15 +51,12 @@ which_arch <- function() {
|
49 | 51 | }
|
50 | 52 |
|
51 | 53 | which_vendor_sys_abi <- function(os = c("linux", "macos", "windows")) {
|
52 |
| - if (match.arg(os) == "linux") { |
53 |
| - "unknown-linux-musl" |
54 |
| - } else if (match.arg(os) == "macos") { |
55 |
| - "apple-darwin" |
56 |
| - } else if (match.arg(os) == "windows") { |
57 |
| - "pc-windows-gnu" |
58 |
| - } else { |
| 54 | + switch(match.arg(os), |
| 55 | + linux = "unknown-linux-musl", |
| 56 | + macos = "apple-darwin", |
| 57 | + windows = "pc-windows-gnu", |
59 | 58 | stop("Unsupported OS: ", os)
|
60 |
| - } |
| 59 | + ) |
61 | 60 | }
|
62 | 61 |
|
63 | 62 | current_os <- which_os()
|
|
0 commit comments