Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# httr2 (development version)

* `req_cache()` pruning no longer errors if a cache file is deleted while the cache is being pruned.

# httr2 1.2.3

* Mocked and cached responses now include the originating request in `resp$request`, just like real responses (#841).
Expand Down
2 changes: 2 additions & 0 deletions R/req-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ cache_info <- function(path, pattern = "\\.rds$") {
}

cache_prune_files <- function(info, to_remove, why, debug = TRUE) {
to_remove[is.na(to_remove)] <- FALSE

if (any(to_remove)) {
if (debug) {
cli::cli_text("Deleted {sum(to_remove)} file{?s} that {?is/are} {why}")
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-req-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ test_that("can prune by size", {
expect_equal(dir(path), "c.rds")
})

test_that("cache_prune_files ignores NAs in to_remove", {
info <- data.frame(name = c("a", "b"), size = 1, mtime = Sys.time())
expect_equal(cache_prune_files(info, c(NA, FALSE), "x", debug = FALSE), info)
})

# headers -----------------------------------------------------------------

test_that("correctly determines if response is cacheable", {
Expand Down
Loading