From 3af13e26bcaf9e1036dca907c70fa1925f5ba325 Mon Sep 17 00:00:00 2001 From: Lukas Pietzschmann Date: Sun, 4 Aug 2024 19:46:53 +0200 Subject: [PATCH] Support for analyzing multiple files at once --- R/file_analysis.R | 4 ++-- R/utils.R | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/R/file_analysis.R b/R/file_analysis.R index 82d69a6..bfdf677 100644 --- a/R/file_analysis.R +++ b/R/file_analysis.R @@ -3,7 +3,7 @@ #' Note that either `filepath` or `content` must be provided, but never both. #' #' @param con The connection to the server -#' @param filepath The path to the file (must be visible to the server) +#' @param filepath A single or multiple file paths (must be visible to the server) #' @param content The R code to be analyzed #' @param cfg Weather to include the control flow graph in the response #' @param id The id of the request @@ -22,7 +22,7 @@ request_file_analysis <- function(con, stopifnot(rlang::is_missing(filepath) || rlang::is_missing(content), !rlang::is_missing(filepath) || !rlang::is_missing(content)) if (!rlang::is_missing(filepath)) { - stopifnot(is.character(filepath)) + stopifnot(is.character(filepath) || is.vector(filepath)) filepath <- normalizePath(filepath, mustWork = FALSE) filetoken <- get_filetoken(filepath) request <- list( diff --git a/R/utils.R b/R/utils.R index c1ba11e..62e4cc1 100644 --- a/R/utils.R +++ b/R/utils.R @@ -24,8 +24,11 @@ get_new_id <- make_id_provider() #' @return The token get_filetoken <- function(filepath = rlang::missing_arg(), content = rlang::missing_arg()) { if (!rlang::is_missing(filepath)) { - stopifnot(is.character(filepath), file.exists(filepath)) - token <- digest::digest(readLines(filepath)) + stopifnot(is.character(filepath) || is.vector(filepath)) + # sort to ensure that a different order will result in the same token + filepath <- sort(c(filepath)) + stopifnot(file.exists(filepath)) + token <- digest::digest(lapply(filepath, readLines)) } else if (!rlang::is_missing(content)) { stopifnot(is.character(content)) token <- digest::digest(content)