Skip to content

Commit ab8bbd0

Browse files
author
Stefan Fleck
committed
safer backup discovery
1 parent f6a2b5b commit ab8bbd0

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

R/BackupQueue.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ get_backups <- function(
876876
if (!length(potential_backups))
877877
return(character())
878878

879-
sfx_patterns <- paste0("(", sfx_patterns, ")", collapse = "|")
879+
sfx_patterns <- paste0("(\\.", sfx_patterns, ")", collapse = "|")
880880

881881
file_dir <- dirname(origin)
882882
file_name <- basename(tools::file_path_sans_ext(origin))
@@ -890,7 +890,7 @@ get_backups <- function(
890890
)
891891
back_names <- basename(potential_backups)
892892

893-
sel <- grepl(file_name, back_names, fixed = TRUE)
893+
sel <- grepl(paste0(file_name, "."), back_names, fixed = TRUE)
894894
sel[regexpr(file_name, back_names, fixed = TRUE) != 1] <- FALSE
895895

896896
backups <- potential_backups[sel]

tests/testthat/test_rotate.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,26 @@ test_that("rotate works with funky filenames", {
179179
prune_backups(tf, 0)
180180
expect_length(list_backups(tf), 0)
181181
})
182+
183+
184+
185+
186+
test_that("rotate works with funky filenames 2", {
187+
td2 <- file.path(td, "test")
188+
dir.create(td2)
189+
on.exit(unlink(td2, recursive = TRUE))
190+
191+
tfs <- file.path(td2, c(
192+
"2021.zip",
193+
"2021.q1.zip",
194+
"2021.q1.test.zip",
195+
"2021.q1.test.1.zip"
196+
))
197+
198+
file.create(tfs)
199+
on.exit(unlink(td2, recursive = TRUE))
200+
201+
expect_length(list_backups(tfs[[1]]), 0L)
202+
expect_lengt(list_backups(tfs[[2]]), 0L)
203+
epect_length(list_backups(tfs[[3]]), 1L)
204+
})

0 commit comments

Comments
 (0)