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

Refactor file bundling functions #684

Merged
merged 23 commits into from
Feb 22, 2023
Merged

Refactor file bundling functions #684

merged 23 commits into from
Feb 22, 2023

Conversation

hadley
Copy link
Member

@hadley hadley commented Feb 20, 2023

  • Move all in bundleFiles.R
  • Refactor listBundleFiles() and explodeFiles() to perform enforceBundleLimits() at end. IMO this makes the recursion used in these functions much easier to understand.
  • listBundleFiles() no errors if too big/too many files, rather than silently truncating, thus matching the behavior of standardizeAppFiles().
  • I also tested more of the file removal behaviour in listBundleFiles(), revealing a bug in the support for .rscignore. Fixes .rcsignore file not ignoring files #568.
  • Updated errors and warnings

@@ -166,6 +166,28 @@ isShinyRmd <- function(filename) {
}
is_shiny_prerendered(yaml$runtime, yaml$server)
}

yamlFromRmd <- function(filename) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discovered this was in the wrong place while extracting the bundling functions.


# remove any files lines listed .rscignore
if (".rscignore" %in% contents) {
ignoreContents <- readLines(file.path(dir, ".rscignore"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two changes here:

  • readLines(file.path(dir, ".rscignore")) instead of readLines(".rscignore"); if that ever worked before it was by coincidence
  • Also remove .rscignore itself from the bundle

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely worked because:

  • ignore files usually at top level
  • working directory almost always the content directory

@hadley
Copy link
Member Author

hadley commented Feb 20, 2023

To do:

  • Update listBundleFile() docs
  • Update docs for .rscignore in deployApp()

Copy link
Contributor

@aronatkins aronatkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforcement during the walk is removed.

R/bundleFiles.R Outdated
children <- character()
for (name in contents) {
if (isTRUE(is_dir[[name]])) {
dirList <- recursiveBundleFiles(file.path(dir, name), depth + 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes of getOption("rsconnect.max.bundle.size") and getOption("rsconnect.max.bundle.files") as the walk progresses. This is an important check because folks occasionally use an appDir which is massive (a consequence of deploying $HOME/document.Rmd, for example).

Some historical issues with this code:

I'm not finding the original issue, but folks observed "hangs" (very long runtime) if there's no feedback until after the entire directory is processed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh bummer 😬 I'll think about how to restore this.

R/bundleFiles.R Outdated Show resolved Hide resolved
@hadley
Copy link
Member Author

hadley commented Feb 21, 2023

@aronatkins restored eager evaluation and added a test.

Copy link
Contributor

@aronatkins aronatkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bundle-size enforcement could move into the directory-contents loop rather than outside, which will cause us to exit earlier for additional types of directory structures.

R/bundleFiles.R Show resolved Hide resolved
R/bundleFiles.R Show resolved Hide resolved
R/bundleFiles.R Show resolved Hide resolved
R/bundleFiles.R Outdated Show resolved Hide resolved
children <- append(children, name)
totalFiles <- totalFiles + 1
totalSize <- totalSize + file_size(file.path(dir, name))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforcement checks should happen after each name is processed rather than after the fill set of list.files. Consider a directory with 20k files, a directory containing 10 2GB files, or a deep, broad directory trees.

You do not need checks both after each file and prior to exit; checking in the loop body is sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I misunderstand the recursion here.


# remove any files lines listed .rscignore
if (".rscignore" %in% contents) {
ignoreContents <- readLines(file.path(dir, ".rscignore"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely worked because:

  • ignore files usually at top level
  • working directory almost always the content directory

@hadley hadley merged commit 29ccb69 into main Feb 22, 2023
@hadley hadley deleted the bundleFiles branch February 22, 2023 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.rcsignore file not ignoring files
2 participants