Skip to content

Commit

Permalink
Merge pull request #125 from mrc-ide/use-files-from-disk
Browse files Browse the repository at this point in the history
Use existing files on disk instead of pushing afresh
  • Loading branch information
r-ash authored Mar 1, 2024
2 parents 4a060c1 + fb4655d commit 2cf7d79
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orderly2
Title: Orderly Next Generation
Version: 1.99.12
Version: 1.99.13
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Robert", "Ashton", role = "aut"),
Expand Down
10 changes: 8 additions & 2 deletions R/location.R
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ location_build_pull_plan_packets <- function(packet_id, recursive, root, call) {
index <- root$index$data()
if (recursive) {
full <- find_all_dependencies(packet_id, index$metadata)
n_extra <- length(full) - length(packet_id)
} else {
full <- packet_id
}
Expand Down Expand Up @@ -801,10 +800,17 @@ location_pull_files <- function(files, root) {
cli::cli_alert_info("Looking for suitable files already on disk")
store <- temporary_filestore(root)
cleanup <- function() store$destroy()
for (hash in files$hash) {
on_disk <- vlapply(files$hash, function(hash) {
exists <- FALSE
if (!is.null(path <- find_file_by_hash(root, hash))) {
store$put(path, hash)
exists <- TRUE
}
exists
})
if (any(on_disk)) {
cli::cli_alert_success("Found {sum(on_disk)} file{?s} on disk")
files <- files[!on_disk, , drop = FALSE]
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-location.R
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,26 @@ test_that("skip files in the file store", {
})


test_that("skip files known elsewhere on disk", {
root <- list()
for (name in c("src", "dst")) {
root[[name]] <- create_temporary_root(use_file_store = FALSE)
}

id <- create_random_packet_chain(root$src, 3)
orderly_location_add("src", "path", list(path = root$src$path),
root = root$dst)
orderly_location_pull_metadata(root = root$dst)
suppressMessages(orderly_location_pull_packet(id[[1]], root = root$dst))

res <- testthat::evaluate_promise(
orderly_location_pull_packet(id[[2]], root = root$dst))
expect_match(res$messages, "Found 1 file on disk", all = FALSE)
expect_match(res$messages, "Need to fetch 2 files.+from 1 location",
all = FALSE)
})


test_that("can prune orphans from tree", {
root <- list()
for (name in c("here", "there")) {
Expand Down

0 comments on commit 2cf7d79

Please sign in to comment.