Skip to content

Commit

Permalink
Use existing files on disk instead of pushing afresh
Browse files Browse the repository at this point in the history
  • Loading branch information
r-ash committed Feb 29, 2024
1 parent 4a060c1 commit 44c8e0c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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, ]
}
}

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 44c8e0c

Please sign in to comment.