-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Stop using process.umask()
#6
Conversation
Sorry for pushing with broken tests, I realize this cannot be merged as is but hopefully showing the test errors can help us find a way to deal with this. |
I don't really understand umask and pulled it from some other code. Nor do I really understand what is going on in the linked issues. I assume this would be a breaking change so we probably couldn't upstream into gulp 4. Is there an interim solution? |
I don't know an interim solution. The issue is that libc does not provide a function to "query umask". The libc function is: // Set the umask and return the old value
mode_t umask(mode_t mask); So const old = process.umask(0);
process.umask(old); So there is race condition where other threads would create files using an invalid umask of 0 (all new files would have 0o000 permission). In theory a half-broken solution would be to create our own replacement umask function: let oldMask = 0;
function getUmask() {
let newMask = process.umask(oldMask);
if (newMask !== oldMask) {
process.umask(newMask);
oldMask = newMask;
}
return newMask
} Using this |
@coreyfarrell if we make this a breaking change, what do you think we should do? I just checked my default install of node and it looks like the default umask is |
@phated it looks like I was incorrect in my previous assessment. This is not a breaking change, the existing code does only performs chmod on existing paths if a mode is explicitly set. The tests were failing because my first commit had a bug where it was passing the wrong About the default umask, node.js does not set this. It is actually set per user profile. For example on my system the umask for my normal user is |
Additional note the CI failure at |
@coreyfarrell I still think we are talking past each other. The point of the masking in this was to replicate the behavior of the |
We have two paths for what to do when a directory already exists. When mode is provided the directory is I'm going to be out for a while but when I get back I can work on enabling CI for MacOS? |
I have a new scaffold to apply here that will add github actions with MacOS support. Should I do that and then we can continue work on this? |
I think that would be a good idea. |
@coreyfarrell all set! Please let me know how else I can help here. I'm wondering if we need some more tests to demonstrate how node-core's behavior is different between Linux and MacOS to highlight why the mask mode is needed. |
cf46402
to
eb41013
Compare
eb41013
to
f345cf3
Compare
@phated I'm unsure why the CI is failing, it is giving an error I've never seen on the Checkout step. I tried refreshing the |
@coreyfarrell I'm sorry you were the first to run into this. It turns out that my usage of the prettier action was extremely flawed. I've adjusted the workflow to only format code that is pushed to master, so this should work for you now. |
According to isaacs/node-mkdirp#22, the umask is applied at the operating system level. As with most things deep inside node, I don't trust it and would like to test that assumption. |
I disabled the coveralls warnings now. |
Just pushed a change that updates the |
For completeness' sake, I just tried |
Alright, I just figured out the test case that I was concerned about, and I also think I figured out the way to solve it. I will get that shipped over sometime this weekend. Sorry for the spam. |
@coreyfarrell this went a bit off the rails, but I think I feel confident I understand how everything is working now. Could you take a look at the changeset and the test runs with verbose logging enabled to see if you agree with everything that I did? |
@phated I'm not on a computer now but I'll be able to review at some point this weekend. Thanks for helping with the CI issues. |
mkdirp.js
Outdated
dirpath = path.resolve(dirpath); | ||
|
||
fs.mkdir(dirpath, mode, onMkdir); | ||
fs.mkdir(dirpath, { mode: mode }, onMkdir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options object form of fs.mkdir
requires node.js v10.12.0. If you want to be compatible with node.js 10.0.0 then this needs to switch back to fs.mkdir(dirname, mode, onMkdir)
. If not I'd lean towards saying that package.json#engines.node
should specify >=10.12.0
.
Other than this I think LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'll put that back.
ref nodejs/node#32321 Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
Ref nodejs/node#32321
This can result in a behavior change in an edge case:
./dir
without providingcustomMode
../dir
already exists but has a difference mode than the currentprocess.umask()
.I think the current release would reset the existing directory to match the current umask where the new code will leave it alone.