Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce bundle limits when exploding file enumerations #546

Merged
merged 2 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

## 0.8.25 (in development)

* Use the `curl` option `-T` when uploading files to avoid out of memory errors with large files. (#544)
* Use the `curl` option `-T` when uploading files to avoid out of memory
errors with large files. (#544)
* The `rsconnect.max.bundle.size` and `rsconnect.max.bundle.files` options are
enforced when processing an enumerated set of files. Previously, these
limits were enforced only when bundling an entire content directory. (#542)


## 0.8.24

Expand Down
36 changes: 29 additions & 7 deletions R/bundle.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,22 @@ listBundleFiles <- function(appDir) {

bundleFiles <- function(appDir) {
files <- listBundleFiles(appDir)
if (files$totalSize > getOption("rsconnect.max.bundle.size")) {
enforceBundleLimits(appDir, files$totalSize, length(files$contents))
files$contents
}

enforceBundleLimits <- function(appDir, totalSize, totalFiles) {
aronatkins marked this conversation as resolved.
Show resolved Hide resolved
if (totalSize > getOption("rsconnect.max.bundle.size")) {
stop("The directory ", appDir, " cannot be deployed because it is too ",
"large (the maximum size is ", getOption("rsconnect.max.bundle.size"),
" bytes). Remove some files or adjust the rsconnect.max.bundle.size ",
"option.")
} else if (length(files$contents) > getOption("rsconnect.max.bundle.files")) {
"option.", call. = FALSE)
} else if (totalFiles > getOption("rsconnect.max.bundle.files")) {
stop("The directory ", appDir, " cannot be deployed because it contains ",
"too many files (the maximum number of files is ",
getOption("rsconnect.max.bundle.files"), "). Remove some files or ",
"adjust the rsconnect.max.bundle.files option.")
"adjust the rsconnect.max.bundle.files option.", call. = TRUE)
}

files$contents
}

bundleApp <- function(appName, appDir, appFiles, appPrimaryDoc, assetTypeName,
Expand Down Expand Up @@ -1076,6 +1079,8 @@ preservePackageDescriptions <- function(bundleDir) {
# recursively into their constituent files, and returns just a list of files
explodeFiles <- function(dir, files) {
exploded <- c()
totalSize <- 0
totalFiles <- 0
for (f in files) {
target <- file.path(dir, f)
info <- file.info(target)
Expand All @@ -1086,11 +1091,28 @@ explodeFiles <- function(dir, files) {
# a directory; explode it
contents <- list.files(target, full.names = FALSE, recursive = TRUE,
include.dirs = FALSE)
exploded <- c(exploded, file.path(f, contents))
contentPaths <- file.path(f, contents)
contentInfos <- file.info(contentPaths)

totalSize <- totalSize + sum(contentInfos$size, na.rm = TRUE)
totalFiles <- totalFiles + length(contentPaths)

exploded <- c(exploded, contentPaths)
} else {
# not a directory; an ordinary file

ourSize <- if (is.na(info$size)) { 0 } else { info$size }
totalSize <- totalSize + ourSize
totalFiles <- totalFiles + 1

exploded <- c(exploded, f)
}
# Limits are being enforced after processing each entry on the
# input. This means that an input directory needs to be fully
# enumerated before issuing an error. This is different from the
# approach by bundleFiles, which enforces limits while walking
# directories.
enforceBundleLimits(dir, totalSize, totalFiles)
}
exploded
}
Expand Down