Skip to content

Commit

Permalink
fix download file error in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jul 2, 2024
1 parent b338b7a commit e11423e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ download_inform <- function(urls, file_paths, ...) {
"status {cli::qty(n_failed_files)} code{?s}:",
"{.val {status[!is_success]}}"
),
x = "error {cli::qty(n_failed_files)} message{?s}: {.val {status$error[!is_success]}}"
x = paste(
"error {cli::qty(n_failed_files)} message{?s}:",
"{.val {status$error[!is_success]}}"
)
))
}
}
Expand Down Expand Up @@ -115,7 +118,8 @@ base_download_inform <- function(urls, file_paths, ...) {
cli::cli_inform("Downloading {.val {l}} files")
}
status <- utils::download.file(urls,
destfile = file_paths, ..., method = "libcurl"
destfile = file_paths, ...,
method = "libcurl"
)
is_success <- status == 0L
is_need_deleted <- !is_success & file.exists(file_paths)
Expand Down
2 changes: 1 addition & 1 deletion R/fda_drugs.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fda_drugs_file <- function(url = NULL, force,
ext = "zip",
name = "Drugs@FDA data",
dir = dir,
method = "base",
method = "base", mode = "wb",
arg = arg, call = call
)
}
Expand Down
4 changes: 2 additions & 2 deletions R/utils-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ cache_download <- function(url, prefix, ext, dir, method = NULL,
file <- paste(file, ext, sep = ".")
}
if (identical(method, "base")) {
base_download_inform(url, file)
base_download_inform(url, file, ...)
} else {
download_inform(url, file, ...)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ unzip2 <- function(path, compress_dir, ignore.case = TRUE) {
str_remove(basename(path), "\\.zip$", ignore.case = ignore.case)
)
exdir <- dir_create2(compress_dir)
if (is.null(utils::unzip(path, exdir = exdir, overwrite = TRUE))) {
if (length(utils::unzip(path, exdir = exdir, overwrite = TRUE)) == 0L) {
cli::cli_abort("Cannot uncompress {.file {path}}")
}
exdir
Expand Down

0 comments on commit e11423e

Please sign in to comment.