diff --git a/NEWS.md b/NEWS.md index 37a19c0..17aa06b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,9 @@ `sessioninfo.include_hostname` global option is set to `TRUE` (@certara-jcraig, #99). +* sessioninfo now does not leave behind detritus in the temporary + directory. + # sessioninfo 1.2.2 * This version does not add an emoji hash to the output. diff --git a/R/mocks.r b/R/mocks.r index db98328..1ee34fe 100644 --- a/R/mocks.r +++ b/R/mocks.r @@ -4,3 +4,4 @@ getNamespaceVersion <- NULL loadedNamespaces <- NULL search <- NULL system <- NULL +system2 <- NULL diff --git a/R/platform-info.R b/R/platform-info.R index 8244f0c..71d9896 100644 --- a/R/platform-info.R +++ b/R/platform-info.R @@ -91,10 +91,14 @@ get_quarto_version <- function() { if (path == "") { "NA" } else { - ver <- system("quarto -V", intern = TRUE)[1] + tmp <- tempfile() + on.exit(unlink(tmp, recursive = TRUE), add = TRUE) + dir.create(tmp, recursive = TRUE, showWarnings = FALSE) + tmp <- normalizePath(tmp, winslash = "/") + ver <- system2("quarto", "-V", stdout = TRUE, env = paste0("TMPDIR=", tmp))[1] paste0(ver, " @ ", path) } - } +} #' @export diff --git a/tests/testthat/test-platform-info.R b/tests/testthat/test-platform-info.R index d18ac99..ec0d548 100644 --- a/tests/testthat/test-platform-info.R +++ b/tests/testthat/test-platform-info.R @@ -39,6 +39,6 @@ test_that("get_quarto_version", { expect_snapshot(get_quarto_version()) local_mocked_bindings(Sys.which = function(...) "/path/to/quarto") - local_mocked_bindings(system = function(...) "1.3.450") + local_mocked_bindings(system2 = function(...) "1.3.450") expect_snapshot(get_quarto_version()) })