Skip to content

Commit

Permalink
better handle very old and latest snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelru committed Aug 29, 2024
1 parent 805e2c8 commit e18797f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/get_ref.R
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ get_avail_date <- function(remote_ref, start = get_release_date(remote_ref)) {
}

#' @rdname get_avail_date
#'
#' @importFrom pkgcache ppm_snapshots
#'
#' @export
#'
#' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != ""
Expand All @@ -606,8 +609,13 @@ get_avail_date.remote_ref_cran <- function(remote_ref, start = get_release_date(
i <- 0
date <- start
while (i <= max_iter) {
# there are some gaps in the snapshots so it's important to at first find the closest date
ppm_url <- get_ppm_snapshot_by_date(date)
date <- unname(as.Date(sub(".*/", "", ppm_url)))
date <- `if`(
grepl("/latest$", ppm_url),
tail(pkgcache::ppm_snapshots(), 1)$date,
unname(as.Date(sub(".*/", "", ppm_url)))
)
data <- available.packages(
repos = ppm_url,
filters = list(function(db) db[db[, "Package"] == remote_ref$package, ])
Expand Down
3 changes: 3 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ get_ppm_snapshot_by_date <- function(date = NA) {
if (date >= tail(pkgcache::ppm_snapshots(), 1)$date) {
return(pkgcache::repo_resolve("PPM@latest"))
}
if (date <= head(pkgcache::ppm_snapshots(), 1)$date) {
return(pkgcache::repo_resolve(sprintf("PPM@%s", head(pkgcache::ppm_snapshots(), 1)$date)))
}
tryCatch(
pkgcache::repo_resolve(sprintf("PPM@%s", as.character(as.Date(date) + 1))),
error = function(err) {
Expand Down

0 comments on commit e18797f

Please sign in to comment.