Skip to content

Commit

Permalink
fix error in printing of backup queue when dry run is activated
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fleck committed Sep 3, 2022
1 parent d8903f6 commit c9d77b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion R/BackupQueue.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ BackupQueue <- R6::R6Class(
dd,
c(paste(nrow(dd), "files total"), sum(as.integer(dd[, "size"])))
)
dd[, "size"] <- pad_left(fmt_bytes(dd[, "size"]))

if (DRY_RUN$active){
dd[, "size"] <- pad_left(fmt_bytes(dd[, "size"], na = "<dry run>"))
} else {
dd[, "size"] <- pad_left(fmt_bytes(dd[, "size"]))
}


dd[, "file"] <- pad_right(dd[, "file"])
assert(nrow(dd) >= 3)
sel <- 2:(nrow(dd) - 1)
Expand Down
10 changes: 8 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ first <- function(x){


fmt_bytes <- function(
x
x,
na = "<NA>"
){
x <- as.numeric(x)

readablifiy <- function(.x){
if (is.na(.x) || is.null(.x)){
return(na)
}

for (unit in c("B", "KiB", "MiB", "GiB", "TiB")){
if (max(abs(.x)) < 1024 || unit == "TiB")
if (max(abs(.x), na.rm = TRUE) < 1024 || unit == "TiB")
break
else
.x <- .x / 1024
}

return(paste(round(.x, 1), unit))
}

Expand Down

0 comments on commit c9d77b2

Please sign in to comment.