fs icon indicating copy to clipboard operation
fs copied to clipboard

Relationship between umask and created directory permissions

Open chacalle opened this issue 3 years ago • 1 comments

Hello.

I am trying to understand the relationship between umask and the permissions created directories have.

I expected dir_create to follow the system umask setting (like shell mkdir path or base::dir.create) but it seems to follow the specified default mode. I think it would be great for dir_create to follow the umask setting so that I don't need to modify each call but maybe there is a good reason I don't understand for why fs was set up this way.

Thank you!

library(fs)
library(glue)
library(dplyr)
library(magrittr)

test_dir <- tempdir()

# Create directories three ways -------------------------------------------

Sys.umask(2)
fs::dir_create(fs::path(test_dir, "test_fs"))

Sys.umask(2)
base::dir.create(fs::path(test_dir, "test_base"))

Sys.umask(2)
mkdir_path <- fs::path(test_dir, "test_mkdir")
system(
  command = glue::glue("
  umask 002
  mkdir {mkdir_path}
  ")
)

# Get info on permissions of test directories -----------------------------

fs::dir_info(test_dir) %>%
  mutate(directory = fs::path_file(path)) %>%
  filter(grepl("test", directory)) %>%
  select(directory, permissions)

# A tibble: 3 x 2
  directory  permissions
  <chr>      <fs::perms>
1 test_base  rwxrwxr-x  
2 test_fs    rwxr-xr-x  
3 test_mkdir rwxrwxr-x 

Session Info:

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] magrittr_2.0.1 dplyr_1.0.2    glue_1.4.2     fs_1.5.0      

loaded via a namespace (and not attached):
 [1] fansi_0.4.1      utf8_1.1.4       assertthat_0.2.1 crayon_1.3.4    
 [5] R6_2.5.0         lifecycle_0.2.0  pillar_1.4.7     cli_2.2.0       
 [9] rlang_0.4.9      rstudioapi_0.13  vctrs_0.3.5      generics_0.1.0  
[13] ellipsis_0.3.1   tools_4.0.3      purrr_0.3.4      compiler_4.0.3  
[17] pkgconfig_2.0.3  tidyselect_1.1.0 tibble_3.0.4

chacalle avatar Dec 04 '20 02:12 chacalle

I think this is a good idea, and it also applies to file_create and possibly other functions as well.

gaborcsardi avatar Dec 08 '21 14:12 gaborcsardi