Skip to content

Commit

Permalink
Suppress error messages in get_file_versions()
Browse files Browse the repository at this point in the history
  • Loading branch information
hsonne committed Jul 26, 2024
1 parent 31fc790 commit 5a2277b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 40 deletions.
41 changes: 41 additions & 0 deletions R/get_file_versions.R
Original file line number Diff line number Diff line change
@@ -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")
)
}
14 changes: 9 additions & 5 deletions R/get_version_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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()
}

Expand All @@ -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"
Expand Down
33 changes: 0 additions & 33 deletions R/list_file_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
}
2 changes: 1 addition & 1 deletion man/get_file_versions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/get_version_info.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a2277b

Please sign in to comment.