diff --git a/R/build.R b/R/build.R index e74bf19..79cd06f 100644 --- a/R/build.R +++ b/R/build.R @@ -5,15 +5,27 @@ build_package <- function(path, tmpdir, build_args, libpath, quiet) { path <- normalizePath(path) + check_for_tilde_file(path) + dir.create(tmpdir, recursive = TRUE, showWarnings = FALSE) tmpdir <- normalizePath(tmpdir) if (file.info(path)$isdir) { if (!quiet) cat_head("R CMD build") + + desc <- desc(path) + clean_doc <- as_flag(desc$get("Config/build/clean-inst-doc"), NULL) + with_envvar( c("R_LIBS_USER" = paste(libpath, collapse = .Platform$path.sep)), { - proc <- pkgbuild_process$new(path, tmpdir, args = build_args) + proc <- pkgbuild_process$new( + path, + tmpdir, + args = build_args, + clean_doc = clean_doc + ) on.exit(proc$kill(), add = TRUE) + callback <- detect_callback() while (proc$is_incomplete_output() || proc$is_incomplete_error()) { proc$poll_io(-1) @@ -38,3 +50,15 @@ build_package <- function(path, tmpdir, build_args, libpath, quiet) { dest } } + +check_for_tilde_file <- function(path) { + lst <- dir(path) + if ("~" %in% lst) { + stop( + "This package contains a file or directory named `~`. ", + "Because of a bug in older R versions (before R 4.0.0), ", + "building this package might delete your entire home directory!", + "It is best to (carefully!) remove the file. rcmdcehck will exit now." + ) + } +} diff --git a/tests/testthat/test-build.R b/tests/testthat/test-build.R index f3ebff3..c9eb688 100644 --- a/tests/testthat/test-build.R +++ b/tests/testthat/test-build.R @@ -26,3 +26,11 @@ test_that("different packages in the same dir are fine", { expect_equal(readLines(res), "baz") expect_equal(readLines(f1), "foobar") }) + +test_that("protection against ~ deletion", { + mockery::stub(check_for_tilde_file, "dir", c("foo", "~", "bar")) + expect_error( + check_for_tilde_file(tempfile()), + "delete your entire home directory" + ) +})