Skip to content

bslib dependencies fail during file copy when installed read-only #1154

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

Closed
natashanath opened this issue Jan 6, 2025 · 8 comments · Fixed by #1184
Closed

bslib dependencies fail during file copy when installed read-only #1154

natashanath opened this issue Jan 6, 2025 · 8 comments · Fixed by #1184

Comments

@natashanath
Copy link

natashanath commented Jan 6, 2025

Permission denied when using precompiled css from a read-only bslib installation

In enterprise settings it is not uncommon to have a centralized library of packages where everything is installed read-only and maintained by designated users/teams. Another use case which is quickly gaining popularity is using Nix package manager for maintaining data science environments. Nix also installs everything read-only.

file.copy(precompiled_css, out_file)

One solution would be to add copy.mode = FALSE to the file.copy calls, so that the file mode attributes are not preserved.

This fails in applications that call bslib internally, like elmer

library(S7)
library(httr2)
library(coro)
library(shinychat)
library(elmer)

chat <- chat_ollama(
  model = 'zephyr7b',
  system_prompt = 'You are a friendly but terse coding assistant. You are an expert in R, Python, SQL.',
  echo = TRUE
)
elmer::live_browser(chat)
# UI error displayed:
An error occurred: inherits(pool, "curl_multi") is not TRUE
# Error in debugging:
Warning in file.copy(from, to, ...) :
  problem copying /path/to/R/library/bslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.eot to /path/to/tmp/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.eot: Permission denied
Warning in file.copy(from, to, ...) :
  problem copying /path/to/R/library/bslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.svg to /path/to/tmp/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.svg: Permission denied
Warning in file.copy(from, to, ...) :
  problem copying /path/to/R/librarybslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf to /path/to/tmp/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.ttf: Permission denied
Warning in file.copy(from, to, ...) :
  problem copying /path/to/R/library/bslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.woff to /path/to/tmp/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.woff: Permission denied
Warning in file.copy(from, to, ...) :
  problem copying /path/to/R/library/bslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2 to /path/to/tmp/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.woff2: Permission denied

Added here based on the issue raised on elmer

@gadenbuie
Copy link
Member

One solution would be to add copy.mode = FALSE to the file.copy calls, so that the file mode attributes are not preserved.

That seems reasonable, would you like to submit a PR with the fix?

@gadenbuie
Copy link
Member

Some follow up questions: Are you sure that the file mode attributes are the issue? Can you otherwise write files into R's temp folders on your system?

@gadenbuie
Copy link
Member

gadenbuie commented Jan 6, 2025

Part of my reservation is that the files causing the warning are not copied via file.copy() in the linked line but instead are copied by sass::write_file_attachments() below:

