Skip to content

Commit

Permalink
checksum functions: drop silently_close_connections() *
Browse files Browse the repository at this point in the history
It appears to have been a fix for a missing close() statement
in the examples (after using writeLines()), rather than a
problem with the function.
It was done to avoid R auto-closing dangling connections with
a warning, a bit later.
  • Loading branch information
florisvdh committed Mar 18, 2021
1 parent 08b3307 commit 1460b88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
16 changes: 4 additions & 12 deletions R/filemanagement.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ fileman_up <- function(name,
#'
#' The function names were chosen to match those of GNU coreutils.
#'
#' The functions use the OpenSSL implementation of the \code{openssl} package,
#' and silently close file connections.
#' The functions use the OpenSSL implementation of the \code{openssl} package.
#' Note that \code{n2khab} will mask
#' \code{\link[tools:md5sum]{tools::md5sum()}},
#' which is a standalone implementation.
Expand All @@ -412,7 +411,9 @@ fileman_up <- function(name,
#' file2 <- tempfile()
#' files <- c(file1, file2)
#' file.create(files)
#' writeLines("some text", file(file2))
#' con <- file(file2)
#' writeLines("some text", con)
#' close(con)
#'
#' # computing two alternative checksums:
#' md5sum(files)
Expand All @@ -436,7 +437,6 @@ md5sum <- function(files) {
assert_that_allfiles_exist(files)
checksums <- map_chr(files, ~paste(md5(file(.))))
names(checksums) <- basename(files)
silently_close_connections()
return(checksums)
}

Expand All @@ -446,7 +446,6 @@ sha256sum <- function(files) {
assert_that_allfiles_exist(files)
checksums <- map_chr(files, ~paste(sha256(file(.))))
names(checksums) <- basename(files)
silently_close_connections()
return(checksums)
}

Expand All @@ -460,10 +459,3 @@ assert_that_allfiles_exist <- function(x) {
paste0(x[!exist], collapse = "\n")))
}

#' @keywords internal
silently_close_connections <- function() {
oldopt <- options(warn = -1)[[1]]
closeAllConnections()
options(warn = oldopt)
}

7 changes: 4 additions & 3 deletions man/checksum.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1460b88

Please sign in to comment.