Skip to content

Commit

Permalink
#31 add downloaded files integrity check
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Aug 7, 2020
1 parent e786ac8 commit f68a6d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Authors@R: c(
person("Julien", "Barde", role = c("ctb"), email = "julien.barde@ird.fr", comment = c(ORCID = "0000-0002-3519-6141")))
Maintainer: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
Depends: R (>= 3.3.0), methods
Imports: R6, httr, jsonlite, xml2, keyring
Imports: R6, httr, jsonlite, xml2, keyring, tools
Suggests: testthat
Description: Provides an Interface to 'Zenodo' (<https://zenodo.org>) REST API,
including management of depositions, attribution of DOIs by 'Zenodo' and
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ import(keyring)
import(methods)
import(xml2)
importFrom(R6,R6Class)
importFrom(tools,file_path_as_absolute)
importFrom(tools,md5sum)
20 changes: 16 additions & 4 deletions R/ZenodoRecord.R
Original file line number Diff line number Diff line change
Expand Up @@ -1157,12 +1157,24 @@ ZenodoRecord <- R6Class("ZenodoRecord",
length(self$files), ifelse(length(self$files)>1,"s",""), self$id,
self$doi, sum(sapply(self$files, function(x){x$filesize})))

#download_file util
download_file <- function(file){
cat(sprintf("Downloading file '%s' from record '%s' (doi: '%s') - size: %s\n",
cat(sprintf("[zen4R][INFO] Downloading file '%s' from record '%s' (doi: '%s') - size: %s\n",
file$filename, self$id, self$doi, file$filesize))
download.file(url = file$links$download, destfile = file.path(path, file$filename))
cat(sprintf("File '%s' successfully downloaded at '%s'\n",
file$filename, file.path(path, file$filename)))
target_file <-file.path(path, file$filename)
download.file(url = file$links$download, destfile = target_file)

#check md5sum
target_file_md5sum <- tools::md5sum(target_file)
if(target_file_md5sum==file$checksum){
cat(sprintf("[zen4R][INFO] File '%s' successfully downloaded at '%s' and its integrity verified (md5sum: %s)\n",
file$filename, tools::file_path_as_absolute(target_file), file$checksum))
}else{
warnMsg <- sprintf("[zen4R][WARN] Download issue: md5sum (%s) of file '%s' does not match Zenodo archive md4sum (%s)\n",
target_file_md5sum, tools::file_path_as_absolute(target_file), file$checksum)
cat(warnMsg)
warning(warnMsg)
}
}

if(parallel){
Expand Down
2 changes: 2 additions & 0 deletions R/zen4R.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' @import jsonlite
#' @import xml2
#' @import keyring
#' @importFrom tools file_path_as_absolute
#' @importFrom tools md5sum
#'
#' @title Interface to 'Zenodo' REST API
#' @description Provides an Interface to 'Zenodo' (<https://zenodo.org>) REST API,
Expand Down

0 comments on commit f68a6d0

Please sign in to comment.