Skip to content

Commit 07a988b

Browse files
committed
mirror.packages: download newer versions
Only skip downloading a package if it already has the right version and MD5sum (in case of binary rebuilds). When downloading a new version of the package, remove the old one. This should help ensure that the source packages mirrored from CRAN are as new as binaries (or newer), which install.packages(type = "both") assumes when resolving dependencies.
1 parent 0f166cb commit 07a988b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

.ci/ci.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ function(pkgs,
155155
db <- utils::available.packages(repos.url, type = type)
156156
allpkgs <- c(pkgs, unlist(tools::package_dependencies(unique(pkgs), db, which, recursive = TRUE), use.names = FALSE))
157157
except <- c("R", unlist(tools:::.get_standard_package_names()[except.priority], use.names = FALSE))
158-
## do not re-download existing packages, ignore version
158+
## do not re-download existing packages with the right version
159159
if (length(except.repodir) && file.exists(file.path(contrib.url(except.repodir, type = type, ver = binary.ver), "PACKAGES"))) {
160160
except.curl <- contrib.url(file.path("file:", normalizePath(except.repodir)), type = type, ver = binary.ver)
161-
except <- c(except, rownames(utils::available.packages(except.curl, type = type, fields = "Package")))
161+
except.db <- utils::available.packages(except.curl, type = type, fields = "Package")
162+
except <- c(except, merge(db, except.db, by = c("Package", "Version", "MD5sum"))[,"Package"])
162163
}
163164
newpkgs <- setdiff(allpkgs, except)
164165
if (!all(availpkgs<-newpkgs %in% rownames(db))) {
@@ -174,6 +175,13 @@ function(pkgs,
174175
"source" = "tar.gz",
175176
"mac.binary" = "tgz",
176177
"win.binary" = "zip")
178+
## clean up stale package files for which new versions will be downloaded
179+
if (file.exists(file.path(destdir, "PACKAGES"))) {
180+
repo.db <- utils::available.packages(file.path("file:", normalizePath(destdir)), type = type)
181+
oldver <- repo.db[repo.db[, "Package"] %in% newpkgs, c("Package", "Version"), drop=FALSE]
182+
oldfiles <- file.path(destdir, sprintf("%s_%s.%s", oldver[,"Package"], oldver[,"Version"], pkgsext))
183+
unlink(oldfiles[file.exists(oldfiles)])
184+
}
177185
pkgsver <- db[db[, "Package"] %in% newpkgs, c("Package", "Version"), drop=FALSE]
178186
dlfiles <- file.path(destdir, sprintf("%s_%s.%s", pkgsver[,"Package"], pkgsver[,"Version"], pkgsext))
179187
unlink(dlfiles[file.exists(dlfiles)])

0 commit comments

Comments
 (0)