Skip to content

Commit 12e52ca

Browse files
authored
gh-127146: Emscripten: Make os.umask() actually work (#136706)
Provide a stub implementation of umask that is enough to get some tests passing. More work is needed upstream in Emscripten to make all umask tests to pass.
1 parent 8e2f4b4 commit 12e52ca

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Lib/test/test_os.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,11 +1918,9 @@ def test_makedir(self):
19181918
support.is_wasi,
19191919
"WASI's umask is a stub."
19201920
)
1921-
@unittest.skipIf(
1922-
support.is_emscripten,
1923-
"TODO: Fails in buildbot; see #135783"
1924-
)
19251921
def test_mode(self):
1922+
# Note: in some cases, the umask might already be 2 in which case this
1923+
# will pass even if os.umask is actually broken.
19261924
with os_helper.temp_umask(0o002):
19271925
base = os_helper.TESTFN
19281926
parent = os.path.join(base, 'dir1')

Python/emscripten_syscalls.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// defined with weak linkage so we can override it.
88
EM_JS(int, __syscall_getuid32_js, (void), {
99
// If we're in node and we can, report the native uid
10-
if (typeof process !== "undefined" && typeof process.getuid === "function") {
10+
if (ENVIRONMENT_IS_NODE) {
1111
return process.getuid();
1212
}
1313
// Fall back to the stub case of returning 0.
@@ -17,3 +17,23 @@ EM_JS(int, __syscall_getuid32_js, (void), {
1717
int __syscall_getuid32(void) {
1818
return __syscall_getuid32_js();
1919
}
20+
21+
EM_JS(int, __syscall_umask_js, (int mask), {
22+
// If we're in node and we can, call native process.umask()
23+
if (ENVIRONMENT_IS_NODE) {
24+
try {
25+
return process.umask(mask);
26+
} catch(e) {
27+
// oops...
28+
// NodeJS docs: "In Worker threads, process.umask(mask) will throw an exception."
29+
// umask docs: "This system call always succeeds"
30+
return 0;
31+
}
32+
}
33+
// Fall back to the stub case of returning 0.
34+
return 0;
35+
})
36+
37+
int __syscall_umask(int mask) {
38+
return __syscall_umask_js(mask);
39+
}

0 commit comments

Comments
 (0)