Skip to content

Commit

Permalink
Add argument "dbg"
Browse files Browse the repository at this point in the history
to download_files(), download_from_href()
and set dbg = FALSE when calling
remove_common_root()
  • Loading branch information
hsonne committed Apr 18, 2023
1 parent 1262fb8 commit 3962769
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions R/download_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
#' \code{kwb.nextcloud:::nextcloud_user}
#' @param auth authentication as returned by
#' \code{kwb.nextcloud:::nextcloud_user}
#' @param dbg logical indicating whether or not to show debug messages
#' @importFrom kwb.utils createDirectories defaultIfNULL uniqueDirnames
#' @importFrom kwb.file remove_common_root
#' @export
#'
download_files <- function(
hrefs = NULL,
target_dir = create_download_dir("nextcloud_"),
target_dir = create_download_dir("nextcloud_", dbg = dbg),
paths = NULL,
user = nextcloud_user(),
auth = nextcloud_auth()
auth = nextcloud_auth(),
dbg = TRUE
)
{
#kwb.utils::assignPackageObjects("kwb.nextcloud")
Expand All @@ -44,11 +46,12 @@ download_files <- function(
}

# Keep only the necessary tree structure
target_paths <- kwb.file::remove_common_root(paths_decoded)
target_paths <- kwb.file::remove_common_root(paths_decoded, dbg = FALSE)

# Create required target folders
kwb.utils::createDirectories(
file.path(target_dir, kwb.utils::uniqueDirnames(target_paths))
file.path(target_dir, kwb.utils::uniqueDirnames(target_paths)),
dbg = dbg
)

# Create the full paths to the target files
Expand All @@ -58,7 +61,7 @@ download_files <- function(
FUN = download_from_href,
hrefs,
target_files,
MoreArgs = list(auth = auth),
MoreArgs = list(auth = auth, dbg = dbg),
SIMPLIFY = FALSE,
USE.NAMES = FALSE
))
Expand All @@ -68,12 +71,17 @@ download_files <- function(

#' @importFrom kwb.utils catAndRun
#' @keywords internal
download_from_href <- function(href, target_file, auth = nextcloud_auth())
download_from_href <- function(
href,
target_file,
auth = nextcloud_auth(),
dbg = TRUE
)
{
# Expect the target directory to exist
stopifnot(file.exists(dirname(target_file)))

kwb.utils::catAndRun(paste("Downloading", href), {
kwb.utils::catAndRun(paste("Downloading", href), dbg = dbg, {

response <- nextcloud_request(href, "GET", auth)

Expand Down

0 comments on commit 3962769

Please sign in to comment.