rstudio / pins-r

Pin, discover, and share resources
https://pins.rstudio.com
Other
316 stars 62 forks source link

permission error when updating cache with `pin_download` and `board_url` #535

Closed atusy closed 3 years ago

atusy commented 3 years ago

pin_download is successful for the first time but not for the second time. It cache directories and nested files have insufficient permissions. See reprex below.

I faced the issue on Linux.

reprex

# pin_download
board <- pins::board_url(
  c("html" = "https://example.com"),
  cache = tempfile()
)
cache <- pins::pin_download(board, "html")

# Force cache invalidation
yaml_path <- file.path(dirname(cache), "download-cache.yaml")
yaml <- yaml::read_yaml(yaml_path)
yaml[["https://example.com"]][c("expires", "etag")] <- list(0, '"0"')
yaml::write_yaml(yaml, yaml_path)

# Try refresh
pins::pin_download(board, "html")
#> Error: [EACCES] Failed to copy '/tmp/RtmpHJSIfF/file16997b7b739c' to '/tmp/RtmpHJSIfF/file1699199f481e/1b32e0fefbab2ff4ba0974f8fbf3f303/example.com': permission denied

# Check permissions
system2("ls", c(dirname(cache), "-la"), stdout = TRUE)
#> [1] "total 16"                                                          
#> [2] "drwxr-xr-x 2 rstudio rstudio 4096 Oct 14 20:48 ."                  
#> [3] "drwxr-xr-x 3 rstudio rstudio 4096 Oct 14 20:48 .."                 
#> [4] "-r--r--r-- 1 rstudio rstudio    0 Oct 14 20:48 data.txt"           
#> [5] "-rw-rw-rw- 1 rstudio rstudio  162 Oct 14 20:48 download-cache.yaml"
#> [6] "-r--rw-rw- 1 rstudio rstudio 1256 Oct 14 20:48 example.com"

Created on 2021-10-14 by the reprex package (v2.0.1)

hadley commented 3 years ago

Oooh because the cache is made write only to avoid the user accidentally changing.

atusy commented 3 years ago

I see! I opened a PR to fix it!

hongooi73 commented 3 years ago

@hadley is this bug going to affect the other Internet-based boards (S3, Azure, MS365, rsconnect)?

atusy commented 3 years ago

@hongooi73 As far as I understand, board_url and board_kaggle are affected because they use http_download. Others should be safe as they do not rely on http_download.

atusy commented 3 years ago

@hongooi73 Sorry, maybe I am wrong. It seems azure_download, and others are also changing files to be read only, but not adding write permission before downloading.

https://github.com/rstudio/pins/blob/921aee570ce48f5887bd997d941ec5e23468a8d1/R/board_azure.R#L185-L199

atusy commented 3 years ago

maybe I'm wrong again. Other boards attempts a download when path is missing. Maybe they do not have to care about update? I'm not using those boards, so am unsure...

hadley commented 3 years ago

I think it's only board_url() because for the other boards the pin-versions are immutable.

github-actions[bot] commented 2 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.