@@ -295,8 +295,15 @@ labkey.webdav.doDownloadFolder <- function(localDir, baseUrl=NULL, folderPath, r
295295
296296 files <- labkey.webdav.listDir(baseUrl = baseUrl , folderPath = folderPath , fileSet = fileSet , remoteFilePath = remoteFilePath )
297297 for (file in files [[" files" ]]) {
298- relativeToRemoteRoot <- sub(prefix , " " , file [[" href" ]])
299- relativeToDownloadStart <- sub(paste0(prefix , remoteFilePath ), " " , file [[" href" ]])
298+ # Issue 53043: the files list href includes the server contextPath, so trim that if available
299+ fileHref <- file [[" href" ]]
300+ prefixIndex <- regexpr(prefix , fileHref )
301+ if (prefixIndex > - 1 ) {
302+ fileHref <- substr(fileHref , prefixIndex , nchar(fileHref ))
303+ }
304+
305+ relativeToRemoteRoot <- sub(prefix , " " , fileHref )
306+ relativeToDownloadStart <- sub(paste0(prefix , remoteFilePath ), " " , fileHref )
300307
301308 localPath <- file.path(localDir , relativeToDownloadStart )
302309 if (file [[" isdirectory" ]]) {
@@ -319,7 +326,7 @@ labkey.webdav.doDownloadFolder <- function(localDir, baseUrl=NULL, folderPath, r
319326
320327 labkey.webdav.doDownloadFolder(localDir = localPath , baseUrl = baseUrl , folderPath = folderPath , fileSet = fileSet , remoteFilePath = relativeToRemoteRoot , overwriteFiles = overwriteFiles , mergeFolders = mergeFolders , showProgressBar = showProgressBar )
321328 } else {
322- url <- paste0(baseUrl , trimLeadingPath(file [[ " href " ]] ))
329+ url <- paste0(baseUrl , trimLeadingPath(fileHref ))
323330
324331 logMessage(paste0(" Downloading file: " , relativeToRemoteRoot ))
325332 logMessage(paste0(" to: " , localPath ))
0 commit comments