Skip to content

Instantly share code, notes, and snippets.

@allaway
Last active November 18, 2022 22:40
Show Gist options
  • Select an option

  • Save allaway/be1966bc4c7017f07a39658a7c3e2dc6 to your computer and use it in GitHub Desktop.

Select an option

Save allaway/be1966bc4c7017f07a39658a7c3e2dc6 to your computer and use it in GitHub Desktop.
Check if Synapse-listed MD5 matches locally calculated MD5 by downloading files with client
library(synapser)
synLogin()
ids <- synTableQuery("select id from syn23664752")$asDataFrame()
md5_fail <- "syn45353855" # a known file with a bad md5 in filehandle
ids_testing <- c(md5_fail, ids$id)
res <- lapply(ids_testing[1:2], function(x){
message(glue::glue("{which(ids_testing==x)} of {length(ids_testing)}:{x}"))
res = tryCatch({
boo <- synGet(x)$path
res <- 'md5 match'
#need to delete file to avoid clogging instance after check
if (file.exists(boo)) {
#Delete file if it exists
message(glue::glue("deleting {x}"))
file.remove(boo)
}
res
}, error = function(e) {
#assume that if synapse returns an error it is an md5 mismatch error
res <- "md5 mismatch"
})
})
res_df <- dplyr::bind_cols(tibble::as_tibble_col(ids_testing, column_name = "synapse_id"),
tibble::as_tibble_col(res, column_name = "md5_passed"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment