1414# limitations under the License.
1515# #
1616
17- labkey.webdav.get <- function (baseUrl = NULL , folderPath , remoteFilePath , localFilePath , overwrite = TRUE , fileSet = " @files" )
17+ labkey.webdav.get <- function (baseUrl = NULL , folderPath , remoteFilePath , localFilePath , overwrite = TRUE , fileSet = " @files" , showProgressBar = FALSE )
1818{
19- baseUrl = labkey.getBaseUrl(baseUrl );
19+ baseUrl <- labkey.getBaseUrl(baseUrl );
2020
2121 # # check required parameters
2222 if (missing(baseUrl ) || is.null(baseUrl ) || missing(folderPath ) || missing(remoteFilePath ) || missing(localFilePath )){
@@ -33,15 +33,15 @@ labkey.webdav.get <- function(baseUrl=NULL, folderPath, remoteFilePath, localFil
3333
3434 url <- paste(baseUrl , " _webdav" , folderPath , fileSet , " /" , remoteFilePath , sep = " " );
3535
36- ret <- labkey.webdav.getByUrl(url , localFilePath , overwrite )
36+ ret <- labkey.webdav.getByUrl(url , localFilePath , overwrite , showProgressBar = showProgressBar )
3737 if (! is.null(ret ) && ! is.na(ret ) && ret == FALSE ) {
3838 return (FALSE )
3939 }
4040
4141 return (file.exists(localFilePath ))
4242}
4343
44- labkey.webdav.getByUrl <- function (url , localFilePath , overwrite = TRUE )
44+ labkey.webdav.getByUrl <- function (url , localFilePath , overwrite = TRUE , showProgressBar = FALSE )
4545{
4646 # dont bother querying if this file already exists, since we wont overwrite it
4747 if (! overwrite & file.exists(localFilePath )) {
@@ -59,11 +59,16 @@ labkey.webdav.getByUrl <- function(url, localFilePath, overwrite=TRUE)
5959
6060 options <- labkey.getRequestOptions(method = " GET" )
6161
62+ progressBar <- NULL
63+ if (showProgressBar ) {
64+ progressBar <- httr :: progress()
65+ }
66+
6267 if (! is.null(.lkdefaults [[" debug" ]]) && .lkdefaults [[" debug" ]] == TRUE ){
6368 print(paste0(" URL: " , url ))
64- response <- GET(url = url , write_disk(localFilePath , overwrite = overwrite ), config = options , verbose(data_in = TRUE , info = TRUE , ssl = TRUE ))
69+ response <- GET(url = url , write_disk(localFilePath , overwrite = overwrite ), config = options , verbose(data_in = TRUE , info = TRUE , ssl = TRUE ), progressBar )
6570 } else {
66- response <- GET(url = url , write_disk(localFilePath , overwrite = overwrite ), config = options )
71+ response <- GET(url = url , write_disk(localFilePath , overwrite = overwrite ), config = options , progressBar )
6772 }
6873
6974 processResponse(response )
@@ -120,7 +125,7 @@ labkey.webdav.mkDir <- function(baseUrl=NULL, folderPath, remoteFilePath, fileSe
120125
121126labkey.webdav.validateAndBuildRemoteUrl <- function (baseUrl = NULL , folderPath , remoteFilePath , fileSet = " @files" )
122127{
123- baseUrl = labkey.getBaseUrl(baseUrl );
128+ baseUrl <- labkey.getBaseUrl(baseUrl );
124129
125130 # # check required parameters
126131 if (missing(baseUrl ) || is.null(baseUrl ) || missing(folderPath ) || missing(fileSet ) || missing(remoteFilePath )){
@@ -143,7 +148,7 @@ encodeRemotePath <- function(path, splitSlash = TRUE) {
143148
144149labkey.webdav.pathExists <- function (baseUrl = NULL , folderPath , remoteFilePath , fileSet = " @files" )
145150{
146- baseUrl = labkey.getBaseUrl(baseUrl );
151+ baseUrl <- labkey.getBaseUrl(baseUrl );
147152
148153 if (missing(baseUrl ) || is.null(baseUrl ) || missing(folderPath ) || missing(remoteFilePath )) {
149154 stop (paste(" A value must be specified for each of baseUrl, folderPath, fileSet, and remoteFilePath" ));
@@ -162,7 +167,7 @@ labkey.webdav.isDirectory <- function(baseUrl=NULL, folderPath, remoteFilePath,
162167
163168labkey.webdav.listDir <- function (baseUrl = NULL , folderPath , remoteFilePath , fileSet = " @files" , haltOnError = TRUE )
164169{
165- baseUrl = labkey.getBaseUrl(baseUrl );
170+ baseUrl <- labkey.getBaseUrl(baseUrl );
166171
167172 url <- labkey.webdav.validateAndBuildRemoteUrl(baseUrl = baseUrl , folderPath = folderPath , fileSet = fileSet , remoteFilePath = remoteFilePath )
168173 url <- paste0(url , " ?method=JSON" )
@@ -191,7 +196,7 @@ labkey.webdav.listDir <- function(baseUrl=NULL, folderPath, remoteFilePath, file
191196
192197labkey.webdav.delete <- function (baseUrl = NULL , folderPath , remoteFilePath , fileSet = " @files" )
193198{
194- baseUrl = labkey.getBaseUrl(baseUrl );
199+ baseUrl <- labkey.getBaseUrl(baseUrl );
195200
196201 url <- labkey.webdav.validateAndBuildRemoteUrl(baseUrl = baseUrl , folderPath = folderPath , fileSet = fileSet , remoteFilePath = remoteFilePath )
197202 url <- paste0(url , " ?method=DELETE" )
@@ -206,7 +211,7 @@ labkey.webdav.delete <- function(baseUrl=NULL, folderPath, remoteFilePath, fileS
206211
207212labkey.webdav.mkDirs <- function (baseUrl = NULL , folderPath , remoteFilePath , fileSet = " @files" )
208213{
209- baseUrl = labkey.getBaseUrl(baseUrl );
214+ baseUrl <- labkey.getBaseUrl(baseUrl );
210215
211216 if (missing(baseUrl ) || is.null(baseUrl ) || missing(folderPath ) || missing(remoteFilePath )){
212217 stop (paste(" A value must be specified for each of baseUrl, folderPath, fileSet, and remoteFilePath" ))
@@ -226,7 +231,7 @@ labkey.webdav.mkDirs <- function(baseUrl=NULL, folderPath, remoteFilePath, fileS
226231 return (TRUE )
227232}
228233
229- labkey.webdav.downloadFolder <- function (localBaseDir , baseUrl = NULL , folderPath , remoteFilePath , overwriteFiles = TRUE , mergeFolders = TRUE , fileSet = " @files" ) {
234+ labkey.webdav.downloadFolder <- function (localBaseDir , baseUrl = NULL , folderPath , remoteFilePath , overwriteFiles = TRUE , mergeFolders = TRUE , fileSet = " @files" , showProgressBar = FALSE ) {
230235 if (missing(localBaseDir ) || missing(baseUrl ) || is.null(baseUrl ) || missing(folderPath ) || missing(remoteFilePath )){
231236 stop (paste(" A value must be specified for each of localBaseDir, baseUrl, folderPath, fileSet, and remoteFilePath" ))
232237 }
@@ -257,7 +262,7 @@ labkey.webdav.downloadFolder <- function(localBaseDir, baseUrl=NULL, folderPath,
257262 return (F )
258263 }
259264
260- labkey.webdav.doDownloadFolder(localDir = localBaseDir , baseUrl = baseUrl , folderPath = folderPath , remoteFilePath = remoteFilePath , overwriteFiles = overwriteFiles , mergeFolders = mergeFolders , fileSet = fileSet )
265+ labkey.webdav.doDownloadFolder(localDir = localBaseDir , baseUrl = baseUrl , folderPath = folderPath , remoteFilePath = remoteFilePath , overwriteFiles = overwriteFiles , mergeFolders = mergeFolders , fileSet = fileSet , showProgressBar = showProgressBar )
261266}
262267
263268normalizeFolder <- function (localDir ){
@@ -277,7 +282,7 @@ logMessage <- function(msg) {
277282 }
278283}
279284
280- labkey.webdav.doDownloadFolder <- function (localDir , baseUrl = NULL , folderPath , remoteFilePath , depth , overwriteFiles = TRUE , mergeFolders = TRUE , fileSet = " @files" )
285+ labkey.webdav.doDownloadFolder <- function (localDir , baseUrl = NULL , folderPath , remoteFilePath , overwriteFiles = TRUE , mergeFolders = TRUE , fileSet = " @files" , showProgressBar = FALSE )
281286{
282287 baseUrl <- normalizeSlash(baseUrl , leading = F , trailing = F )
283288 folderPath <- encodeFolderPath(folderPath );
@@ -312,14 +317,14 @@ labkey.webdav.doDownloadFolder <- function(localDir, baseUrl=NULL, folderPath, r
312317 next
313318 }
314319
315- labkey.webdav.doDownloadFolder(localDir = localPath , baseUrl = baseUrl , folderPath = folderPath , fileSet = fileSet , remoteFilePath = relativeToRemoteRoot , overwriteFiles = overwriteFiles , mergeFolders = mergeFolders )
320+ labkey.webdav.doDownloadFolder(localDir = localPath , baseUrl = baseUrl , folderPath = folderPath , fileSet = fileSet , remoteFilePath = relativeToRemoteRoot , overwriteFiles = overwriteFiles , mergeFolders = mergeFolders , showProgressBar = showProgressBar )
316321 } else {
317322 url <- paste0(baseUrl , trimLeadingPath(file [[" href" ]]))
318323
319324 logMessage(paste0(" Downloading file: " , relativeToRemoteRoot ))
320325 logMessage(paste0(" to: " , localPath ))
321326
322- labkey.webdav.getByUrl(url , localPath , overwriteFiles )
327+ labkey.webdav.getByUrl(url , localPath , overwriteFiles , showProgressBar = showProgressBar )
323328 }
324329 }
325330
@@ -341,7 +346,7 @@ prepareDirectory <- function(localPath, overwriteFiles, mergeFolders) {
341346
342347 if (! mergeFolders && overwriteFiles ) {
343348 logMessage(' deleting existing folder' )
344- unlink(localPath , recursive = T )
349+ unlink(localPath , recursive = TRUE )
345350 }
346351 else if (! mergeFolders && ! overwriteFiles ) {
347352 logMessage(' skipping existing folder' )
@@ -354,5 +359,5 @@ prepareDirectory <- function(localPath, overwriteFiles, mergeFolders) {
354359 dir.create(localPath , recursive = TRUE )
355360 }
356361
357- return (T )
362+ return (TRUE )
358363}
0 commit comments