Skip to content

Commit

Permalink
Fix random download of source tarball instead of binary (#47)
Browse files Browse the repository at this point in the history
# Pull Request

- Closes #44 

Part of insightsengineering/coredev-tasks#546

Upstream bug: r-lib/pkgdepends#367

#### Changes description:

- Removes sources links that include "src/contrib/Archive"
- When `{pkgdepends}` attempts to download the tarball, it will try all
sources and archive-based sources are only source-code
- Re-downloads tarball using mirror.
  - Last attempt to explicitly use `ppm` snapshot mirror

#### Testing

1. Install or load this branch
-
`renv::install("insightsengineering/verdepcheck@fix-random-download%40main")`
3. Clone
[`{tmc}`](https://github.com/insightsengineering/teal.modules.clinical)
    - checkout `546-fix-verdepcheck@main` branch
5. Run all strategies:
    - `verdepcheck::min_cohort_deps_check("/path/to/tmc")`
    - `verdepcheck::min_isolated_deps_check("/path/to/tmc")`
    - `verdepcheck::release_deps_check("/path/to/tmc")`
    - `verdepcheck::max_deps_check("/path/to/tmc")`
  • Loading branch information
averissimo authored Jun 6, 2024
1 parent ca6e4bf commit 644a5b8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
50 changes: 50 additions & 0 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,59 @@ execute_ip <- function(ip, path, build_args, check_args, ...) {
#'
#' @export
download_ip <- function(ip) {
res <- ip$get_resolution()

# Prevent downloads of non-binary files by removing source that has "Archive" in the URL
# Track issue: https://github.com/r-lib/pkgdepends/issues/367
ix <- res$platform == pkgdepends::current_r_platform()
new_sources <- lapply(
res$sources[ix],
function(x) {
if (length(x) > 1 && any(grepl("src/contrib/Archive", x))) {
x[!grepl("src/contrib/Archive", x)]
} else {
x
}
}
)
ip$.__enclos_env__$private$plan$.__enclos_env__$private$resolution$result$sources[ix] <- new_sources

ip$download()
ip$stop_for_download_error()

# Safety fallback that will try to download the binary again.
#
# note: that binary must be downloaded with relevant user agent with supported
# platform and R version.
for (ix_el in which(ix)) {
withr::with_tempdir(
code = {
tar_file <- file.path(ip$get_config()$get("cache_dir"), res$target[ix_el])

# Only do this for files that actually exist
if (!file.exists(tar_file)) next
utils::untar(tarfile = tar_file, exdir = "./")
tryCatch(
{
asNamespace("pkgdepends")$verify_extracted_package(res$package[ix_el], "./")
},
error = function(error) {
cli::cli_warn("{res$package[ix_el]} binary is not valid, trying to re-download.")
# Attempts to download again using {pkgcache} / {pkgdepends} http methods
async_fun <- asNamespace("pkgcache")$async(function() {
asNamespace("pkgcache")$download_file(
# Builds URL manually from mirror
url = file.path(res$mirror[ix_el], "src/contrib", basename(tar_file)),
destfile = tar_file
)
})
asNamespace("pkgcache")$synchronise(async_fun())
}
)
}
)
}

return(invisible(ip))
}

Expand Down
4 changes: 2 additions & 2 deletions R/get_ref.R
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ get_release_date.remote_ref_cran <- function(remote_ref) {
package_version(remote_ref$version, strict = FALSE)
)
)
as.Date(tail(rel_data[idx, "mtime"], 1))
as.Date(utils::tail(rel_data[idx, "mtime"], 1))
} else {
as.Date(tail(rel_data$mtime, 1))
as.Date(utils::tail(rel_data$mtime, 1))
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default_config <- function() {
)
}
append_config <- function(x1, x2) {
modifyList(x1, x2)
utils::modifyList(x1, x2)
}

#' @importFrom utils installed.packages
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The main functions are:
- `new_<strategy>_deps_installation_proposal` for creating `installation_proposal` objects
- `<strategy>_deps_check` that creates and executes `installation_proposal` and then run `"R CMD CHECK"`

This package is heavily based on [`pkgdepends`](https://r-lib.github.io/pkgdepends/) for dependency resolution and [`rcmdcheck`](https://r-lib.github.io/rcmdcheck/) for executing `"R CMD CHECK"`.
This package is heavily based on [`pkgdepends`](https://r-lib.github.io/pkgdepends/) for dependency resolution and [`rcmdcheck`](https://rcmdcheck.r-lib.org/) for executing `"R CMD CHECK"`.

## Install

Expand Down

0 comments on commit 644a5b8

Please sign in to comment.