Skip to content

Commit e802fb4

Browse files
committed
ensure rotate, backup and co. work with hidden files
1 parent 33a69c3 commit e802fb4

7 files changed

Lines changed: 35 additions & 8 deletions

File tree

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# rotor (dev)
22

3-
* `rotate()`, `backup()` and co no longer fail on filenames that
3+
* `rotate()`, `backup()` and co. no longer fail on filenames that
44
contain special regex characters (such as `*` or `+`)
5+
* `rotate()`, `backup()` and co. now work with hidden files
56

67

78
# rotor 0.3.5

R/BackupQueue.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ BackupQueueIndex <- R6::R6Class(
292292
tools::file_path_sans_ext(basename(self$origin))
293293
)
294294
ext <- tools::file_ext(self$origin)
295-
sfx <- "1"
295+
sfx <- "1" # the new file will always have the 1 suffix, the old ones are incremented
296296
if (is_blank(ext)) {
297297
name_new <- paste(name, sfx, sep = ".")
298298
} else {

R/Cache.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Cache <- R6::R6Class(
189189
#' @description purge the cache (remove all cached files)
190190
destroy = function(
191191
){
192-
files <- list.files(self$dir, recursive = TRUE, all.files = TRUE)
192+
files <- list.files(self$dir, recursive = TRUE, all.files = TRUE, no.. = TRUE)
193193
assert(!length(files), DirIsNotEmptyError(dir = self$dir))
194194

195195
unlink(self$dir, recursive = TRUE)
@@ -330,7 +330,7 @@ Cache <- R6::R6Class(
330330
#' [base::file.info()] returns
331331
files = function(){
332332

333-
files <- list.files(self$dir, full.names = TRUE)
333+
files <- list.files(self$dir, full.names = TRUE, all.files = TRUE, no.. = TRUE)
334334

335335
if (!length(files)){
336336
return(EMPTY_CACHE_INDEX)

R/DirectoryQueue.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ DirectoryQueue <- R6::R6Class(
7979

8080
files = function(){
8181

82-
files <- list.files(self$dir, full.names = TRUE)
82+
files <- list.files(self$dir, full.names = TRUE, all.files = TRUE, no.. = TRUE,)
8383

8484
if (!length(files)){
8585
return(data.frame())

R/DryRunMemory.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ DryRunMemory <- R6::R6Class(
2626

2727

2828
list = function(path){
29-
x <- path_standardize(list.files(path, full.names = TRUE))
29+
x <- path_standardize(list.files(path, full.names = TRUE, all.files = TRUE, no.. = TRUE))
3030
unique(self$fake(x))
3131
},
3232

R/utils-fs.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,17 @@ list_files <- function(
8888
full.names = FALSE,
8989
...,
9090
dry_run = DRY_RUN$active,
91-
verbose = dry_run
91+
verbose = dry_run,
92+
all.files = TRUE,
93+
no.. = TRUE
9294
){
9395
if (dry_run) {
9496
res <- DRY_RUN$list(path, ...)
9597
if (!full.names) res <- basename(res)
9698
return(res)
9799
}
98100

99-
list.files(path = path, full.names = full.names, ...)
101+
list.files(path = path, full.names = full.names, ..., no.. = no.., all.files = all.files)
100102
}
101103

102104

tests/testthat/test_rotate.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,27 @@ test_that("BackupQueueIndex: $prune_identical works", {
155155
unname(c(cars_md5, iris_md5))
156156
)
157157
})
158+
159+
160+
161+
162+
163+
test_that("rotate works with funky filenames", {
164+
td2 <- file.path(td, "test")
165+
dir.create(td2)
166+
on.exit(unlink(td2, recursive = TRUE))
167+
168+
fn <- "...one long incredibly unbroken sentence ... xzy12+-.test.ext"
169+
170+
tf <- file.path(td2, fn)
171+
saveRDS(iris, tf)
172+
expect_true(file.exists(tf))
173+
174+
rotate(tf)
175+
rotate(tf, verbose = TRUE, size = 0)
176+
177+
expect_length(list_backups(tf), 2)
178+
expect_match(basename(list_backups(tf)),".*\\.[1,2]\\.ext$")
179+
prune_backups(tf, 0)
180+
expect_length(list_backups(tf), 0)
181+
})

0 commit comments

Comments
 (0)