Skip to content

Commit

Permalink
Add argument 'force' to clean(), clean.library(), and clean.software()
Browse files Browse the repository at this point in the history
  • Loading branch information
Arni Magnusson committed Apr 6, 2020
1 parent 7990a14 commit a2d3851
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ icesTAF 3.4-0 (2020-03-27)

* Added function taf.session() to show session information.

* Added argument 'force' to clean(), clean.library(), and clean.software().

* Added argument 'ignore' to cp().

* Improved clean.software() to remove software folder, not just software files.

* Improved download.github() to store GitHub metadata in the DESCRIPTION file,
if the GitHub resource is an R package. Warn if the tar.gz file looks like an
R package nested inside a repository.
Expand Down
17 changes: 8 additions & 9 deletions R/clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' \verb{report}), \verb{bootstrap}, or other directories.
#'
#' @param dirs directories to delete.
#' @param force passed to \code{software} and \code{clean.library} if any of the
#' \code{dirs} is \code{"bootstrap"}.
#'
#' @note
#' The purpose of removing the directories is to make sure that subsequent TAF
Expand All @@ -17,16 +19,13 @@
#' \verb{bootstrap/initial} and \verb{*.bib} metadata files from being
#' accidentally deleted.
#'
#' The commands \code{clean("bootstrap/software")} and
#' \code{clean("bootstrap/library")} remove those directories completely.
#'
#' @seealso
#' \code{\link{clean.library}} selectively removes packages from
#' \verb{bootstrap/library}.
#'
#' \code{\link{clean.software}} selectively removes software from
#' \verb{bootstrap/software}.
#'
#' \code{\link{clean.library}} selectively removes packages from
#' \verb{bootstrap/library}.
#'
#' \code{\link{mkdir}} and \code{\link{rmdir}} create and remove empty
#' directories.
#'
Expand All @@ -39,7 +38,7 @@
#'
#' @export

clean <- function(dirs=c("data", "model", "output", "report"))
clean <- function(dirs=c("data", "model", "output", "report"), force=FALSE)
{
## Convert "bootstrap/" to "bootstrap", so clean("bootstrap/") doesn't go wild
dirs <- sub("/$", "", dirs)
Expand All @@ -48,8 +47,8 @@ clean <- function(dirs=c("data", "model", "output", "report"))
{
## An odd directory called 'library:' can appear in Linux
unlink(c("bootstrap/data", "bootstrap/library:"), recursive=TRUE)
clean.software("bootstrap/software")
clean.library("bootstrap/library")
clean.software("bootstrap/software", force=force)
clean.library("bootstrap/library", force=force)
dirs <- dirs[dirs != "bootstrap"]
}

Expand Down
6 changes: 4 additions & 2 deletions R/clean.library.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#'
#' @param folder location of local TAF library.
#' @param quiet whether to suppress messages about removed packages.
#' @param force whether to remove the local TAF library, regardless of how it
#' compares to SOFTWARE.bib entries.
#'
#' @note
#' For each package, the cleaning procedure selects between three cases:
Expand Down Expand Up @@ -39,11 +41,11 @@
#'
#' @export

clean.library <- function(folder="bootstrap/library", quiet=FALSE)
clean.library <- function(folder="bootstrap/library", quiet=FALSE, force=FALSE)
{
installed <- dir(folder)

if(!file.exists(file.path(folder, "../SOFTWARE.bib")))
if(!file.exists(file.path(folder, "../SOFTWARE.bib")) || force)
{
unlink(folder, recursive=TRUE)
}
Expand Down
11 changes: 7 additions & 4 deletions R/clean.software.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#'
#' @param folder location of local TAF software folder.
#' @param quiet whether to suppress messages about removed software.
#' @param force whether to remove the local TAF software folder, regardless of
#' how it compares to SOFTWARE.bib entries.
#'
#' @note
#' For each file (and subdirectory) in the software folder, the cleaning
Expand Down Expand Up @@ -39,11 +41,12 @@
#'
#' @export

clean.software <- function(folder="bootstrap/software", quiet=FALSE)
clean.software <- function(folder="bootstrap/software", quiet=FALSE,
force=FALSE)
{
software.files <- dir(folder, full.names=TRUE)

if(!file.exists(file.path(folder, "../SOFTWARE.bib")))
if(!file.exists(file.path(folder, "../SOFTWARE.bib")) || force)
{
unlink(folder, recursive=TRUE)
}
Expand All @@ -54,8 +57,8 @@ clean.software <- function(folder="bootstrap/software", quiet=FALSE)
for(file in software.files)
{
## Read sha.file, the SHA for a software file
pkg <- sub(".*/(.*)_.*", "\\1", file) # path/pkg_sha.tar.gz -> pkg
sha.file <- sub(".*_(.*?)\\..*", "\\1", file) # path/pkg_sha.tar.gz -> sha
pkg <- sub(".*/(.*)_.*", "\\1", file) # path/pkg_sha.tar.gz -> pkg
sha.file <- sub(".*_(.*?)\\..*", "\\1", file) # path/pkg_sha.tar.gz -> sha
## Read sha.bib, the corresponding SHA from SOFTWARE.bib
if(pkg %in% names(bib))
{
Expand Down
14 changes: 7 additions & 7 deletions man/clean.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/clean.library.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/clean.software.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2d3851

Please sign in to comment.