Ignore NAs when pruning cache files#859
Closed
hadley wants to merge 1 commit into
Closed
Conversation
`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`.
Member
|
What leads to this is 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 |
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 |
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 numeric() < Sys.Date()
# logical(0)
library(messydates)
numeric() < Sys.Date()
# [1] NA |
Member
Author
|
Seems like this isn't httr2's problem to fix 😄 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
file.info()returnsNAfor files it can't stat, which happens when a cache file is deleted (e.g. by another process, or an OS temp cleaner) between whencache_info()lists it withdir()and when it stats it. TheseNAs propagated intoto_remove:if (any(to_remove))errors with "missing value where TRUE/FALSE needed" when there's anNAbut noTRUE.TRUE,info[!to_remove, ]turnsNA-indexed rows into all-NArows, corrupting later pruning passes.cache_prune_files()now coercesNAentries into_removetoFALSE, leaving such files in place.🤖 Generated with Claude Code