Skip to content

Commit

Permalink
Merge pull request #149 from mrc-ide/mrc-5495-writable
Browse files Browse the repository at this point in the history
Make files writable when they are exported.
  • Loading branch information
richfitz authored Jul 8, 2024
2 parents 1fd09ff + d872996 commit 195ffc5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
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.19
Version: 1.99.20
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Robert", "Ashton", role = "aut"),
Expand Down
5 changes: 5 additions & 0 deletions R/outpack_root.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ file_export <- function(root, id, there, here, dest, overwrite, call = NULL) {
}
fs::file_copy(there_full, here_full, overwrite)
}

# Files in the archive and file store are (generally) read-only.
# When exporting for interactive use, it's easier on the user if we make them
# writable again.
fs::file_chmod(here_full, "u+w")
}


Expand Down
30 changes: 30 additions & 0 deletions tests/testthat/test-outpack-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,33 @@ test_that("good error message if file not found in packet", {
i = "For 'd.txt' did you mean 'a.txt', 'b.txt' or 'c.txt'",
i = "Remember that all orderly paths are case sensitive"))
})


test_that("Can overwrite when copying files from packet", {
root <- create_temporary_root(use_file_store = TRUE)

id1 <- create_random_packet(root)
id2 <- create_random_packet(root)

# Just a bit of a sanity check. The two packets are random, so we'd expect
# them to have different contents.
expect_false(identical(
readRDS(file.path(root$path, "archive", "data", id1, "data.rds")),
readRDS(file.path(root$path, "archive", "data", id2, "data.rds"))))

dst <- temp_file()

suppressMessages(
orderly_copy_files(id1, files = "data.rds", dest = dst, root = root))

expect_identical(
readRDS(file.path(dst, "data.rds")),
readRDS(file.path(root$path, "archive", "data", id1, "data.rds")))

suppressMessages(
orderly_copy_files(id2, files = "data.rds", dest = dst, root = root))

expect_identical(
readRDS(file.path(dst, "data.rds")),
readRDS(file.path(root$path, "archive", "data", id2, "data.rds")))
})
17 changes: 17 additions & 0 deletions tests/testthat/test-outpack-packet.R
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,23 @@ test_that("Re-adding files triggers hash", {
})


test_that("Can detect changes to dependencies", {
root <- create_temporary_root()
id <- create_random_packet(root, "data")

path_src <- withr::local_tempdir()
p <- outpack_packet_start_quietly(path_src, "next", root = root)

outpack_packet_use_dependency(p, id, "data.rds")
saveRDS(1:10, file.path(path_src, "data.rds"))

err <- expect_error(
outpack_packet_end_quietly(p),
"File was changed after being added")
expect_equal(err$body, c(x = "data.rds"))
})


test_that("Can ignore files from the final packet", {
root <- create_temporary_root(path_archive = "archive", use_file_store = TRUE)
path_src <- create_temporary_simple_src()
Expand Down

0 comments on commit 195ffc5

Please sign in to comment.