diff --git a/emsdk/patches/posixish_memfs.patch b/emsdk/patches/posixish_memfs.patch new file mode 100644 index 000000000..926feb4b3 --- /dev/null +++ b/emsdk/patches/posixish_memfs.patch @@ -0,0 +1,38 @@ +Modify MEMFS to update timestamp of parent directory on file creation and removal. +More POSIXish compliant for a one timestamp fs, behaves like a modification date. + +--- a/emsdk/fastcomp/emscripten/src/library_memfs.js 2019-08-19 18:11:40.000000000 +0200 ++++ b/emsdk/fastcomp/emscripten/src/library_memfs.js 2020-12-23 12:22:38.000000000 +0100 +@@ -88,6 +88,7 @@ + // add the new node to the parent + if (parent) { + parent.contents[name] = node; ++ parent.timestamp = node.timestamp; + } + return node; + }, +@@ -213,12 +214,16 @@ + } + // do the internal rewiring + delete old_node.parent.contents[old_node.name]; ++ var now = Date.now(); ++ old_node.parent.timestamp = now; + old_node.name = new_name; + new_dir.contents[new_name] = old_node; ++ new_dir.timestamp = now; + old_node.parent = new_dir; + }, + unlink: function(parent, name) { + delete parent.contents[name]; ++ parent.timestamp = Date.now(); + }, + rmdir: function(parent, name) { + var node = FS.lookupNode(parent, name); +@@ -226,6 +231,7 @@ + throw new FS.ErrnoError({{{ cDefine('ENOTEMPTY') }}}); + } + delete parent.contents[name]; ++ parent.timestamp = Date.now(); + }, + readdir: function(node) { + var entries = ['.', '..']; diff --git a/emsdk/tests/test_memfsmtime.py b/emsdk/tests/test_memfsmtime.py new file mode 100644 index 000000000..4338ce8e0 --- /dev/null +++ b/emsdk/tests/test_memfsmtime.py @@ -0,0 +1,78 @@ +import subprocess +from . import common + + +def test_memfsmtime(tmpdir): + with tmpdir.as_cwd(): + with open("main.c", "w") as f: + f.write( + r"""\ +#include +#include +#include +#include +#include +#include +#include + +void mysleep(int delta) +{ + time_t end = time(NULL) + delta; + + while (time(NULL) t0); + assert(t1 == t2); + mysleep(1); + unlink(fname); + t3 = getmtime(tmpdir); + assert(t3 > t1); +} +""" + ) + + subprocess.run( + [ + "emcc", + "-s", + "MAIN_MODULE=1", + "main.c", + ], + check=True, + env=common.env, + ) + out = subprocess.run( + ["node", "a.out.js"], capture_output=True, check=False, env=common.env + ) + assert out.returncode == 0