Skip to content

Fix snapshot cleanup deleting .new files for multi-dot filenames - #2355

Open
jadhavgaurav wants to merge 1 commit into
r-lib:mainfrom
jadhavgaurav:fix/snapshot-cleanup-multidot
Open

jadhavgaurav wants to merge 1 commit into
r-lib:mainfrom
jadhavgaurav:fix/snapshot-cleanup-multidot

Conversation

@jadhavgaurav

Copy link
Copy Markdown

Problem

expect_snapshot_file() with a snapshot name containing more than one dot (for example tc12.2_image_annotate.html) has its .new comparison file deleted by the next snapshot cleanup, so snapshot_review() has nothing to show.

Root cause

new_name() in R/snapshot-file.R (used when the .new file is created) splits a filename via split_path(), which finds the first dot with regexpr(".", name, fixed = TRUE). For tc12.2_image_annotate.html this produces tc12.new.2_image_annotate.html.

snapshot_expected() in R/snapshot-cleanup.R (used during cleanup to decide which files are still expected) instead built the .new name with tools::file_path_sans_ext() / tools::file_ext(), which split on the last dot. For the same filename that predicts tc12.2_image_annotate.new.html.

Since the predicted name never matches the file that was actually created, cleanup treats the real .new file as unused and deletes it.

Fix

snapshot_expected() now calls new_name() directly instead of re-deriving the .new name with a different, inconsistent splitting convention. Both sides of the comparison are now guaranteed to agree because they're the same code.

Testing

Added a regression test in tests/testthat/test-snapshot-cleanup.R using a multi-dot snapshot name. Verified it fails on the unmodified source (flags the real .new file as outdated) and passes with the fix. Ran the full existing test suite (pkgload::load_all() + testthat::test_file() per file, since the parallel callr-based runner doesn't start in this sandbox); 1041 pre-existing tests pass unmodified, 3 pre-existing failures reproduce identically with and without this change (they depend on running inside the package's own R CMD check/devtools::test() process context, e.g. testing_package() and topenv() checks, not on anything touched here).

Fixes #2326

snapshot_expected() split snapshot filenames on the last dot via
tools::file_path_sans_ext()/tools::file_ext() to predict the .new
variant, while new_name() (used when the .new file is actually
created) splits on the first dot via split_path(). For a filename
like tc12.2_image_annotate.html this mismatch makes cleanup expect
tc12.2_image_annotate.new.html while the real file is named
tc12.new.2_image_annotate.html, so the real .new file is flagged as
unused and deleted.

snapshot_expected() now calls new_name() directly instead of
duplicating its splitting logic, so both sides always agree.

Fixes r-lib#2326

This branch has not been deployed

No deployments
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.

Snapshot .new files deleted for filenames with multiple dots

1 participant