Skip to content

Commit 45540a1

Browse files
author
Stefan Fleck
committed
merge changes from master
Merge branch 'master' of https://github.com/s-fleck/rotor # Conflicts: # DESCRIPTION # NEWS.md
2 parents 55a18e7 + b69ca26 commit 45540a1

File tree

7 files changed

+25
-47
lines changed

7 files changed

+25
-47
lines changed

DESCRIPTION

Lines changed: 2 additions & 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.2.9000
4+
Version: 0.3.4.9000
55
Authors@R:
66
person(given = "Stefan",
77
family = "Fleck",
@@ -27,6 +27,7 @@ Suggests:
2727
rmarkdown,
2828
testthat,
2929
uuid,
30+
ulid,
3031
zip
3132
Encoding: UTF-8
3233
LazyData: true

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* Backups now retain their original timestamp (created, last modified) where
44
possible (even when zipped)
55

6+
# rotor 0.3.4
7+
8+
* Hotfix for some tests related to the `Cache` R6 class that fail on systems
9+
with low-precision file system timestamps (such as ext3 and old Windows
10+
file systems)
611

712
# rotor 0.3.2
813

R/Cache.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ Cache <- R6::R6Class(
162162

163163
if (!is.null(max_size) && !is.infinite(max_size)){
164164
max_size <- parse_size(max_size)
165-
files <- files[order(files$mtime, decreasing = TRUE), ]
166-
files$cumsize <- cumsum(files$size)
165+
files$cumsize <- rev(cumsum(rev(files$size)))
167166
rem$size <- files[files$cumsize > max_size, ]
168167
}
169168

cran-comments.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,5 @@
1010

1111
0 errors | 0 warnings | 0 notes
1212

13-
Sorry for the many resubmissions. This package currently has an issue that
14-
only to occur on macOS. It does not occur on the same macOS version available
15-
on Rhub.
16-
17-
My current theory is that the error is caused by the accuracy of the
18-
'mtime' filestamp, which is linked to the file system the machine uses.
19-
I implemented a workaround under that assumption, but I cannot be 100% sure
20-
that this fixes that error. If the error still persists... could you please
21-
inform me which file system you use on r-release-macos-x86_64?
13+
More fixes for file-system timestamp related bugs that I could not reproduce on
14+
my test systems. Sorry again for all the trouble.

man/Cache.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_BackupQueue.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ test_that("BackupQueueIndex$push() can push to different directory", {
458458

459459

460460
test_that("BackupQueueIndex dry run doesnt modify file system", {
461+
try({unlink(td, recursive = TRUE)})
461462
dir.create(td, recursive = TRUE)
462463
on.exit(unlink(td, recursive = TRUE))
463464

tests/testthat/test_Cache.R

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ test_that("setting hash functions work", {
6060
expect_identical(cache_hash$n, 0L)
6161

6262

63-
# To override this behaviour use a generate for unique ids, such as
63+
# To override this behaviour use a function that generates globally unique ids instead of hashes
6464
cache_uid <- Cache$new(td, hashfun = function(x) ascending_id())
6565
cache_uid$push(iris)
6666
cache_uid$push(iris)
6767
expect_identical(cache_hash$n, 2L)
6868
cache_hash$purge()
6969

70-
# ensure hashfun allways returns a scalar
70+
# fail if hashfun does not returns a scalar
7171
cache_err <- Cache$new(td, hashfun = function(x) c(ascending_id(), ascending_id()))
7272
expect_error(cache_err$push(iris), class = "ValueError")
7373
})
@@ -86,6 +86,7 @@ test_that("pruning works by number of files works", {
8686
k3 <- cache$push(cars)
8787
expect_identical(cache$n, 3L)
8888

89+
# cached files are sorted in the order of their creation
8990
expect_identical(cache$files$key[[1]], k1)
9091
expect_identical(cache$files$key[[2]], k2)
9192
expect_identical(cache$files$key[[3]], k3)
@@ -98,7 +99,7 @@ test_that("pruning works by number of files works", {
9899

99100

100101

101-
test_that("pruning works by number of files sorts by key if timestamp are identical", {
102+
test_that("$files is ordered by key if timestamps are identical", {
102103
td <- file.path(tempdir(), "cache-test")
103104
on.exit(unlink(td, recursive = TRUE))
104105

@@ -125,26 +126,22 @@ test_that("pruning works by number of files sorts by key if timestamp are identi
125126

126127

127128

128-
test_that("pruning by size works", {
129+
test_that("pruning by size works, even if timestamps are identical", {
129130
td <- file.path(tempdir(), "cache-test")
130131
on.exit(unlink(td, recursive = TRUE))
131132

132133
# When using a real hash function as hashfun, identical objects will only
133134
# be added to the cache once
134135
cache <- Cache$new(td, hashfun = function(x) ascending_id())
135-
cache$push(iris)
136-
Sys.sleep(0.1)
137-
cache$push(iris)
138-
Sys.sleep(0.1)
139-
cache$push(iris)
140-
Sys.sleep(0.1)
141-
cache$push(iris)
142-
Sys.sleep(0.1)
143-
cache$push(iris)
144-
Sys.sleep(0.1)
136+
for (i in 1:5) cache$push(iris)
145137
cache$push(cars)
146138
expect_identical(cache$n, 6L)
147139

140+
141+
for (p in cache$files$path){ # loop necessary for compat with R < 3.6.0
142+
Sys.setFileTime(p, "1999-01-01 00:00:00")
143+
}
144+
148145
expect_true(cache$size > 2048)
149146
cache$prune(max_size = "2kb")
150147
expect_true(cache$size <= 2048)
@@ -164,16 +161,7 @@ test_that("Inf max_* do not prunes", {
164161
# When using a real hash function as hashfun, identical objects will only
165162
# be added to the cache once
166163
cache <- Cache$new(td, hashfun = function(x) ascending_id())
167-
cache$push(iris)
168-
Sys.sleep(0.1)
169-
cache$push(iris)
170-
Sys.sleep(0.1)
171-
cache$push(iris)
172-
Sys.sleep(0.1)
173-
cache$push(iris)
174-
Sys.sleep(0.1)
175-
cache$push(iris)
176-
Sys.sleep(0.1)
164+
for (i in 1:5) cache$push(iris)
177165
cache$push(cars)
178166
expect_identical(cache$n, 6L)
179167

@@ -231,16 +219,7 @@ test_that("pruning by age works", {
231219

232220
cache <- MockCache$new(dir = td, hashfun = function(x) ascending_id())
233221
on.exit(cache$purge(), add = TRUE)
234-
cache$push(iris)
235-
Sys.sleep(0.1)
236-
cache$push(iris)
237-
Sys.sleep(0.1)
238-
cache$push(iris)
239-
Sys.sleep(0.1)
240-
cache$push(iris)
241-
Sys.sleep(0.1)
242-
cache$push(iris)
243-
Sys.sleep(0.1)
222+
for (i in 1:5) cache$push(iris)
244223

245224
expect_identical(nrow(cache$files), 5L)
246225

0 commit comments

Comments
 (0)