Conversation
Within a session, this should avoid recomputing file hashes where the file size and mtime have not changed. This exploits remake's internal caching, which is not tested in this commit (and this entirely lacks any sort of integration test). For #110
krlmlr
left a comment
There was a problem hiding this comment.
Looks good, thanks.
| expect_equal(st$db$get(filename)$hash, h) | ||
|
|
||
| ## Does not call back to the underlying hash function: | ||
| with_mock("hash_files" = lava, |
There was a problem hiding this comment.
Need to set "remake::hash_files" so that tests work in R CMD check. (Don't know why.)
| expect_false(st$exists(file)) | ||
| }) | ||
|
|
||
| test_that("caching file store", { |
There was a problem hiding this comment.
How about splitting the test so that each test_that() call tests only one aspect of the behavior?
There was a problem hiding this comment.
Yeah, that would be better style. It can get a bit tedious though as there's so much side effect heavy bits here (remake is basically all side effect)
| ## Then, we could change the file *size* and force rehashing. | ||
| writeBin(bytes[-1], filename) | ||
| h2 <- digest::digest(bytes[-1], serialize = FALSE) | ||
| with_mock("hash_files" = lava, |
| self$db$set(filename, info) | ||
| info$hash | ||
| } else { | ||
| stop(sprintf("file %s not found in file store", filename)) |
There was a problem hiding this comment.
Handling abnormal conditions first saves one indent, but that's a matter of style.
| )) | ||
|
|
||
| file_info <- function(filename) { | ||
| info <- file.info(filename, extra_cols = FALSE) |
There was a problem hiding this comment.
Does this function support len(filename) != 1? How about renaming to file_mtime_and_size() or similar?
| } | ||
| } | ||
| info$hash <- hash_files(filename, named = FALSE) | ||
| self$db$set(filename, info) |
There was a problem hiding this comment.
Would inserting the whole object at once provide better encapsulation?
self$db$set(filename, list(info = info))
Within a session, this should avoid recomputing file hashes where the file size and mtime have not changed. This exploits remake's internal caching.
Fixes #110.