From fc2c113932ff8c23deb5be96b49d21f5b0f71d0a Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 16 Jul 2025 15:33:15 +0200 Subject: [PATCH] gh-127146: Emscripten: Make os.umask() actually work (GH-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. (cherry picked from commit 12e52cad718723636a96042f9399634392285c44) Co-authored-by: Hood Chatham --- Lib/test/test_os.py | 6 ++---- Python/emscripten_syscalls.c | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 1e50dc43c35f5c..de3a17fe893170 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1918,11 +1918,9 @@ def test_makedir(self): support.is_wasi, "WASI's umask is a stub." ) - @unittest.skipIf( - support.is_emscripten, - "TODO: Fails in buildbot; see #135783" - ) def test_mode(self): + # Note: in some cases, the umask might already be 2 in which case this + # will pass even if os.umask is actually broken. with os_helper.temp_umask(0o002): base = os_helper.TESTFN parent = os.path.join(base, 'dir1') diff --git a/Python/emscripten_syscalls.c b/Python/emscripten_syscalls.c index 7875bfc8fe56ae..bb80f979420ec1 100644 --- a/Python/emscripten_syscalls.c +++ b/Python/emscripten_syscalls.c @@ -7,7 +7,7 @@ // defined with weak linkage so we can override it. EM_JS(int, __syscall_getuid32_js, (void), { // If we're in node and we can, report the native uid - if (typeof process !== "undefined" && typeof process.getuid === "function") { + if (ENVIRONMENT_IS_NODE) { return process.getuid(); } // Fall back to the stub case of returning 0. @@ -17,3 +17,23 @@ EM_JS(int, __syscall_getuid32_js, (void), { int __syscall_getuid32(void) { return __syscall_getuid32_js(); } + +EM_JS(int, __syscall_umask_js, (int mask), { + // If we're in node and we can, call native process.umask() + if (ENVIRONMENT_IS_NODE) { + try { + return process.umask(mask); + } catch(e) { + // oops... + // NodeJS docs: "In Worker threads, process.umask(mask) will throw an exception." + // umask docs: "This system call always succeeds" + return 0; + } + } + // Fall back to the stub case of returning 0. + return 0; +}) + +int __syscall_umask(int mask) { + return __syscall_umask_js(mask); +}