Skip to content

Commit

Permalink
ensure rotate, backup and co. work with hidden files
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fleck committed Feb 7, 2021
1 parent 33a69c3 commit e802fb4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# rotor (dev)

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


# rotor 0.3.5
Expand Down
2 changes: 1 addition & 1 deletion R/BackupQueue.R
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ BackupQueueIndex <- R6::R6Class(
tools::file_path_sans_ext(basename(self$origin))
)
ext <- tools::file_ext(self$origin)
sfx <- "1"
sfx <- "1" # the new file will always have the 1 suffix, the old ones are incremented
if (is_blank(ext)) {
name_new <- paste(name, sfx, sep = ".")
} else {
Expand Down
4 changes: 2 additions & 2 deletions R/Cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Cache <- R6::R6Class(
#' @description purge the cache (remove all cached files)
destroy = function(
){
files <- list.files(self$dir, recursive = TRUE, all.files = TRUE)
files <- list.files(self$dir, recursive = TRUE, all.files = TRUE, no.. = TRUE)
assert(!length(files), DirIsNotEmptyError(dir = self$dir))

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

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

if (!length(files)){
return(EMPTY_CACHE_INDEX)
Expand Down
2 changes: 1 addition & 1 deletion R/DirectoryQueue.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ DirectoryQueue <- R6::R6Class(

files = function(){

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

if (!length(files)){
return(data.frame())
Expand Down
2 changes: 1 addition & 1 deletion R/DryRunMemory.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DryRunMemory <- R6::R6Class(


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

Expand Down
6 changes: 4 additions & 2 deletions R/utils-fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ list_files <- function(
full.names = FALSE,
...,
dry_run = DRY_RUN$active,
verbose = dry_run
verbose = dry_run,
all.files = TRUE,
no.. = TRUE
){
if (dry_run) {
res <- DRY_RUN$list(path, ...)
if (!full.names) res <- basename(res)
return(res)
}

list.files(path = path, full.names = full.names, ...)
list.files(path = path, full.names = full.names, ..., no.. = no.., all.files = all.files)
}


Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test_rotate.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,27 @@ test_that("BackupQueueIndex: $prune_identical works", {
unname(c(cars_md5, iris_md5))
)
})





test_that("rotate works with funky filenames", {
td2 <- file.path(td, "test")
dir.create(td2)
on.exit(unlink(td2, recursive = TRUE))

fn <- "...one long incredibly unbroken sentence ... xzy12+-.test.ext"

tf <- file.path(td2, fn)
saveRDS(iris, tf)
expect_true(file.exists(tf))

rotate(tf)
rotate(tf, verbose = TRUE, size = 0)

expect_length(list_backups(tf), 2)
expect_match(basename(list_backups(tf)),".*\\.[1,2]\\.ext$")
prune_backups(tf, 0)
expect_length(list_backups(tf), 0)
})

0 comments on commit e802fb4

Please sign in to comment.