diff --git a/R/get_file_versions.R b/R/get_file_versions.R new file mode 100644 index 0000000..071bd5a --- /dev/null +++ b/R/get_file_versions.R @@ -0,0 +1,41 @@ +# get_file_versions ------------------------------------------------------------ + +#' Get Information on Versions of Given Files +#' +#' @param file_info data frame as returned by \code{\link{list_files}} when +#' being called with \code{full_info = TRUE} +#' @returns data frame +#' @importFrom kwb.utils moveColumnsToFront selectColumns +#' @export +get_file_versions <- function(file_info) +{ + # Remove information on directories + file_info <- file_info[!kwb.utils::selectColumns(file_info, "isdir"), ] + + if (nrow(file_info) == 0L) { + message("There are no (non-directory) files within file_info.") + return() + } + + # Get version information for the remaining files + file_ids <- kwb.utils::selectColumns(file_info, "fileid") + version_info <- get_version_info(file_ids, dbg = FALSE) + + if (is.null(version_info)) { + return() + } + + columns_file_info <- c("fileid", "file", "lastmodified", "etag") + columns_version_info <- c("fileid", "version", "href") + + result <- merge( + x = kwb.utils::selectColumns(file_info, columns_file_info), + y = kwb.utils::selectColumns(version_info, columns_version_info), + by = "fileid" + ) + + kwb.utils::moveColumnsToFront( + result, + columns = c("fileid", "file", "version") + ) +} diff --git a/R/get_version_info.R b/R/get_version_info.R index aaf481b..9942700 100644 --- a/R/get_version_info.R +++ b/R/get_version_info.R @@ -7,6 +7,7 @@ #' @param user nextcloud user #' @param ignore pattern matching columns to be excluded from the result. Set #' to \code{NULL} to see what columns are available. +#' @param dbg logical indicating whether or not to print debug messages #' @return data frame with one row per version. There seems to be only an entry #' if the corresponding file as more than one version. #' @importFrom kwb.utils catAndRun excludeNULL safeRowBindAll @@ -15,7 +16,8 @@ get_version_info <- function( file_ids, user = nextcloud_user(), - ignore = "^(status|quota|getcontent|resource)" + ignore = "^(status|quota|getcontent|resource)", + dbg = TRUE ) { #user <- "hsonne" @@ -24,14 +26,15 @@ get_version_info <- function( kwb.utils::catAndRun( paste("Getting version info for fileid =", fileid), - get_one_version_info(fileid, ignore = ignore, user = user) + get_one_version_info(fileid, ignore = ignore, user = user), + dbg = dbg ) }) results <- kwb.utils::excludeNULL(results, dbg = FALSE) if (length(results) == 0L) { - message("No versions available for given file IDs") + message("No versions available for given file IDs.") return() } @@ -43,12 +46,13 @@ get_version_info <- function( #' @importFrom kwb.utils isTryError orderBy selectColumns #' @keywords internal get_one_version_info <- function( - fileid, ignore = NULL, user = nextcloud_user(), auth = nextcloud_auth() + fileid, ignore = NULL, user = nextcloud_user(), auth = nextcloud_auth(), + silent = TRUE ) { href <- fileid_to_version_href(fileid, user) - result <- try({ + result <- try(silent = silent, { content <- nextcloud_request( href, verb = "PROPFIND", auth = auth, body = NULL, as = "parsed" diff --git a/R/list_file_versions.R b/R/list_file_versions.R index 67e8be1..f6b85e9 100644 --- a/R/list_file_versions.R +++ b/R/list_file_versions.R @@ -18,36 +18,3 @@ list_file_versions <- function(path, pattern = NULL, ...) file_info <- list_files(path, pattern, full_info = TRUE, ...) get_file_versions(file_info) } - -# get_file_versions ------------------------------------------------------------ - -#' Get Information on Versions of Given Files -#' -#' @param file_info data frame as returned by \code{\link{list_files}} when -#' being called with \code{full_info = TRUE} -#' @returns data frame -#' @importFrom kwb.utils moveColumnsToFront selectColumns -#' @export -get_file_versions <- function(file_info) -{ - # Remove information on directories - file_info <- file_info[!kwb.utils::selectColumns(file_info, "isdir"), ] - - # Get version information for the remaining files - file_ids <- kwb.utils::selectColumns(file_info, "fileid") - version_info <- get_version_info(file_ids) - - columns_file_info <- c("fileid", "file", "lastmodified", "etag") - columns_version_info <- c("fileid", "version", "href") - - result <- merge( - x = kwb.utils::selectColumns(file_info, columns_file_info), - y = kwb.utils::selectColumns(version_info, columns_version_info), - by = "fileid" - ) - - kwb.utils::moveColumnsToFront( - result, - columns = c("fileid", "file", "version") - ) -} diff --git a/man/get_file_versions.Rd b/man/get_file_versions.Rd index af6c03e..881b115 100644 --- a/man/get_file_versions.Rd +++ b/man/get_file_versions.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/list_file_versions.R +% Please edit documentation in R/get_file_versions.R \name{get_file_versions} \alias{get_file_versions} \title{Get Information on Versions of Given Files} diff --git a/man/get_version_info.Rd b/man/get_version_info.Rd index 432c537..c2c7fd5 100644 --- a/man/get_version_info.Rd +++ b/man/get_version_info.Rd @@ -7,7 +7,8 @@ get_version_info( file_ids, user = nextcloud_user(), - ignore = "^(status|quota|getcontent|resource)" + ignore = "^(status|quota|getcontent|resource)", + dbg = TRUE ) } \arguments{ @@ -18,6 +19,8 @@ column \code{fileid}) by \code{\link{list_files}}} \item{ignore}{pattern matching columns to be excluded from the result. Set to \code{NULL} to see what columns are available.} + +\item{dbg}{logical indicating whether or not to print debug messages} } \value{ data frame with one row per version. There seems to be only an entry