Skip to content

Commit

Permalink
Check for files, not directory
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jun 7, 2024
1 parent 4c14281 commit 588a559
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
1 change: 1 addition & 0 deletions Hi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/tmp/RtmpnPKaoc/filec11448ecabfd/README.md
26 changes: 24 additions & 2 deletions R/clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,34 @@ clean_site <- function(pkg = ".", quiet = FALSE) {

if (!dir_exists(pkg$dst_path)) return(invisible())

top_level <- dir_ls(pkg$dst_path)
top_level <- top_level[!path_file(top_level) %in% c("CNAME", "dev")]
check_dest_is_pkgdown(pkg)
top_level <- dest_files(pkg)

is_dir <- is_dir(top_level)
dir_delete(top_level[is_dir])
file_delete(top_level[!is_dir])

invisible(TRUE)
}

check_dest_is_pkgdown <- function(pkg) {
if (file_exists(path(pkg$dst_path, "pkgdown.yml"))) {
return()
}

cli::cli_abort(c(
"{.file {pkg$dst_path}} is non-empty and not built by pkgdown",
"!" = "Make sure it contains no important information \\
and use {.run pkgdown::clean_site()} to delete its contents."
)
)
}

dest_files <- function(pkg) {
if (!dir_exists(pkg$dst_path)) {
character()
} else {
top_level <- dir_ls(pkg$dst_path)
top_level[!path_file(top_level) %in% c("CNAME", "dev")]
}
}
23 changes: 2 additions & 21 deletions R/context.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ section_init <- function(pkg,
rstudio_save_all()
pkg <- as_pkgdown(pkg, override = override)

if (dir_exists(pkg$dst_path)) {
check_dest_is_pkgdown(pkg)
if (length(dest_files(pkg)) > 0) {
check_dest_is_pkgdown(pkg)
} else {
init_site(pkg)
}
Expand All @@ -24,25 +24,6 @@ section_init <- function(pkg,
pkg
}

check_dest_is_pkgdown <- function(pkg) {
top_level <- dir_ls(pkg$dst_path)
top_level <- top_level[!path_file(top_level) %in% c("CNAME", "dev", "deps")]
if (length(top_level) == 0) {
return(invisible())
}

if ("pkgdown.yml" %in% path_file(top_level)) {
return(invisible())
}

cli::cli_abort(c(
"{.file {pkg$dst_path}} is non-empty and not built by pkgdown",
"!" = "Make sure it contains no important information \\
and use {.run pkgdown::clean_site()} to delete its contents."
)
)
}

local_options_link <- function(pkg, depth, .frame = parent.frame()) {
article_index <- article_index(pkg)
Rdname <- get_rdname(pkg$topics)
Expand Down

0 comments on commit 588a559

Please sign in to comment.