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

[R] write_feather does not follow system-level umask setting #323

Closed
gnguy opened this issue Nov 9, 2017 · 2 comments
Closed

[R] write_feather does not follow system-level umask setting #323

gnguy opened this issue Nov 9, 2017 · 2 comments

Comments

@gnguy
Copy link

gnguy commented Nov 9, 2017

It appears that when using write_feather in R, it does not follow system-level umask settings.

When writing files using write_feather with a Sys.umask setting of 002, they appear to write files with rw-r--r-- permissions, which I would associate with a umask of 022. When I write files immediately after that while using write.csv, they write appropriately with rw-rw-r-- permissions.

I applied basically the same tests that were used in this issue (similar behavior that was happening with fwrite) Rdatatable/data.table#2049

library(feather)
Sys.umask(mode = "002")
Sys.umask()

2

filename <- "~/Desktop/umask_test.feather"
system(paste0("rm ", filename))
test_df <- data.frame(x=c(0,1))
write_feather(test_df, filename)
system(paste0("ls -la ",filename))

-rw-r--r-- 1 gngu 50513 176 Nov 9 09:23 /Users/gngu/Desktop/umask_test.feather

write.csv(test_df, "~/Desktop/umask_test.csv")
system("ls -la ~/Desktop/umask_test.csv")

-rw-rw-r-- 1 gngu 50513 19 Nov 9 09:23 /Users/gngu/Desktop/umask_test.csv

sessionInfo()

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.3

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] feather_0.3.1

loaded via a namespace (and not attached):
[1] hms_0.3 tools_3.3.2 tibble_1.3.0 yaml_2.1.14 Rcpp_0.12.12

@mcocdawc
Copy link

mcocdawc commented Oct 17, 2018

We had the same problem (feather_0.3.1 as well) and solved it with this workaround:

#' Obtain the chmod octal number from umask.
#'
#' @details  Applies https://en.wikipedia.org/wiki/Umask#Mask_effect.
#' Note that newly created files should not be executable
#' even if umask says so. https://en.wikipedia.org/wiki/Umask#Exceptions
#' Use the boolean executable argument to control behaviour.
#' 
#' @examples Sys.chmod(path, chmod_from_umask())
#' @export
chmod_from_umask <- function(umask = Sys.umask(), executable = FALSE){
  umask <- unlist(strsplit(stringr::str_pad(umask, 3, pad = '0'), split = ''))
  bitop <- function(i) {
    packBits(intToBits(7)
             & !intToBits(i) 
             & !intToBits(!executable),
             type = 'integer')
  }
  paste(sapply(umask, bitop), collapse = '')
}
#' Wrapper around write_feather that obeys sys.umask
#' 
#' This function is necessary, because 
#' \code{feather::write_feather} does not obey sys.umask
#' \url{https://github.com/wesm/feather/issues/323}
#' @export
write_feather <- function(x, path){
  feather::write_feather(x, path)
  Sys.chmod(path, chmod_from_umask())
}

@wesm
Copy link
Owner

wesm commented Apr 10, 2020

If you can reproduce this issue with the Feather implementation in arrow please open a JIRA issue with the Arrow project at http://issues.apache.org/jira. We're working to change feather to use arrow internally

@wesm wesm closed this as completed Apr 10, 2020
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

No branches or pull requests

3 participants