Skip to content

Commit 9c9406b

Browse files
committed
removes "dir" column from $backups/backup_info()
1 parent 73ea042 commit 9c9406b

File tree

5 files changed

+48
-45
lines changed

5 files changed

+48
-45
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
triggered.
88
* added `backup_info()` which is similar to `file.info()` but with additional
99
backup related infos.
10+
* removed `"dir"` column from `$backups`/`backup_info()`
1011

1112

1213
# rotor 0.2.2

R/BackupQueue.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,14 @@ BackupQueue <- R6::R6Class(
251251
}
252252

253253
fname_matrix <- filenames_as_matrix(self$file, backups = backup_files)
254-
fname_df <- as.data.frame(fname_matrix, stringsAsFactors = FALSE)
254+
fname_df <- as.data.frame(
255+
fname_matrix[, c("name", "sfx", "ext"), drop = FALSE],
256+
stringsAsFactors = FALSE
257+
)
255258
finfo <- file.info(backup_files)
256259

257260
res <- cbind(
258-
data.frame(path = row.names(finfo), stringsAsFactors = FALSE),
261+
path = data.frame(path = rownames(finfo), stringsAsFactors = FALSE),
259262
fname_df,
260263
finfo
261264
)
@@ -360,7 +363,7 @@ BackupQueueIndex <- R6::R6Class(
360363
backups <- self$backups
361364
backups$sfx_new <- pad_left(backups$index, pad = "0")
362365
backups$path_new <-
363-
paste(file.path(backups$dir, backups$name), backups$sfx_new, backups$ext, sep = ".")
366+
paste(file.path(dirname(backups$path), backups$name), backups$sfx_new, backups$ext, sep = ".")
364367

365368
backups$path_new <- gsub("\\.$", "", backups$path_new)
366369

@@ -383,7 +386,7 @@ BackupQueueIndex <- R6::R6Class(
383386
backups <- self$backups
384387
backups$index <- backups$index + as.integer(n)
385388
backups$path_new <- paste(
386-
file.path(backups$dir, backups$name),
389+
file.path(dirname(backups$path), backups$name),
387390
pad_left(backups$index, pad = "0"),
388391
backups$ext,
389392
sep = "."
@@ -842,7 +845,6 @@ get_backups <- function(
842845

843846
EMPTY_BACKUPS <- data.frame(
844847
path = character(0),
845-
dir = character(0),
846848
name = character(0),
847849
sfx = character(0),
848850
ext = character(0),

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ an empty file in place of the original one. This is useful for log rotation.
3535
`backup()`, `backup_date()` and `backup_time()` do the same but keep the
3636
original file.
3737

38-
rotor also includes a few utility functions for examining backups of a
38+
rotor also includes utility functions for finding and examining the backups of a
3939
file: `list_backups()`, `backup_info()`, `n_backups`, `newest_backup()`,
4040
`oldest_backup()`. See the
4141
[function reference](https://s-fleck.github.io/rotor/reference/index.html) for

README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ addition, they create an empty file in place of the original one. This
3030
is useful for log rotation. `backup()`, `backup_date()` and
3131
`backup_time()` do the same but keep the original file.
3232

33-
rotor also includes a few utility functions for examining backups of a
34-
file: `list_backups()`, `backup_info()`, `n_backups`, `newest_backup()`,
35-
`oldest_backup()`. See the [function
33+
rotor also includes utility functions for finding and examining the
34+
backups of a file: `list_backups()`, `backup_info()`, `n_backups`,
35+
`newest_backup()`, `oldest_backup()`. See the [function
3636
reference](https://s-fleck.github.io/rotor/reference/index.html) for
3737
details.
3838

@@ -83,8 +83,8 @@ backup(tf, compression = TRUE)
8383

8484
# display backups of a file
8585
list_backups(tf)
86-
#> [1] "/tmp/RtmppxEUB8/rotor/mylogfile.1.log.zip"
87-
#> [2] "/tmp/RtmppxEUB8/rotor/mylogfile.2.log"
86+
#> [1] "/tmp/RtmpT5fN3W/rotor/mylogfile.1.log.zip"
87+
#> [2] "/tmp/RtmpT5fN3W/rotor/mylogfile.2.log"
8888
```
8989

9090
`rotate()` also backs up a file, but replaces the original file with an
@@ -93,9 +93,9 @@ empty one.
9393
``` r
9494
rotate(tf)
9595
list_backups(tf)
96-
#> [1] "/tmp/RtmppxEUB8/rotor/mylogfile.1.log"
97-
#> [2] "/tmp/RtmppxEUB8/rotor/mylogfile.2.log.zip"
98-
#> [3] "/tmp/RtmppxEUB8/rotor/mylogfile.3.log"
96+
#> [1] "/tmp/RtmpT5fN3W/rotor/mylogfile.1.log"
97+
#> [2] "/tmp/RtmpT5fN3W/rotor/mylogfile.2.log.zip"
98+
#> [3] "/tmp/RtmpT5fN3W/rotor/mylogfile.3.log"
9999

100100
# the original file is now empty
101101
readLines(tf)
@@ -118,10 +118,10 @@ backup(tf, max_backups = 4)
118118
backup(tf, max_backups = 4)
119119

120120
list_backups(tf)
121-
#> [1] "/tmp/RtmppxEUB8/rotor/mylogfile.1.log"
122-
#> [2] "/tmp/RtmppxEUB8/rotor/mylogfile.2.log"
123-
#> [3] "/tmp/RtmppxEUB8/rotor/mylogfile.3.log"
124-
#> [4] "/tmp/RtmppxEUB8/rotor/mylogfile.4.log.zip"
121+
#> [1] "/tmp/RtmpT5fN3W/rotor/mylogfile.1.log"
122+
#> [2] "/tmp/RtmpT5fN3W/rotor/mylogfile.2.log"
123+
#> [3] "/tmp/RtmpT5fN3W/rotor/mylogfile.3.log"
124+
#> [4] "/tmp/RtmpT5fN3W/rotor/mylogfile.4.log.zip"
125125
```
126126

127127
We can also use `prune_backups()` to delete old backups. Other than
@@ -154,30 +154,30 @@ backup_time(tf, format = "%Y-%m-%d_%H-%M-%S") # Python logging
154154
backup_time(tf, format = "%Y%m%dT%H%M%S") # ISO 8601 compatible
155155

156156
backup_info(tf)
157-
#> path
158-
#> 1 /tmp/RtmppxEUB8/rotor/mylogfile.2019-05-30_23-15-33.log
159-
#> 2 /tmp/RtmppxEUB8/rotor/mylogfile.2019-05-30--23-15-33.log
160-
#> 5 /tmp/RtmppxEUB8/rotor/mylogfile.20190530T231533.log
161-
#> 3 /tmp/RtmppxEUB8/rotor/mylogfile.2019-05-30.log
162-
#> 4 /tmp/RtmppxEUB8/rotor/mylogfile.2019-05.log
163-
#> dir name sfx ext size isdir mode
164-
#> 1 /tmp/RtmppxEUB8/rotor mylogfile 2019-05-30_23-15-33 log 26 FALSE 664
165-
#> 2 /tmp/RtmppxEUB8/rotor mylogfile 2019-05-30--23-15-33 log 26 FALSE 664
166-
#> 5 /tmp/RtmppxEUB8/rotor mylogfile 20190530T231533 log 26 FALSE 664
167-
#> 3 /tmp/RtmppxEUB8/rotor mylogfile 2019-05-30 log 26 FALSE 664
168-
#> 4 /tmp/RtmppxEUB8/rotor mylogfile 2019-05 log 26 FALSE 664
169-
#> mtime ctime atime uid gid
170-
#> 1 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
171-
#> 2 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
172-
#> 5 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
173-
#> 3 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
174-
#> 4 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
175-
#> uname grname timestamp
176-
#> 1 hoelk hoelk 2019-05-30 23:15:33
177-
#> 2 hoelk hoelk 2019-05-30 23:15:33
178-
#> 5 hoelk hoelk 2019-05-30 23:15:33
179-
#> 3 hoelk hoelk 2019-05-30 00:00:00
180-
#> 4 hoelk hoelk 2019-05-01 00:00:00
157+
#> path name
158+
#> 1 /tmp/RtmpT5fN3W/rotor/mylogfile.2019-05-31_06-48-27.log mylogfile
159+
#> 2 /tmp/RtmpT5fN3W/rotor/mylogfile.2019-05-31--06-48-27.log mylogfile
160+
#> 5 /tmp/RtmpT5fN3W/rotor/mylogfile.20190531T064827.log mylogfile
161+
#> 3 /tmp/RtmpT5fN3W/rotor/mylogfile.2019-05-31.log mylogfile
162+
#> 4 /tmp/RtmpT5fN3W/rotor/mylogfile.2019-05.log mylogfile
163+
#> sfx ext size isdir mode mtime
164+
#> 1 2019-05-31_06-48-27 log 26 FALSE 664 2019-05-31 06:48:27
165+
#> 2 2019-05-31--06-48-27 log 26 FALSE 664 2019-05-31 06:48:27
166+
#> 5 20190531T064827 log 26 FALSE 664 2019-05-31 06:48:27
167+
#> 3 2019-05-31 log 26 FALSE 664 2019-05-31 06:48:26
168+
#> 4 2019-05 log 26 FALSE 664 2019-05-31 06:48:26
169+
#> ctime atime uid gid uname grname
170+
#> 1 2019-05-31 06:48:27 2019-05-31 06:48:27 1000 1000 hoelk hoelk
171+
#> 2 2019-05-31 06:48:27 2019-05-31 06:48:27 1000 1000 hoelk hoelk
172+
#> 5 2019-05-31 06:48:27 2019-05-31 06:48:27 1000 1000 hoelk hoelk
173+
#> 3 2019-05-31 06:48:26 2019-05-31 06:48:26 1000 1000 hoelk hoelk
174+
#> 4 2019-05-31 06:48:26 2019-05-31 06:48:26 1000 1000 hoelk hoelk
175+
#> timestamp
176+
#> 1 2019-05-31 06:48:27
177+
#> 2 2019-05-31 06:48:27
178+
#> 5 2019-05-31 06:48:27
179+
#> 3 2019-05-31 00:00:00
180+
#> 4 2019-05-01 00:00:00
181181
```
182182

183183
If we examine the “timestamp” column in the example above, we see that

tests/testthat/test_BackupQueue.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ test_that("BackupQueueIndex$push_backup() can push to different directory", {
412412
bt <- BackupQueueIndex$new(tf, backup_dir = bu_dir)
413413
bt$push_backup()
414414

415-
expect_match(bt$backups$dir, "rotor.backups")
415+
expect_match(dirname(bt$backups$path), "rotor.backups")
416416
bt$set_compression(TRUE)
417417
bt$push_backup()
418418

@@ -773,7 +773,7 @@ test_that("BackupQueueDateTime$push_backup() can push to different directory", {
773773
bt <- BackupQueueDateTime$new(tf, backup_dir = bu_dir)
774774
bt$push_backup()
775775

776-
expect_match(bt$backups$dir, "rotor.backups")
776+
expect_match(dirname(bt$backups$path), "rotor.backups")
777777
bt$set_compression(TRUE)
778778
bt$push_backup()
779779

@@ -1099,7 +1099,7 @@ test_that("BackupQueueDateTime$push_backup() can push to different directory", {
10991099
bt <- BackupQueueDate$new(tf, backup_dir = bu_dir)
11001100
bt$push_backup()
11011101

1102-
expect_match(bt$backups$dir, "rotor.backups")
1102+
expect_match(dirname(bt$backups$path), "rotor.backups")
11031103
bt$set_compression(TRUE)
11041104
bt$push_backup()
11051105

0 commit comments

Comments
 (0)