Skip to content

Commit 55a18e7

Browse files
author
Stefan Fleck
committed
Backups now retain their original timestamp (last modified) where possible (even when zipped)
1 parent eb2411f commit 55a18e7

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

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.2
4+
Version: 0.3.2.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+
* Backups now retain their original timestamp (created, last modified) where
4+
possible (even when zipped)
5+
6+
17
# rotor 0.3.2
28

39
* fixes time zone related issue in `Cache$prune()`.

R/copy_or_compress.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,6 @@ copy_or_compress <- function(
8181
stop("should not be possible to arrive here")
8282
}
8383

84+
Sys.setFileTime(outname, file.mtime(file))
8485
outname
8586
}

R/utils-fs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ file_copy <- function(
2929
return(DRY_RUN$create(to))
3030
}
3131

32-
file.copy(from, to, ...)
32+
file.copy(from, to, ..., copy.date = TRUE)
3333
}
3434

3535

tests/testthat/test_copy_or_compress.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ context("copy_or_compress")
22

33
dr <- tempdir()
44
td <- file.path(dr, "rotor")
5+
timestamp_tolerance <- 10 # seconds
6+
57
dir.create(td, recursive = TRUE)
68
teardown({
79
unlink(td, recursive = TRUE)
@@ -10,6 +12,17 @@ teardown({
1012

1113

1214

15+
create_testfile <- function(){
16+
tf <- file.path(td, "compresstest.log")
17+
saveRDS(iris, file = tf, compress = FALSE)
18+
fake_time <- as.POSIXct("1990-01-01 02:03:04")
19+
Sys.setFileTime(tf, fake_time)
20+
expect_true(equalish(file.info(tf)$mtime, fake_time, timestamp_tolerance), "cannot fake timestamp")
21+
tf
22+
}
23+
24+
25+
1326

1427
test_that("copy_or_compress works with default zip command", {
1528
if (!is_zipcmd_available())
@@ -58,3 +71,23 @@ test_that("copy_or_compress works with zip::zipr", {
5871
expect_identical(zip::zip_list(r)[1, ]$filename, "compresstest.log")
5972
})
6073

74+
75+
76+
77+
test_that("copy_or_compress preserves timestamp", {
78+
tf <- create_testfile()
79+
on.exit(unlink(tf))
80+
81+
copy <- copy_or_compress(tf, paste0(tf, ".copy"))
82+
on.exit(unlink(copy), add = TRUE)
83+
expect_true(equalish(file.mtime(tf), file.mtime(copy), tolerance = timestamp_tolerance))
84+
85+
zip <- copy_or_compress(tf, tf, compression = "utils::zip")
86+
on.exit(unlink(zip), add = TRUE)
87+
expect_true(equalish(file.mtime(zip), file.mtime(tf), timestamp_tolerance))
88+
unlink(zip)
89+
90+
zip <- copy_or_compress(tf, tf, compression = "zip::zipr")
91+
expect_true(equalish(file.mtime(zip), file.mtime(tf), timestamp_tolerance))
92+
})
93+

0 commit comments

Comments
 (0)