diff --git a/R/build.R b/R/build.R index 630ed86..41f4d9a 100644 --- a/R/build.R +++ b/R/build.R @@ -10,7 +10,7 @@ build_package <- function(path, tmpdir, build_args, libpath, quiet) { dir.create(tmpdir, recursive = TRUE, showWarnings = FALSE) tmpdir <- normalizePath(tmpdir) - if (file.info(path)$isdir) { + if (safecheck_isdir(path)) { if (!quiet) cat_head("R CMD build") desc <- desc(path) diff --git a/R/env.R b/R/env.R index 8537750..51e4831 100644 --- a/R/env.R +++ b/R/env.R @@ -42,7 +42,7 @@ load_env <- function(path, targz, package, envir = parent.frame()) { if (!should_load) return() env <- NULL - if (file.info(path)$isdir) { + if (safecheck_isdir(path)) { env_path <- file.path(path, "tools", "check.env") } else { dir.create(tmp <- tempfile()) diff --git a/R/package.R b/R/package.R index 3e01892..983cec5 100644 --- a/R/package.R +++ b/R/package.R @@ -130,7 +130,7 @@ rcmdcheck <- function( error_on <- match.arg(error_on, c("never", "error", "warning", "note")) - if (file.info(path)$isdir) { + if (safecheck_isdir(path)) { path <- find_package_root_file(path = path) } else { path <- normalizePath(path) diff --git a/R/utils.R b/R/utils.R index 40d19de..76f0453 100644 --- a/R/utils.R +++ b/R/utils.R @@ -213,3 +213,10 @@ data_literal <- function(...) { colClasses = "character" ) } + +safecheck_isdir <- function(path){ + if(!file.exists(path)) stop("path '", path, "' does not exist!") + res <- file.info(path, extra_cols = FALSE) + if(is.na(res$isdir)) stop("path '", path, "' is not readable!") + res$isdir +} diff --git a/tests/testthat/test-errors.R b/tests/testthat/test-errors.R index 17eb7ae..3a57633 100644 --- a/tests/testthat/test-errors.R +++ b/tests/testthat/test-errors.R @@ -73,3 +73,7 @@ test_that("error_on argument", { tryCatch(rcmdcheck(), error = function(e) e) expect_equal(value, "note") }) + +test_that("error correctly when reading invalid files", { + expect_error(rcmdcheck("Invalid file name"), "path 'Invalid file name' does not exist!") +})