Skip to content

Ignore NAs when pruning cache files#859

Closed
hadley wants to merge 1 commit into
mainfrom
fix-cache-prune-na
Closed

Ignore NAs when pruning cache files#859
hadley wants to merge 1 commit into
mainfrom
fix-cache-prune-na

Conversation

@hadley

@hadley hadley commented Jul 1, 2026

Copy link
Copy Markdown
Member

file.info() returns NA for files it can't stat, which happens when a cache file is deleted (e.g. by another process, or an OS temp cleaner) between when cache_info() lists it with dir() and when it stats it. These NAs propagated into to_remove:

  • if (any(to_remove)) errors with "missing value where TRUE/FALSE needed" when there's an NA but no TRUE.
  • Where there is a TRUE, info[!to_remove, ] turns NA-indexed rows into all-NA rows, corrupting later pruning passes.

cache_prune_files() now coerces NA entries in to_remove to FALSE, leaving such files in place.

🤖 Generated with Claude Code

`file.info()` returns `NA` for files that can't be stat'd, which happens
when a cache file is deleted between listing and stat'ing it. This
propagated into `to_remove`, causing `if (any(to_remove))` to error or
corrupt the returned `info`. Now coerce `NA` to `FALSE`.
@jeroen

jeroen commented Jul 1, 2026

Copy link
Copy Markdown
Member

What leads to this is info being a zero-row data frame:

Browse[1]> info
[1] name  size  mtime
<0 rows> (or 0-length row.names)

Browse[1]> info$mtime + max$age
POSIXct of length 0

Browse[1]> info$mtime + max$age < Sys.time()
[1] NA

@hadley

hadley commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

Hmmmm, but

.POSIXct(numeric())
#> POSIXct of length 0
.POSIXct(numeric()) < Sys.time()
#> logical(0)

Created on 2026-07-01 with reprex v2.1.1

@jeroen

jeroen commented Jul 1, 2026

Copy link
Copy Markdown
Member

Okay so here is the full reproducer for completeness:

unlink(tools::R_user_dir("gh", which = 'cache'), recursive = TRUE)

library(messydates) # Breaks date comparisons!
gh::gh('/repos/cran/manydata')

The bug is in the messydates package which when loaded changes behavior of date comparisons:

numeric() < Sys.Date()
# logical(0)

library(messydates)
numeric() < Sys.Date()
# [1] NA

@hadley

hadley commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

Seems like this isn't httr2's problem to fix 😄

@hadley hadley closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants