diff --git a/R/metadata.R b/R/metadata.R index ba5d8c1..4cfc2be 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -154,14 +154,12 @@ get_metadata <- function( else { db_path <- file.path(cache_directory, "metadata.0.2.3.parquet") - if (!file.exists(db_path)){ - report_file_sizes(remote_url) - sync_remote_file( - remote_url, - db_path, - progress(type = "down", con = stderr()) - ) - } + report_file_sizes(remote_url) + sync_remote_file( + remote_url, + db_path, + progress(type = "down", con = stderr()) + ) table <- duckdb() |> dbConnect(drv = _, read_only = TRUE) |> diff --git a/R/utils.R b/R/utils.R index 0e455a1..dd757f8 100644 --- a/R/utils.R +++ b/R/utils.R @@ -58,10 +58,19 @@ get_default_cache_dir <- function() { #' Synchronises a single remote file with a local path #' @importFrom httr write_disk GET stop_for_status #' @importFrom cli cli_abort cli_alert_info +#' @importFrom rlang is_interactive #' @return `NULL`, invisibly #' @keywords internal sync_remote_file <- function(full_url, output_file, ...) { - if (!file.exists(output_file)) { + user_over <- NA + if (file.exists(output_file)) { + if (is_interactive()) { + user_over <- menu(c("Yes", "No"), title = "Cached file alread exists. Overwrite?") + } else { + user_over <- 1 + } + } + if (!file.exists(output_file) || user_over == 1) { output_dir <- dirname(output_file) dir.create(output_dir, recursive = TRUE, @@ -70,7 +79,7 @@ sync_remote_file <- function(full_url, output_file, ...) { cli_alert_info("Downloading {full_url} to {output_file}") tryCatch( - GET(full_url, write_disk(output_file), ...) |> stop_for_status(), + GET(full_url, write_disk(output_file, overwrite = TRUE), ...) |> stop_for_status(), error = function(e) { # Clean up if we had an error file.remove(output_file)