Skip to content

Commit

Permalink
fixed R package repo state, when files are not available any more
Browse files Browse the repository at this point in the history
this catches problems, when files are manually deleted, especially newest version files.
  • Loading branch information
FelixErnst committed Jun 10, 2020
1 parent fe6f9ca commit 5b59d5e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
importFrom(tools, "write_PACKAGES")
importFrom(tools, "write_PACKAGES", "update_PACKAGES")
importFrom(utils, "untar", "unzip", "contrib.url")
export(addRepo,
initRepo,
Expand All @@ -7,5 +7,6 @@ export(addRepo,
getRepoInfo,
pruneRepo,
pruneRepoForAllRversions,
updateRepo,
archivePackages,
archivePackagesForAllRversions)
7 changes: 7 additions & 0 deletions R/insertPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ insertPackage <- function(file,
invisible(NULL)
}

.get_write_PACKAGES_type <- function(pkgtype){
split_pkgtype <- strsplit(pkgtype,"\\.")[[1L]]
write_pkgtype <- paste(split_pkgtype[seq.int(1L,min(2L,length(split_pkgtype)))],
collapse = ".")
write_pkgtype
}

##' @rdname insertPackage
insertPackages <- function(file, ...){
invisible(lapply(file, insertPackage, ...))
Expand Down
31 changes: 28 additions & 3 deletions R/pruneRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
##' Given a package name, R will always find the newest version of
##' that package. Older versions are therefore effectively shadowed
##' and can be removed without functionally changing a repository.
##'
##' However, if a current package file is removed without \code{pruneRepo}, the
##' PACKAGES, PACKAGES.gz and PACKAGES.rds file might be not up to date. To
##' ensure the correct information is available in these indices, run
##' \code{updateRepo}.
##'
##' This function is still undergoing development and polish and may
##' These functions are still undergoing development and polish and may
##' change in subsequent versions.
##'
##' @name pruneRepo
Expand All @@ -31,7 +36,7 @@
##' files should be removed. Nothing happens if \sQuote{FALSE}. If
##' different from (logical) \sQuote{FALSE} and equal to character
##' \dQuote{git} files are removed via \code{git rm} else via a
##' straight file deletion.
##' straight file deletion.
##' @return A data frame describing the repository is returned
##' containing columns with columns \dQuote{file},
##' \dQuote{package} (just the name), \dQuote{version} and a
Expand Down Expand Up @@ -159,6 +164,7 @@ pruneRepo <- function(repopath = getOption("dratRepo", "~/git/drat"),
} else {
mapply(.prune_cmd, rmfiles$contrib.url, rmfiles$file)
}
updateRepo(repopath, type = unique(rmfiles$type), version = version)
repoinfo <- repoinfo[repoinfo[,"newest"],]
}
invisible(repoinfo)
Expand All @@ -182,4 +188,23 @@ pruneRepoForAllRversions <- function(repopath = getOption("dratRepo", "~/git/dra
remove = FALSE){
pruneRepo(repopath = repopath, type = type, pkg = pkg, version = NA,
remove = remove)
}
}

##' @rdname pruneRepo
updateRepo <- function(repopath = getOption("dratRepo", "~/git/drat"),
type = c("source", "mac.binary", "mac.binary.el-capitan",
"mac.binary.mavericks", "win.binary", "both"),
version = NA){
# input check
type <- .norm_type(type)
#
repodir <- contrib.url2(repopath, type, version)
repodir <- repodir[dir.exists(repodir)]
.update_packages_index(repodir)
}

.update_packages_index <- function(contrib.url, strict = FALSE){
udpate_pkgtype <- lapply(names(contrib.url),.get_write_PACKAGES_type)
update <- mapply(update_PACKAGES, dir = contrib.url, type = udpate_pkgtype)
invisible(NULL)
}
15 changes: 14 additions & 1 deletion man/pruneRepo.Rd

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

0 comments on commit 5b59d5e

Please sign in to comment.