| 1 |
|
| 2 |
renv_tar_exe <- function(default = "") { |
| 3 |
|
| 4 |
# allow override |
| 5 |
tar <- getOption("renv.tar.exe") |
| 6 |
if (!is.null(tar)) |
| 7 |
return(tar) |
| 8 |
|
| 9 |
# on unix, just use default |
| 10 |
if (renv_platform_unix()) { |
| 11 |
tar <- Sys.which("tar") |
| 12 |
if (nzchar(tar)) |
| 13 |
return(tar) |
| 14 |
} |
| 15 |
|
| 16 |
# on Windows, use system tar.exe if available |
| 17 |
root <- Sys.getenv("SystemRoot", unset = NA) |
| 18 |
if (is.na(root)) |
| 19 |
root <- "C:/Windows" |
| 20 |
|
| 21 |
# use tar if it exists |
| 22 |
tarpath <- file.path(root, "System32/tar.exe") |
| 23 |
if (file.exists(tarpath)) |
| 24 |
return(tarpath) |
| 25 |
|
| 26 |
# otherwise, give up (don't trust the arbitrary tar on PATH) |
| 27 |
default |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
renv_tar_decompress <- function(tar, archive, files = NULL, exdir = ".", ...) { |
| 32 |
|
| 33 |
# build argument list |
| 34 |
args <- c( |
| 35 |
"xf", renv_shell_path(archive), |
| 36 |
if (!identical(exdir, ".")) |
| 37 |
c("-C", renv_shell_path(exdir)), |
| 38 |
if (length(files)) |
| 39 |
renv_shell_path(files) |
| 40 |
) |
| 41 |
|
| 42 |
# make sure exdir exists |
| 43 |
ensure_directory(exdir) |
| 44 |
|
| 45 |
# perform decompress |
| 46 |
return(renv_system_exec(tar, args, action = "decompressing archive")) |
| 47 |
|
| 48 |
} |