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

File-creation mode should respect umask #16237

Closed
micahjsmith opened this issue May 6, 2016 · 3 comments
Closed

File-creation mode should respect umask #16237

micahjsmith opened this issue May 6, 2016 · 3 comments
Labels
needs more info Clarification or a reproducible example is required

Comments

@micahjsmith
Copy link
Contributor

I think that file creation using open should respect the mask set by umask (at least on *nix). Currently, open calls ios_file which uses a file-creation mode given in src/support/ios.c:

fd = open_cloexec(fname, flags, S_IRUSR | S_IWUSR /* 0600 */ | S_IRGRP | S_IROTH /* 0644 */);

This gives every file user read-write permissions and group and other read-only permissions, regardless of the value of umask. On a multi-user system, teams may use the umask builtin to specify a mask for file-creation; it makes sense to me to respect this in open.

@vtjnash
Copy link
Sponsor Member

vtjnash commented May 6, 2016

can you produce an example of what you want and when it fails? You can't ignore umask since it is enforced by open:

http://linux.die.net/man/2/open

mode specifies the permissions to use in case a new file is created. This argument must be supplied when O_CREAT is specified in flags; if O_CREAT is not specified, then mode is ignored. The effective permissions are modified by the process's umask in the usual way: The permissions of the created file are (mode & ~umask). Note that this mode only applies to future accesses of the newly created file; the open() call that creates a read-only file may well return a read/write file descriptor.

@vtjnash vtjnash added the needs more info Clarification or a reproducible example is required label May 6, 2016
@micahjsmith
Copy link
Contributor Author

micahjsmith commented May 6, 2016

Sure. I mean that either there should be a way to specify exactly the file-creation mode (I don't think any of the existing open methods allow that) or exact inverse of umask could be used. For example

shell> umask 0002
julia> open("test.txt", "w") do f
       println(f, "hello")
       end
shell> echo "hello" > test1.txt
shell> ls -l test.txt test1.txt
-rw-rw-r-- 1 user group 6 May  6 15:48 test1.txt
-rw-r--r-- 1 user group 6 May  6 15:47 test.txt

So I'm not suggesting that there is any problem with umask/open failing but that in the absence of an ability to control file-creation mode it makes sense to use umask inverse as default (as echo seems to do).

And I think that even if there were an open method allowing this behavior, so many other functions like writetable rely upon the normal version of open that an environment variable/OS setting may make sense.

@micahjsmith
Copy link
Contributor Author

To follow up, given that file creation mode is given by mode & ~umask, I wonder why Julia's open doesn't use the same default mode as Linux's open, which seems to be read and write for user, group, and other. I realize that my original issue doesn't make too much sense, so I'm closing and will open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info Clarification or a reproducible example is required
Projects
None yet
Development

No branches or pull requests

2 participants