Skip to content

Commit 33a69c3

Browse files
author
Stefan Fleck
committed
rotate(), backup() and co no longer fail on filenames that contain special regex characters (such as * or +)
1 parent fb6917d commit 33a69c3

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: rotor
33
Title: Log Rotation and Conditional Backups
4-
Version: 0.3.5
4+
Version: 0.3.5.9000
55
Authors@R:
66
person(given = "Stefan",
77
family = "Fleck",

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# rotor (dev)
2+
3+
* `rotate()`, `backup()` and co no longer fail on filenames that
4+
contain special regex characters (such as `*` or `+`)
5+
6+
17
# rotor 0.3.5
28

39
* Backups now retain their original timestamp (created, last modified) where

R/BackupQueue.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ filenames_as_matrix <- function(
837837
back_names <- basename(backups)
838838

839839
filename_end <-
840-
attr(gregexpr(file_name, back_names[[1]])[[1]], "match.length") + 1L
840+
attr(gregexpr(file_name, back_names[[1]], fixed = TRUE)[[1]], "match.length") + 1L
841841

842842
a <- strsplit_at_seperator_pos(back_names, filename_end)
843843
assert(
@@ -890,7 +890,9 @@ get_backups <- function(
890890
)
891891
back_names <- basename(potential_backups)
892892

893-
sel <- grepl(paste0("^", file_name), back_names)
893+
sel <- grepl(file_name, back_names, fixed = TRUE)
894+
sel[regexpr(file_name, back_names, fixed = TRUE) != 1] <- FALSE
895+
894896
backups <- potential_backups[sel]
895897
back_names <- basename(backups)
896898

tests/testthat/test_BackupQueue.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,28 @@ test_that("BackupQueue finding backups works as expected for files without exten
143143

144144

145145

146+
test_that("BackupQueue finding backups works on files with regex characters", {
147+
dir.create(td, recursive = TRUE)
148+
on.exit(unlink(td, recursive = TRUE))
149+
150+
tf <- file.path(td, "test+-[(")
151+
file.create(tf)
152+
153+
expect_identical(n_backups(tf), 0L)
154+
bq <- BackupQueue$new(tf)
155+
156+
sfxs <-c(1:12, "2019-12-31")
157+
bus <- paste0(tools::file_path_sans_ext(tf), ".", sfxs)
158+
file.create(bus)
159+
160+
expect_path_setequal(bq$files$path, bus)
161+
expect_setequal(bq$files$sfx, sfxs)
162+
expect_setequal(bq$files$ext, "")
163+
})
164+
165+
166+
167+
146168
test_that("dryrun/verbose prune", {
147169
dir.create(td, recursive = TRUE)
148170
on.exit(unlink(td, recursive = TRUE))

0 commit comments

Comments
 (0)