if (!is.null(precompiled_css)) {
out_dir <- file.path(tempdir(), paste0("bslib-precompiled-", version))
if (!dir.exists(out_dir)) {
dir.create(out_dir)
}
out_file <- file.path(out_dir, basename(precompiled_css))
file.copy(precompiled_css, out_file)
# Usually sass() would handle file_attachments and dependencies,
# but we need to do this manually
out_file <- attachDependencies(out_file, htmlDependencies(as_sass(theme)))
write_file_attachments(
as_sass_layer(theme)$file_attachments,
out_dir
)

I haven't looked into file.copy() internals either, but if the file mode attributes were an issue I'd expect the files to be copied but subsequent writes to fail. AFAIK we only read these files, so the warnings here smell different to me.

It might be worth explaining your system set up so that we can recreate the environment and reproduce the issue.

@savyajha
Copy link

savyajha commented Feb 11, 2025

I've come across exactly the same issue. I've seen this on NixOS, where if one installs shiny or bslib using the default rWrapper or radianWrapper, runExample works the first time one runs it, but it fails on the second try because the mode of the font/css/js files copied is 0400, which prevents overwriting them. Here's what I see on my end:

r$> runExample("01_hello", launch.browser = F)

Listening on http://127.0.0.1:4715
^C


r$> runExample("01_hello", launch.browser = F)

Listening on http://127.0.0.1:4715
Warning in file.copy(from, to, ...) :
  problem copying /nix/store/is6v5890bp5rqv3jni0cwb3hd8x0xfpy-r-bslib-0.8.0/library/bslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf to /tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.ttf: Permission denied
Warning in file.copy(from, to, ...) :
  problem copying /nix/store/is6v5890bp5rqv3jni0cwb3hd8x0xfpy-r-bslib-0.8.0/library/bslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.eot to /tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.eot: Permission denied
Warning in file.copy(from, to, ...) :
  problem copying /nix/store/is6v5890bp5rqv3jni0cwb3hd8x0xfpy-r-bslib-0.8.0/library/bslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.woff to /tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.woff: Permission denied
Warning in file.copy(from, to, ...) :
  problem copying /nix/store/is6v5890bp5rqv3jni0cwb3hd8x0xfpy-r-bslib-0.8.0/library/bslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.svg to /tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.svg: Permission denied
Warning in file.copy(from, to, ...) :
  problem copying /nix/store/is6v5890bp5rqv3jni0cwb3hd8x0xfpy-r-bslib-0.8.0/library/bslib/lib/bs3/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2 to /tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.woff2: Permission denied
Warning: Error in file.copy2: Error copying files: /nix/store/is6v5890bp5rqv3jni0cwb3hd8x0xfpy-r-bslib-0.8.0/library/bslib/lib/bs3/assets/fonts/bootstrap
  2: runApp
  1: runExample
^C


r$> q()
rm: cannot remove '/tmp/Rtmp0OK9Mq/shiny-sassd14afa4480ae7b9cccc67f2dd193aa78/fonts/bootstrap/glyphicons-halflings-regular.woff2': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/shiny-sassd14afa4480ae7b9cccc67f2dd193aa78/fonts/bootstrap/glyphicons-halflings-regular.svg': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/shiny-sassd14afa4480ae7b9cccc67f2dd193aa78/fonts/bootstrap/glyphicons-halflings-regular.woff': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/shiny-sassd14afa4480ae7b9cccc67f2dd193aa78/fonts/bootstrap/glyphicons-halflings-regular.eot': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/shiny-sassd14afa4480ae7b9cccc67f2dd193aa78/fonts/bootstrap/glyphicons-halflings-regular.ttf': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/ionRangeSlider1c599cb130648b3bc50b7e5d3e8826fb/fonts/bootstrap/glyphicons-halflings-regular.woff2': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/ionRangeSlider1c599cb130648b3bc50b7e5d3e8826fb/fonts/bootstrap/glyphicons-halflings-regular.svg': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/ionRangeSlider1c599cb130648b3bc50b7e5d3e8826fb/fonts/bootstrap/glyphicons-halflings-regular.woff': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/ionRangeSlider1c599cb130648b3bc50b7e5d3e8826fb/fonts/bootstrap/glyphicons-halflings-regular.eot': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/ionRangeSlider1c599cb130648b3bc50b7e5d3e8826fb/fonts/bootstrap/glyphicons-halflings-regular.ttf': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.woff2': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.svg': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.woff': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.eot': Permission denied
rm: cannot remove '/tmp/Rtmp0OK9Mq/bslib-precompiled-5/fonts/bootstrap/glyphicons-halflings-regular.ttf': Permission denied

@gadenbuie
Copy link
Member

Thanks @savyajha, that's certainly helpful. Have you tried the fix you proposed in #1183? I suspect it won't completely resolve the problem

@savyajha
Copy link

I've not tried it via changing the package. It's a bit difficult to do that in NixOS with R packages in particular. However, I've manually changed the mode to 0644 on every file in the temp directory and it's worked.

@Cormochamelion
Copy link

Cormochamelion commented Feb 14, 2025

I have a similar problem using Guix (which afaik works similar to NixOS). There packages are installed read-only, and can't be overwritten after being copied to the temp dir. My system is plain old Ubuntu, so the temp dir itself shouldn't cause issues with permissions.

My errors look similar to these, only other files.

Copy link

This issue has been automatically locked. If you have found a related problem, please open a new issue (with a reproducible example or feature request) and link to this issue.
🙋 Need help? Connect with us on Discord or Posit Community.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants