-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[nodefs] Fix execute permission bit on Windows when retrieving mode attribute #21902
[nodefs] Fix execute permission bit on Windows when retrieving mode attribute #21902
Conversation
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.
lgtm % some nits and tests updates
@@ -127,6 +127,11 @@ addToLibrary({ | |||
if (NODEFS.isWindows && !stat.blocks) { | |||
stat.blocks = (stat.size+stat.blksize-1)/stat.blksize|0; | |||
} | |||
if (NODEFS.isWindows) { |
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.
Can you combine this with the block above so we only check isWindows
once?
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.
I applied this suggestion in ef0ec92.
test/test_other.py
Outdated
def test_windows_nodefs_execution_permission(self): | ||
if self.get_setting('WASMFS'): | ||
self.set_setting('FORCE_FILESYSTEM') | ||
delete_dir('new-dir') |
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.
You don't need to do this here since tests are guaranteed to start with an empty dir
test/test_other.py
Outdated
} | ||
'''.replace('{{WORKING_DIR}}', Path(self.working_dir).as_posix()) | ||
self.emcc_args += ['-lnodefs.js'] | ||
self.do_run(src) |
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.
You can combine these two lines into self.do_run(src, emcc_args=['-lnodefs.js'])
test/test_other.py
Outdated
int main(int argc, char * argv[]) { | ||
EM_ASM( | ||
FS.mkdir('/working'); | ||
FS.mount(NODEFS, { root: '{{WORKING_DIR}}' }, '/working'); |
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.
I think you can just do { root: '.' }
here? Unless I'm missing something?
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.
Ah, true. I think I introduced this early on when I was running the test without using the test runner. Now using the test runner, I confirmed that using { root: '.' }
works as expected. I'll update it.
FS.mount(NODEFS, { root: '{{WORKING_DIR}}' }, '/working'); | ||
FS.mkdir('/working/new-dir'); | ||
FS.writeFile('/working/new-dir/test.txt', 'test'); | ||
); |
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.
Can you put this EM_ASM
block into a separate setup()
function?
test/test_other.py
Outdated
@only_windows('Check that directory permissions are properly retrieved on Windows') | ||
@requires_node | ||
def test_windows_nodefs_execution_permission(self): | ||
if self.get_setting('WASMFS'): |
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.
I think this will always be false unless you add @also_with_wasmfs
. I'm not sure if you want to do that here though.
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.
I added this part based on what I saw in other tests (example). Not exactly sure if it's needed but we could remove it if it's not 👍.
test/test_other.py
Outdated
@requires_node | ||
def test_windows_nodefs_execution_permission(self): | ||
if self.get_setting('WASMFS'): | ||
self.set_setting('FORCE_FILESYSTEM') |
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.
Is this needed? Maybe just remove these two lines?
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.
As shared here, probably not. I'll remove it.
test/test_other.py
Outdated
err = stat("/working/new-dir/test.txt", &s); | ||
assert((s.st_mode & S_IXUSR) == S_IXUSR); | ||
assert((s.st_mode & S_IXGRP) == S_IXGRP); | ||
assert((s.st_mode & S_IXOTH) == S_IXOTH); |
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.
I think you can just do assert(s.st_mode & S_IXOTH)
since each of those defines is just a single bit
src/library_nodefs.js
Outdated
if (NODEFS.isWindows) { | ||
// Node.js on Windows never represents permission bit 'x', so | ||
// propagate read bits to execute bits. | ||
stat.mode = stat.mode | (stat.mode & 292) >> 2; |
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.
Can you put brackets around the (stat.mode & 292) >> 2
so its clear that the shift only applies the part of this expression?
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.
I noticed you updated the code where this is based in #21904. I'll apply the same here. Thanks 🙇 !
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.
Done in 75abe47.
I noticed this while reviewing emscripten-core#21902.
I noticed this while reviewing #21902.
@sbc100 thank you so much for reviewing the PR so quickly 🙇 ! I've checked the feedback and pushed changes accordingly. Let me know if you could take another look, thanks! |
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.
Thanks for working on this!
# Conflicts: # src/library_nodefs.js
On Windows, files and directories created within a mounted
NODEFS
instance consistently have the execution permission bitx
disabled, even though they are actually accessible. The permissions returned consistently indicate0666
. If this value is used to create other files or directories to match the same permissions, they will possess a different value, potentially leading to inconsistencies.This PR applies a solution similar to #5847, albeit within the
getattr
function ofNODEFS
.