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
Add umask command #681
Comments
It is an oversight. On the other hand, adding a builtin to Elvish is really easy; you can take a look at One thing that makes this slightly more tricky than other builtins is that |
Okay, I may have a look. But it could take weeks, possibly months. Got two really hectic weeks coming up, followed by one vacation week. Meanwhile, for the record: There is no reason why we have to mimic the
and thereby create Also, what about symbolic modes? We might wish to support those too, although designing the interface will require some thought. |
Aha. Having Re symbolic mode, it can get interesting for a variable. If you do |
What about adding a command for symbolic mode? (similar to set-env and get-env) |
Yeah, if we want to go all out, here is my suggestion: The |
Interesting discussion, and nice that we can depart from "the traditional way" of doing things like umask and look for better models. I like the variable idea. How about making the variable take only a numeric value, and have a builtin to convert symbolic to numeric specifications? E.g.:
For completeness, there should be a way to convert numeric-to-symbolic masks, like the Note: Please remember that the umask value is the complement of the desired permission - i.e. the bits in the mask are disabled. So just for correctness, in @xiaq's example above, the numeric value of |
@hanche heh, seems we had a very similar idea exactly at the same time (42 minutes ago) ;) |
FWIW, I think this is a good example of a feature that belongs in the new |
Could be, although I notice that the (Side note: I started implementing this shortly after posting the issue, then realised I didn't know either the go language, the appropriate library/ies, nor xiaq's coding conventions well enough to pull it off. Then life intervened before I could proceed to learning what I needed to figure out. By now, I can't even recall what exact problems I ran into, so I'd have to start from scratch. Oh well. It shouldn't have to be more than a dozen lines of code.) |
It's really for anything that cannot be done in an OS agnostic fashion in addition to OS specific constants. It's just that the PR which establishes the Assuming Windows doesn't have an analogous concept, or we can't think of a way to support both UNIX and Windows in an agnostic fashion, then I would argue |
I'm going to take a stab at implementing a |
FWIW, it shouldn't be necessary to have adjunct commands to support symbolic mode. Ideally the umask "get" and "set" methods would implicitly handle the conversion. Having that happen on the "set" method is easy. Having it happen on the "get" method is harder since we need to determine if the context requires emitting a number, implicit string (in which case an octal literal), or an explicit string as a result of the context being |
This is great news! Personally, I have lived a long and happy life with just octal umasks, so I don't see any need for symbolic ones. As for unit tests, one test would be to set the umask to some value and then ask again, to see that the change sticks. And perhaps to run How to make the code compile on windows, I have no idea. If you'd like to share your code and aren't ready yet to put it here on github, feel free to email me. I just added my work email to my profile. |
Re which module this should be in: When thinking about "OS functionalities", there are two different kinds:
Using the prior art of Python and Go, their The second type of functionalities are best exposed via different modules. Go got it wrong in the standard library by implementing a syscall package that has different API on different platforms, but corrected the mistake in golang.org/x/sys, which has a unix subpackage and a windows subpackage. So the |
Re support for symbolic modes: I'd rather that be implemented separately as a command, rather than building the conversion into the variable. My primary concern is that this could be injecting too much magic into the behavior of variable assignment, which should have straightforward semantics. In any case, start with a version that only supports octal masks. |
I agree. Working on an implementation forced me to think about how to provide sane behavior on multiple platforms. I concluded it isn't possible. I initially thought it should be a simple no-op on non-UNIX systems in the hope of making a feature like
I 100% agree on further reflection. Even if the umask stringifier function could easily determine if it was in a "simple" string context and should therefore emit the octal value, or in a |
Also, given how seldom people seem to use symbolic umask values, there doesn't seem to be any justifiable reason to provide support for symbolic umask values. The umask functionality is something almost no shell users think about in my experience. Not even experienced software engineers who work on UNIX. Mostly people just accept the default provided by their environment. Those who need to customize the value can be expected to know about the bit representation and how that relates to operations like creating a file. |
If you have a strong stomach read the POSIX specification for the Pay particular attention to phrases such as
As found in the My implementation is going to limit the legal umask values to exclude any bits outside the range [0 .. 0o777]. That is, it will disallow specifying bits such as setuid and setgid in the umask. It will only allow masking the user/group/other permission sets. |
Resolves elves#681
* Introduce a unix module and implement $unix:umask Resolves #681 * Address review feedback * More review feedback tweaks * goimports reformat
The title speaks for itself, I think. Especially on shared systems, it can sometimes be useful to be able to change the process's
umask
value.The text was updated successfully, but these errors were encountered: