12
12
# ' \code{kwb.nextcloud:::nextcloud_user}
13
13
# ' @param auth authentication as returned by
14
14
# ' \code{kwb.nextcloud:::nextcloud_user}
15
- # ' @importFrom kwb.utils defaultIfNULL
15
+ # ' @param dbg logical indicating whether or not to show debug messages
16
+ # ' @importFrom kwb.utils createDirectories defaultIfNULL uniqueDirnames
16
17
# ' @importFrom kwb.file remove_common_root
17
18
# ' @export
18
19
# '
19
20
download_files <- function (
20
21
hrefs = NULL ,
21
- target_dir = create_download_dir(" nextcloud_" ),
22
+ target_dir = create_download_dir(" nextcloud_" , dbg = dbg ),
22
23
paths = NULL ,
23
24
user = nextcloud_user(),
24
- auth = nextcloud_auth()
25
+ auth = nextcloud_auth(),
26
+ dbg = TRUE
25
27
)
26
28
{
27
29
# kwb.utils::assignPackageObjects("kwb.nextcloud")
@@ -44,10 +46,13 @@ download_files <- function(
44
46
}
45
47
46
48
# Keep only the necessary tree structure
47
- target_paths <- kwb.file :: remove_common_root(paths_decoded )
49
+ target_paths <- kwb.file :: remove_common_root(paths_decoded , dbg = FALSE )
48
50
49
51
# Create required target folders
50
- create_directories(file.path(target_dir , unique_dirnames(target_paths )))
52
+ kwb.utils :: createDirectories(
53
+ file.path(target_dir , kwb.utils :: uniqueDirnames(target_paths )),
54
+ dbg = dbg
55
+ )
51
56
52
57
# Create the full paths to the target files
53
58
target_files <- file.path(target_dir , target_paths )
@@ -56,7 +61,7 @@ download_files <- function(
56
61
FUN = download_from_href ,
57
62
hrefs ,
58
63
target_files ,
59
- MoreArgs = list (auth = auth ),
64
+ MoreArgs = list (auth = auth , dbg = dbg ),
60
65
SIMPLIFY = FALSE ,
61
66
USE.NAMES = FALSE
62
67
))
@@ -66,12 +71,17 @@ download_files <- function(
66
71
67
72
# ' @importFrom kwb.utils catAndRun
68
73
# ' @keywords internal
69
- download_from_href <- function (href , target_file , auth = nextcloud_auth())
74
+ download_from_href <- function (
75
+ href ,
76
+ target_file ,
77
+ auth = nextcloud_auth(),
78
+ dbg = TRUE
79
+ )
70
80
{
71
81
# Expect the target directory to exist
72
82
stopifnot(file.exists(dirname(target_file )))
73
83
74
- kwb.utils :: catAndRun(paste(" Downloading" , href ), {
84
+ kwb.utils :: catAndRun(paste(" Downloading" , href ), dbg = dbg , {
75
85
76
86
response <- nextcloud_request(href , " GET" , auth )
77
87
@@ -82,14 +92,15 @@ download_from_href <- function(href, target_file, auth = nextcloud_auth())
82
92
# write_content_to_file --------------------------------------------------------
83
93
84
94
# ' @importFrom httr content headers
95
+ # ' @importFrom kwb.utils isTryError
85
96
# ' @keywords internal
86
97
write_content_to_file <- function (response , target_file )
87
98
{
88
99
content <- httr :: content(response , type = " application/octet-stream" )
89
100
90
101
result <- try(writeBin(content , target_file ))
91
102
92
- if (is_try_error (result )) {
103
+ if (kwb.utils :: isTryError (result )) {
93
104
94
105
stop(
95
106
" Could not write the response data with writeBin(). " ,
0 commit comments