From 423fd4db6505a9aa48b5a6b61bbae31380d34845 Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Wed, 11 Dec 2024 20:59:12 +0100
Subject: [PATCH 1/7] Correctly handle calls setting timestamp to 0

If someone calls `utimes("file", 0, 0)` the previous code I wrote would
not adjust the time stamp.
---
 src/library_nodefs.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/library_nodefs.js b/src/library_nodefs.js
index 21e0561b783d9..4accc2c66fffb 100644
--- a/src/library_nodefs.js
+++ b/src/library_nodefs.js
@@ -166,7 +166,7 @@ addToLibrary({
             // update the common node structure mode as well
             node.mode = attr.mode;
           }
-          if (attr.atime || attr.mtime) {
+          if (typeof (attr.atime ?? attr.mtime) === "number") {
             var atime = attr.atime && new Date(attr.atime);
             var mtime = attr.mtime && new Date(attr.mtime);
             fs.utimesSync(path, atime, mtime);

From 7afb3d6e1433a5ce60b1f8ef96efc2822834698b Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Mon, 6 Jan 2025 21:58:02 +0100
Subject: [PATCH 2/7] Add a test

---
 src/library_memfs.js       |  2 +-
 src/library_nodefs.js      |  9 +++++++--
 src/library_workerfs.js    |  2 +-
 test/test_core.py          |  2 +-
 test/utime/test_futimens.c | 12 +++++++++++-
 5 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/library_memfs.js b/src/library_memfs.js
index 09a994f7f5b3e..c1ca9b24f9641 100644
--- a/src/library_memfs.js
+++ b/src/library_memfs.js
@@ -172,7 +172,7 @@ addToLibrary({
       },
       setattr(node, attr) {
         for (const key of ["mode", "atime", "mtime", "ctime"]) {
-          if (attr[key]) {
+          if (typeof attr[key] === 'number') {
             node[key] = attr[key];
           }
         }
diff --git a/src/library_nodefs.js b/src/library_nodefs.js
index 4accc2c66fffb..61ad5ca2dad30 100644
--- a/src/library_nodefs.js
+++ b/src/library_nodefs.js
@@ -167,8 +167,13 @@ addToLibrary({
             node.mode = attr.mode;
           }
           if (typeof (attr.atime ?? attr.mtime) === "number") {
-            var atime = attr.atime && new Date(attr.atime);
-            var mtime = attr.mtime && new Date(attr.mtime);
+            // Unfortunately, we have to stat the current value if we don't want
+            // to change it. On top of that, since the times don't round trip
+            // this will only keep the value nearly unchanged not exactly
+            // unchanged. See:
+            // https://github.com/nodejs/node/issues/56492
+            var atime = new Date(attr.atime ?? fs.lstatSync(NODEFS.realPath(node)).atime);
+            var mtime = new Date(attr.mtime ?? fs.lstatSync(NODEFS.realPath(node)).mtime);
             fs.utimesSync(path, atime, mtime);
           }
           if (attr.size !== undefined) {
diff --git a/src/library_workerfs.js b/src/library_workerfs.js
index b5245d201f181..14ca764567029 100644
--- a/src/library_workerfs.js
+++ b/src/library_workerfs.js
@@ -91,7 +91,7 @@ addToLibrary({
       },
       setattr(node, attr) {
         for (const key of ["mode", "atime", "mtime", "ctime"]) {
-          if (attr[key]) {
+          if (typeof attr[key] === 'number') {
             node[key] = attr[key];
           }
         }
diff --git a/test/test_core.py b/test/test_core.py
index 8075a42ade9bd..4f3cbc44c608f 100644
--- a/test/test_core.py
+++ b/test/test_core.py
@@ -5571,7 +5571,7 @@ def test_libgen(self):
   def test_utime(self):
     self.do_runf('utime/test_utime.c', 'success')
 
-  @also_with_noderawfs
+  @also_with_nodefs_both
   def test_futimens(self):
     self.do_runf('utime/test_futimens.c', 'success')
 
diff --git a/test/utime/test_futimens.c b/test/utime/test_futimens.c
index d42f635fa43d6..63a3c5c09f116 100644
--- a/test/utime/test_futimens.c
+++ b/test/utime/test_futimens.c
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <time.h>
 #include <sys/stat.h>
+#include <utime.h>
 
 
 void create_file(const char *path, const char *buffer, int mode) {
@@ -67,7 +68,7 @@ void test() {
   assert(s.st_rdev == 0);
   assert(s.st_size == 8);
   assert(s.st_ctime);
-#if defined(__EMSCRIPTEN__) && !defined(NODERAWFS)
+#if defined(__EMSCRIPTEN__) && !defined(NODERAWFS) && !defined(NODEFS)
   assert(s.st_blksize == 4096);
   assert(s.st_blocks == 1);
 #endif
@@ -128,6 +129,15 @@ void test() {
   times[1].tv_nsec = now.tv_nsec;
   check_times(fd, times, 1);
 
+  printf("check setting time to 0...\n");
+  struct utimbuf tb = {0};
+  utime("folder/file", &tb);
+  times[0].tv_sec = 0;
+  times[0].tv_nsec = 0;
+  times[1].tv_sec = 0;
+  times[1].tv_nsec = 0;
+  check_times(fd, times, 0);
+
   close(fd);
 
   puts("success");

From f51f7a30223096d9081a4a278c7b5d56cab1d859 Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Mon, 6 Jan 2025 22:29:34 +0100
Subject: [PATCH 3/7] Automatic rebaseline of codesize expectations. NFC

This is an automatic change generated by tools/maint/rebaseline_tests.py.

The following (18) test expectation files were updated by
running the tests with `--rebaseline`:

```
other/codesize/test_codesize_cxx_ctors1.gzsize: 8365 => 8374 [+9 bytes / +0.11%]
other/codesize/test_codesize_cxx_ctors1.jssize: 20373 => 20391 [+18 bytes / +0.09%]
other/codesize/test_codesize_cxx_ctors2.gzsize: 8347 => 8358 [+11 bytes / +0.13%]
other/codesize/test_codesize_cxx_ctors2.jssize: 20341 => 20359 [+18 bytes / +0.09%]
other/codesize/test_codesize_cxx_except.gzsize: 9369 => 9377 [+8 bytes / +0.09%]
other/codesize/test_codesize_cxx_except.jssize: 24141 => 24159 [+18 bytes / +0.07%]
other/codesize/test_codesize_cxx_except_wasm.gzsize: 8328 => 8340 [+12 bytes / +0.14%]
other/codesize/test_codesize_cxx_except_wasm.jssize: 20267 => 20285 [+18 bytes / +0.09%]
other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize: 8328 => 8340 [+12 bytes / +0.14%]
other/codesize/test_codesize_cxx_except_wasm_exnref.jssize: 20267 => 20285 [+18 bytes / +0.09%]
other/codesize/test_codesize_cxx_lto.gzsize: 8360 => 8371 [+11 bytes / +0.13%]
other/codesize/test_codesize_cxx_lto.jssize: 20397 => 20415 [+18 bytes / +0.09%]
other/codesize/test_codesize_cxx_mangle.gzsize: 9374 => 9384 [+10 bytes / +0.11%]
other/codesize/test_codesize_cxx_mangle.jssize: 24142 => 24160 [+18 bytes / +0.07%]
other/codesize/test_codesize_cxx_noexcept.gzsize: 8365 => 8374 [+9 bytes / +0.11%]
other/codesize/test_codesize_cxx_noexcept.jssize: 20373 => 20391 [+18 bytes / +0.09%]
other/codesize/test_codesize_files_js_fs.gzsize: 7655 => 7665 [+10 bytes / +0.13%]
other/codesize/test_codesize_files_js_fs.jssize: 18867 => 18885 [+18 bytes / +0.10%]

Average change: +0.10% (+0.07% - +0.14%)
```
---
 test/other/codesize/test_codesize_cxx_ctors1.gzsize             | 2 +-
 test/other/codesize/test_codesize_cxx_ctors1.jssize             | 2 +-
 test/other/codesize/test_codesize_cxx_ctors2.gzsize             | 2 +-
 test/other/codesize/test_codesize_cxx_ctors2.jssize             | 2 +-
 test/other/codesize/test_codesize_cxx_except.gzsize             | 2 +-
 test/other/codesize/test_codesize_cxx_except.jssize             | 2 +-
 test/other/codesize/test_codesize_cxx_except_wasm.gzsize        | 2 +-
 test/other/codesize/test_codesize_cxx_except_wasm.jssize        | 2 +-
 test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize | 2 +-
 test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize | 2 +-
 test/other/codesize/test_codesize_cxx_lto.gzsize                | 2 +-
 test/other/codesize/test_codesize_cxx_lto.jssize                | 2 +-
 test/other/codesize/test_codesize_cxx_mangle.gzsize             | 2 +-
 test/other/codesize/test_codesize_cxx_mangle.jssize             | 2 +-
 test/other/codesize/test_codesize_cxx_noexcept.gzsize           | 2 +-
 test/other/codesize/test_codesize_cxx_noexcept.jssize           | 2 +-
 test/other/codesize/test_codesize_files_js_fs.gzsize            | 2 +-
 test/other/codesize/test_codesize_files_js_fs.jssize            | 2 +-
 18 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize
index 1c35f29ce93d9..0b2a5d20da7ef 100644
--- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize
+++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize
@@ -1 +1 @@
-8365
+8374
diff --git a/test/other/codesize/test_codesize_cxx_ctors1.jssize b/test/other/codesize/test_codesize_cxx_ctors1.jssize
index 6ba1262cc45a0..96c52fa7bdfd0 100644
--- a/test/other/codesize/test_codesize_cxx_ctors1.jssize
+++ b/test/other/codesize/test_codesize_cxx_ctors1.jssize
@@ -1 +1 @@
-20373
+20391
diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize
index a665dbc2e401e..f6e57ea7e7807 100644
--- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize
+++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize
@@ -1 +1 @@
-8347
+8358
diff --git a/test/other/codesize/test_codesize_cxx_ctors2.jssize b/test/other/codesize/test_codesize_cxx_ctors2.jssize
index 092e8f41d3d1a..e3fe80ab6fb2e 100644
--- a/test/other/codesize/test_codesize_cxx_ctors2.jssize
+++ b/test/other/codesize/test_codesize_cxx_ctors2.jssize
@@ -1 +1 @@
-20341
+20359
diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize
index 83df514078c83..6a12f5ee09c7c 100644
--- a/test/other/codesize/test_codesize_cxx_except.gzsize
+++ b/test/other/codesize/test_codesize_cxx_except.gzsize
@@ -1 +1 @@
-9369
+9377
diff --git a/test/other/codesize/test_codesize_cxx_except.jssize b/test/other/codesize/test_codesize_cxx_except.jssize
index 0091e1deb81de..d32865bbb3d8b 100644
--- a/test/other/codesize/test_codesize_cxx_except.jssize
+++ b/test/other/codesize/test_codesize_cxx_except.jssize
@@ -1 +1 @@
-24141
+24159
diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize
index 6b663b45b81f6..e656e95e30a19 100644
--- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize
+++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize
@@ -1 +1 @@
-8328
+8340
diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.jssize b/test/other/codesize/test_codesize_cxx_except_wasm.jssize
index 21ce7fe7a474d..41b5f47b2a7c8 100644
--- a/test/other/codesize/test_codesize_cxx_except_wasm.jssize
+++ b/test/other/codesize/test_codesize_cxx_except_wasm.jssize
@@ -1 +1 @@
-20267
+20285
diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize
index 6b663b45b81f6..e656e95e30a19 100644
--- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize
+++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize
@@ -1 +1 @@
-8328
+8340
diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize
index 21ce7fe7a474d..41b5f47b2a7c8 100644
--- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize
+++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize
@@ -1 +1 @@
-20267
+20285
diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize
index 8d7a41cfdf9a7..b5654a18e535a 100644
--- a/test/other/codesize/test_codesize_cxx_lto.gzsize
+++ b/test/other/codesize/test_codesize_cxx_lto.gzsize
@@ -1 +1 @@
-8360
+8371
diff --git a/test/other/codesize/test_codesize_cxx_lto.jssize b/test/other/codesize/test_codesize_cxx_lto.jssize
index 7b1a75509bfdf..819b0053ef67d 100644
--- a/test/other/codesize/test_codesize_cxx_lto.jssize
+++ b/test/other/codesize/test_codesize_cxx_lto.jssize
@@ -1 +1 @@
-20397
+20415
diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize
index f4514b3a9fef8..474ab3ef3a5e4 100644
--- a/test/other/codesize/test_codesize_cxx_mangle.gzsize
+++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize
@@ -1 +1 @@
-9374
+9384
diff --git a/test/other/codesize/test_codesize_cxx_mangle.jssize b/test/other/codesize/test_codesize_cxx_mangle.jssize
index 27cd4f5eea3a3..4b905f2e491c6 100644
--- a/test/other/codesize/test_codesize_cxx_mangle.jssize
+++ b/test/other/codesize/test_codesize_cxx_mangle.jssize
@@ -1 +1 @@
-24142
+24160
diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize
index 1c35f29ce93d9..0b2a5d20da7ef 100644
--- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize
+++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize
@@ -1 +1 @@
-8365
+8374
diff --git a/test/other/codesize/test_codesize_cxx_noexcept.jssize b/test/other/codesize/test_codesize_cxx_noexcept.jssize
index 6ba1262cc45a0..96c52fa7bdfd0 100644
--- a/test/other/codesize/test_codesize_cxx_noexcept.jssize
+++ b/test/other/codesize/test_codesize_cxx_noexcept.jssize
@@ -1 +1 @@
-20373
+20391
diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize
index 6dbf5aca4f890..2aa9bf2ecdbc8 100644
--- a/test/other/codesize/test_codesize_files_js_fs.gzsize
+++ b/test/other/codesize/test_codesize_files_js_fs.gzsize
@@ -1 +1 @@
-7655
+7665
diff --git a/test/other/codesize/test_codesize_files_js_fs.jssize b/test/other/codesize/test_codesize_files_js_fs.jssize
index 84c612d62c528..90785537789eb 100644
--- a/test/other/codesize/test_codesize_files_js_fs.jssize
+++ b/test/other/codesize/test_codesize_files_js_fs.jssize
@@ -1 +1 @@
-18867
+18885

From 3b1a202120dc8a98cd509230186a40b876543062 Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Mon, 6 Jan 2025 22:49:15 +0100
Subject: [PATCH 4/7] Use `!= null` instead of `typeof _ === 'number'`

---
 src/library_memfs.js    | 2 +-
 src/library_workerfs.js | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/library_memfs.js b/src/library_memfs.js
index c1ca9b24f9641..d27cf26221213 100644
--- a/src/library_memfs.js
+++ b/src/library_memfs.js
@@ -172,7 +172,7 @@ addToLibrary({
       },
       setattr(node, attr) {
         for (const key of ["mode", "atime", "mtime", "ctime"]) {
-          if (typeof attr[key] === 'number') {
+          if (attr[key] != null) {
             node[key] = attr[key];
           }
         }
diff --git a/src/library_workerfs.js b/src/library_workerfs.js
index 14ca764567029..e30c1831a6761 100644
--- a/src/library_workerfs.js
+++ b/src/library_workerfs.js
@@ -91,7 +91,7 @@ addToLibrary({
       },
       setattr(node, attr) {
         for (const key of ["mode", "atime", "mtime", "ctime"]) {
-          if (typeof attr[key] === 'number') {
+          if (attr[key] != null) {
             node[key] = attr[key];
           }
         }

From ab7ed837a48f2613b66dd1ebbb2f797d23f93a40 Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Mon, 6 Jan 2025 22:52:02 +0100
Subject: [PATCH 5/7] Rebaseline code size

---
 test/code_size/embind_hello_wasm.json                   | 8 ++++----
 test/code_size/embind_val_wasm.json                     | 8 ++++----
 test/code_size/hello_webgl2_wasm.json                   | 8 ++++----
 test/code_size/hello_webgl2_wasm2js.json                | 8 ++++----
 test/code_size/hello_webgl_wasm.json                    | 8 ++++----
 test/code_size/hello_webgl_wasm2js.json                 | 8 ++++----
 test/code_size/random_printf_wasm.json                  | 8 ++++----
 test/code_size/random_printf_wasm2js.json               | 8 ++++----
 test/other/codesize/test_codesize_cxx_lto.gzsize        | 2 +-
 test/other/codesize/test_codesize_cxx_lto.jssize        | 2 +-
 test/other/codesize/test_codesize_cxx_lto.size          | 2 +-
 test/other/codesize/test_codesize_files_js_fs.gzsize    | 2 +-
 test/other/codesize/test_codesize_files_js_fs.jssize    | 2 +-
 test/other/codesize/test_codesize_hello_Oz.size         | 2 +-
 test/other/codesize/test_codesize_minimal_pthreads.size | 2 +-
 15 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/test/code_size/embind_hello_wasm.json b/test/code_size/embind_hello_wasm.json
index 62e6c089692f6..d617daa4b7fa6 100644
--- a/test/code_size/embind_hello_wasm.json
+++ b/test/code_size/embind_hello_wasm.json
@@ -3,8 +3,8 @@
   "a.html.gz": 380,
   "a.js": 9879,
   "a.js.gz": 4288,
-  "a.wasm": 7348,
-  "a.wasm.gz": 3375,
-  "total": 17779,
-  "total_gz": 8043
+  "a.wasm": 7488,
+  "a.wasm.gz": 3448,
+  "total": 17919,
+  "total_gz": 8116
 }
diff --git a/test/code_size/embind_val_wasm.json b/test/code_size/embind_val_wasm.json
index acfadb889a929..d75a9865f8df8 100644
--- a/test/code_size/embind_val_wasm.json
+++ b/test/code_size/embind_val_wasm.json
@@ -3,8 +3,8 @@
   "a.html.gz": 380,
   "a.js": 7153,
   "a.js.gz": 3042,
-  "a.wasm": 9119,
-  "a.wasm.gz": 4701,
-  "total": 16824,
-  "total_gz": 8123
+  "a.wasm": 9242,
+  "a.wasm.gz": 4749,
+  "total": 16947,
+  "total_gz": 8171
 }
diff --git a/test/code_size/hello_webgl2_wasm.json b/test/code_size/hello_webgl2_wasm.json
index 7a020bf4f620b..e3f54ca240482 100644
--- a/test/code_size/hello_webgl2_wasm.json
+++ b/test/code_size/hello_webgl2_wasm.json
@@ -3,8 +3,8 @@
   "a.html.gz": 328,
   "a.js": 4538,
   "a.js.gz": 2320,
-  "a.wasm": 10148,
-  "a.wasm.gz": 6641,
-  "total": 15140,
-  "total_gz": 9289
+  "a.wasm": 10209,
+  "a.wasm.gz": 6665,
+  "total": 15201,
+  "total_gz": 9313
 }
diff --git a/test/code_size/hello_webgl2_wasm2js.json b/test/code_size/hello_webgl2_wasm2js.json
index 738a68f71eed7..87eaa279f3b53 100644
--- a/test/code_size/hello_webgl2_wasm2js.json
+++ b/test/code_size/hello_webgl2_wasm2js.json
@@ -1,8 +1,8 @@
 {
   "a.html": 346,
   "a.html.gz": 262,
-  "a.js": 22202,
-  "a.js.gz": 11636,
-  "total": 22548,
-  "total_gz": 11898
+  "a.js": 22211,
+  "a.js.gz": 11605,
+  "total": 22557,
+  "total_gz": 11867
 }
diff --git a/test/code_size/hello_webgl_wasm.json b/test/code_size/hello_webgl_wasm.json
index 10242da677f71..233631ad7d70f 100644
--- a/test/code_size/hello_webgl_wasm.json
+++ b/test/code_size/hello_webgl_wasm.json
@@ -3,8 +3,8 @@
   "a.html.gz": 328,
   "a.js": 4076,
   "a.js.gz": 2163,
-  "a.wasm": 10148,
-  "a.wasm.gz": 6641,
-  "total": 14678,
-  "total_gz": 9132
+  "a.wasm": 10209,
+  "a.wasm.gz": 6665,
+  "total": 14739,
+  "total_gz": 9156
 }
diff --git a/test/code_size/hello_webgl_wasm2js.json b/test/code_size/hello_webgl_wasm2js.json
index ce0cfb4281a7d..08f53bbb6ca1e 100644
--- a/test/code_size/hello_webgl_wasm2js.json
+++ b/test/code_size/hello_webgl_wasm2js.json
@@ -1,8 +1,8 @@
 {
   "a.html": 346,
   "a.html.gz": 262,
-  "a.js": 21728,
-  "a.js.gz": 11470,
-  "total": 22074,
-  "total_gz": 11732
+  "a.js": 21737,
+  "a.js.gz": 11436,
+  "total": 22083,
+  "total_gz": 11698
 }
diff --git a/test/code_size/random_printf_wasm.json b/test/code_size/random_printf_wasm.json
index f75c7599c6da3..8a031efd1a4a0 100644
--- a/test/code_size/random_printf_wasm.json
+++ b/test/code_size/random_printf_wasm.json
@@ -1,6 +1,6 @@
 {
-  "a.html": 12449,
-  "a.html.gz": 6811,
-  "total": 12449,
-  "total_gz": 6811
+  "a.html": 12521,
+  "a.html.gz": 6874,
+  "total": 12521,
+  "total_gz": 6874
 }
diff --git a/test/code_size/random_printf_wasm2js.json b/test/code_size/random_printf_wasm2js.json
index 01548fcbdd758..96fd881187048 100644
--- a/test/code_size/random_printf_wasm2js.json
+++ b/test/code_size/random_printf_wasm2js.json
@@ -1,6 +1,6 @@
 {
-  "a.html": 17233,
-  "a.html.gz": 7535,
-  "total": 17233,
-  "total_gz": 7535
+  "a.html": 17204,
+  "a.html.gz": 7484,
+  "total": 17204,
+  "total_gz": 7484
 }
diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize
index 8d7a41cfdf9a7..7e8ca2500c174 100644
--- a/test/other/codesize/test_codesize_cxx_lto.gzsize
+++ b/test/other/codesize/test_codesize_cxx_lto.gzsize
@@ -1 +1 @@
-8360
+8362
diff --git a/test/other/codesize/test_codesize_cxx_lto.jssize b/test/other/codesize/test_codesize_cxx_lto.jssize
index 7b1a75509bfdf..d01decaf4e1d8 100644
--- a/test/other/codesize/test_codesize_cxx_lto.jssize
+++ b/test/other/codesize/test_codesize_cxx_lto.jssize
@@ -1 +1 @@
-20397
+20403
diff --git a/test/other/codesize/test_codesize_cxx_lto.size b/test/other/codesize/test_codesize_cxx_lto.size
index 608d1dc3431e9..f4e0e27a14ed0 100644
--- a/test/other/codesize/test_codesize_cxx_lto.size
+++ b/test/other/codesize/test_codesize_cxx_lto.size
@@ -1 +1 @@
-122145
+121787
diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize
index 6dbf5aca4f890..c02621465977d 100644
--- a/test/other/codesize/test_codesize_files_js_fs.gzsize
+++ b/test/other/codesize/test_codesize_files_js_fs.gzsize
@@ -1 +1 @@
-7655
+7657
diff --git a/test/other/codesize/test_codesize_files_js_fs.jssize b/test/other/codesize/test_codesize_files_js_fs.jssize
index 84c612d62c528..66a6ccf4611ff 100644
--- a/test/other/codesize/test_codesize_files_js_fs.jssize
+++ b/test/other/codesize/test_codesize_files_js_fs.jssize
@@ -1 +1 @@
-18867
+18873
diff --git a/test/other/codesize/test_codesize_hello_Oz.size b/test/other/codesize/test_codesize_hello_Oz.size
index 39eb8283b0002..c83b06780ee2a 100644
--- a/test/other/codesize/test_codesize_hello_Oz.size
+++ b/test/other/codesize/test_codesize_hello_Oz.size
@@ -1 +1 @@
-1261
+1289
diff --git a/test/other/codesize/test_codesize_minimal_pthreads.size b/test/other/codesize/test_codesize_minimal_pthreads.size
index 0f60aa5d0b843..59501bf076992 100644
--- a/test/other/codesize/test_codesize_minimal_pthreads.size
+++ b/test/other/codesize/test_codesize_minimal_pthreads.size
@@ -1 +1 @@
-19405
+19448

From 54cfc8c100a70baa3492cd7d618fa814eb8a97d5 Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Wed, 8 Jan 2025 21:16:49 +0100
Subject: [PATCH 6/7] slightly shorter approach

---
 src/library_nodefs.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/library_nodefs.js b/src/library_nodefs.js
index 61ad5ca2dad30..bdbfbe6cab863 100644
--- a/src/library_nodefs.js
+++ b/src/library_nodefs.js
@@ -172,8 +172,9 @@ addToLibrary({
             // this will only keep the value nearly unchanged not exactly
             // unchanged. See:
             // https://github.com/nodejs/node/issues/56492
-            var atime = new Date(attr.atime ?? fs.lstatSync(NODEFS.realPath(node)).atime);
-            var mtime = new Date(attr.mtime ?? fs.lstatSync(NODEFS.realPath(node)).mtime);
+            var stat = () => fs.lstatSync(NODEFS.realPath(node));
+            var atime = new Date(attr.atime ?? stat().atime);
+            var mtime = new Date(attr.mtime ?? stat().mtime);
             fs.utimesSync(path, atime, mtime);
           }
           if (attr.size !== undefined) {

From 893535249ca8698bb74a4d356a48f8bd926a8551 Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Wed, 8 Jan 2025 21:26:46 +0100
Subject: [PATCH 7/7] Rebaseline code size

---
 test/code_size/embind_hello_wasm.json                |  8 ++++----
 test/code_size/embind_val_wasm.json                  |  8 ++++----
 test/code_size/hello_webgl2_wasm.json                |  8 ++++----
 test/code_size/hello_webgl2_wasm2js.json             |  8 ++++----
 test/code_size/hello_webgl_wasm.json                 |  8 ++++----
 test/code_size/hello_webgl_wasm2js.json              |  8 ++++----
 test/code_size/random_printf_wasm.json               | 12 ------------
 test/code_size/random_printf_wasm2js.json            |  8 ++++----
 test/other/codesize/test_codesize_cxx_ctors1.gzsize  |  2 +-
 test/other/codesize/test_codesize_cxx_ctors1.jssize  |  2 +-
 test/other/codesize/test_codesize_cxx_ctors2.gzsize  |  2 +-
 test/other/codesize/test_codesize_cxx_ctors2.jssize  |  2 +-
 test/other/codesize/test_codesize_cxx_except.gzsize  |  2 +-
 test/other/codesize/test_codesize_cxx_except.jssize  |  2 +-
 .../codesize/test_codesize_cxx_except_wasm.gzsize    |  2 +-
 .../codesize/test_codesize_cxx_except_wasm.jssize    |  2 +-
 .../test_codesize_cxx_except_wasm_exnref.gzsize      |  2 +-
 .../test_codesize_cxx_except_wasm_exnref.jssize      |  2 +-
 test/other/codesize/test_codesize_cxx_lto.gzsize     |  2 +-
 test/other/codesize/test_codesize_cxx_lto.jssize     |  2 +-
 test/other/codesize/test_codesize_cxx_mangle.gzsize  |  2 +-
 test/other/codesize/test_codesize_cxx_mangle.jssize  |  2 +-
 .../other/codesize/test_codesize_cxx_noexcept.gzsize |  2 +-
 .../other/codesize/test_codesize_cxx_noexcept.jssize |  2 +-
 test/other/codesize/test_codesize_files_js_fs.gzsize |  2 +-
 test/other/codesize/test_codesize_files_js_fs.jssize |  2 +-
 26 files changed, 46 insertions(+), 58 deletions(-)

diff --git a/test/code_size/embind_hello_wasm.json b/test/code_size/embind_hello_wasm.json
index d617daa4b7fa6..62e6c089692f6 100644
--- a/test/code_size/embind_hello_wasm.json
+++ b/test/code_size/embind_hello_wasm.json
@@ -3,8 +3,8 @@
   "a.html.gz": 380,
   "a.js": 9879,
   "a.js.gz": 4288,
-  "a.wasm": 7488,
-  "a.wasm.gz": 3448,
-  "total": 17919,
-  "total_gz": 8116
+  "a.wasm": 7348,
+  "a.wasm.gz": 3375,
+  "total": 17779,
+  "total_gz": 8043
 }
diff --git a/test/code_size/embind_val_wasm.json b/test/code_size/embind_val_wasm.json
index d75a9865f8df8..acfadb889a929 100644
--- a/test/code_size/embind_val_wasm.json
+++ b/test/code_size/embind_val_wasm.json
@@ -3,8 +3,8 @@
   "a.html.gz": 380,
   "a.js": 7153,
   "a.js.gz": 3042,
-  "a.wasm": 9242,
-  "a.wasm.gz": 4749,
-  "total": 16947,
-  "total_gz": 8171
+  "a.wasm": 9119,
+  "a.wasm.gz": 4701,
+  "total": 16824,
+  "total_gz": 8123
 }
diff --git a/test/code_size/hello_webgl2_wasm.json b/test/code_size/hello_webgl2_wasm.json
index e3f54ca240482..7a020bf4f620b 100644
--- a/test/code_size/hello_webgl2_wasm.json
+++ b/test/code_size/hello_webgl2_wasm.json
@@ -3,8 +3,8 @@
   "a.html.gz": 328,
   "a.js": 4538,
   "a.js.gz": 2320,
-  "a.wasm": 10209,
-  "a.wasm.gz": 6665,
-  "total": 15201,
-  "total_gz": 9313
+  "a.wasm": 10148,
+  "a.wasm.gz": 6641,
+  "total": 15140,
+  "total_gz": 9289
 }
diff --git a/test/code_size/hello_webgl2_wasm2js.json b/test/code_size/hello_webgl2_wasm2js.json
index 87eaa279f3b53..738a68f71eed7 100644
--- a/test/code_size/hello_webgl2_wasm2js.json
+++ b/test/code_size/hello_webgl2_wasm2js.json
@@ -1,8 +1,8 @@
 {
   "a.html": 346,
   "a.html.gz": 262,
-  "a.js": 22211,
-  "a.js.gz": 11605,
-  "total": 22557,
-  "total_gz": 11867
+  "a.js": 22202,
+  "a.js.gz": 11636,
+  "total": 22548,
+  "total_gz": 11898
 }
diff --git a/test/code_size/hello_webgl_wasm.json b/test/code_size/hello_webgl_wasm.json
index 233631ad7d70f..10242da677f71 100644
--- a/test/code_size/hello_webgl_wasm.json
+++ b/test/code_size/hello_webgl_wasm.json
@@ -3,8 +3,8 @@
   "a.html.gz": 328,
   "a.js": 4076,
   "a.js.gz": 2163,
-  "a.wasm": 10209,
-  "a.wasm.gz": 6665,
-  "total": 14739,
-  "total_gz": 9156
+  "a.wasm": 10148,
+  "a.wasm.gz": 6641,
+  "total": 14678,
+  "total_gz": 9132
 }
diff --git a/test/code_size/hello_webgl_wasm2js.json b/test/code_size/hello_webgl_wasm2js.json
index 08f53bbb6ca1e..ce0cfb4281a7d 100644
--- a/test/code_size/hello_webgl_wasm2js.json
+++ b/test/code_size/hello_webgl_wasm2js.json
@@ -1,8 +1,8 @@
 {
   "a.html": 346,
   "a.html.gz": 262,
-  "a.js": 21737,
-  "a.js.gz": 11436,
-  "total": 22083,
-  "total_gz": 11698
+  "a.js": 21728,
+  "a.js.gz": 11470,
+  "total": 22074,
+  "total_gz": 11732
 }
diff --git a/test/code_size/random_printf_wasm.json b/test/code_size/random_printf_wasm.json
index 70dd60968da8f..2183a28354b5d 100644
--- a/test/code_size/random_printf_wasm.json
+++ b/test/code_size/random_printf_wasm.json
@@ -1,18 +1,6 @@
 {
-<<<<<<< HEAD
-  "a.html": 12521,
-  "a.html.gz": 6874,
-  "total": 12521,
-  "total_gz": 6874
-||||||| 2396d3e99
-  "a.html": 12449,
-  "a.html.gz": 6811,
-  "total": 12449,
-  "total_gz": 6811
-=======
   "a.html": 12449,
   "a.html.gz": 6808,
   "total": 12449,
   "total_gz": 6808
->>>>>>> main
 }
diff --git a/test/code_size/random_printf_wasm2js.json b/test/code_size/random_printf_wasm2js.json
index 96fd881187048..01548fcbdd758 100644
--- a/test/code_size/random_printf_wasm2js.json
+++ b/test/code_size/random_printf_wasm2js.json
@@ -1,6 +1,6 @@
 {
-  "a.html": 17204,
-  "a.html.gz": 7484,
-  "total": 17204,
-  "total_gz": 7484
+  "a.html": 17233,
+  "a.html.gz": 7535,
+  "total": 17233,
+  "total_gz": 7535
 }
diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize
index ffa23b506397f..86aa6eff1baa3 100644
--- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize
+++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize
@@ -1 +1 @@
-8332
+8335
diff --git a/test/other/codesize/test_codesize_cxx_ctors1.jssize b/test/other/codesize/test_codesize_cxx_ctors1.jssize
index ef1edbf58561b..4a877ad885137 100644
--- a/test/other/codesize/test_codesize_cxx_ctors1.jssize
+++ b/test/other/codesize/test_codesize_cxx_ctors1.jssize
@@ -1 +1 @@
-20255
+20261
diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize
index 15142b4700a5a..04df37df4e230 100644
--- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize
+++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize
@@ -1 +1 @@
-8314
+8317
diff --git a/test/other/codesize/test_codesize_cxx_ctors2.jssize b/test/other/codesize/test_codesize_cxx_ctors2.jssize
index eb667a18ea268..bcb276206776c 100644
--- a/test/other/codesize/test_codesize_cxx_ctors2.jssize
+++ b/test/other/codesize/test_codesize_cxx_ctors2.jssize
@@ -1 +1 @@
-20223
+20229
diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize
index f428367645151..d56d8ca5a5757 100644
--- a/test/other/codesize/test_codesize_cxx_except.gzsize
+++ b/test/other/codesize/test_codesize_cxx_except.gzsize
@@ -1 +1 @@
-9336
+9339
diff --git a/test/other/codesize/test_codesize_cxx_except.jssize b/test/other/codesize/test_codesize_cxx_except.jssize
index 14395a3244cb8..c8f1d5ebab6b7 100644
--- a/test/other/codesize/test_codesize_cxx_except.jssize
+++ b/test/other/codesize/test_codesize_cxx_except.jssize
@@ -1 +1 @@
-24023
+24029
diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize
index c003c23346c0f..9b18d3480ed3a 100644
--- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize
+++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize
@@ -1 +1 @@
-8280
+8283
diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.jssize b/test/other/codesize/test_codesize_cxx_except_wasm.jssize
index cf7a60d0bdfa8..d8f45b2f0ecc7 100644
--- a/test/other/codesize/test_codesize_cxx_except_wasm.jssize
+++ b/test/other/codesize/test_codesize_cxx_except_wasm.jssize
@@ -1 +1 @@
-20148
+20154
diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize
index c003c23346c0f..9b18d3480ed3a 100644
--- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize
+++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize
@@ -1 +1 @@
-8280
+8283
diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize
index cf7a60d0bdfa8..d8f45b2f0ecc7 100644
--- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize
+++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize
@@ -1 +1 @@
-20148
+20154
diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize
index 53251bf6a4ed0..d7bec804220ec 100644
--- a/test/other/codesize/test_codesize_cxx_lto.gzsize
+++ b/test/other/codesize/test_codesize_cxx_lto.gzsize
@@ -1 +1 @@
-8346
+8350
diff --git a/test/other/codesize/test_codesize_cxx_lto.jssize b/test/other/codesize/test_codesize_cxx_lto.jssize
index 418ef026f614a..24fa6e801f419 100644
--- a/test/other/codesize/test_codesize_cxx_lto.jssize
+++ b/test/other/codesize/test_codesize_cxx_lto.jssize
@@ -1 +1 @@
-20331
+20337
diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize
index a5590c1bc4734..a14be756fbbb7 100644
--- a/test/other/codesize/test_codesize_cxx_mangle.gzsize
+++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize
@@ -1 +1 @@
-9341
+9343
diff --git a/test/other/codesize/test_codesize_cxx_mangle.jssize b/test/other/codesize/test_codesize_cxx_mangle.jssize
index 14395a3244cb8..c8f1d5ebab6b7 100644
--- a/test/other/codesize/test_codesize_cxx_mangle.jssize
+++ b/test/other/codesize/test_codesize_cxx_mangle.jssize
@@ -1 +1 @@
-24023
+24029
diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize
index ffa23b506397f..86aa6eff1baa3 100644
--- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize
+++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize
@@ -1 +1 @@
-8332
+8335
diff --git a/test/other/codesize/test_codesize_cxx_noexcept.jssize b/test/other/codesize/test_codesize_cxx_noexcept.jssize
index ef1edbf58561b..4a877ad885137 100644
--- a/test/other/codesize/test_codesize_cxx_noexcept.jssize
+++ b/test/other/codesize/test_codesize_cxx_noexcept.jssize
@@ -1 +1 @@
-20255
+20261
diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize
index c3e8ba91df190..b1ae2d54cfb87 100644
--- a/test/other/codesize/test_codesize_files_js_fs.gzsize
+++ b/test/other/codesize/test_codesize_files_js_fs.gzsize
@@ -1 +1 @@
-7640
+7643
diff --git a/test/other/codesize/test_codesize_files_js_fs.jssize b/test/other/codesize/test_codesize_files_js_fs.jssize
index 61569c21c2a25..1da78483002dd 100644
--- a/test/other/codesize/test_codesize_files_js_fs.jssize
+++ b/test/other/codesize/test_codesize_files_js_fs.jssize
@@ -1 +1 @@
-18801
+18807
