Skip to content
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

Directory modification time should be update when "contents of directory" of changes #869

Open
williamstein opened this issue Oct 26, 2022 · 2 comments

Comments

@williamstein
Copy link
Contributor

This could related to #116.

The rules are possibly complicated (see [1] and [2]), but certain operations, e.g., "create a new file" in a directory should result in the modification timestamp of the directory itself being updated. Posix OS's rely on this behavior; as an example, Python won't scan a path again if its time isn't updated, so without this behavior you can't install new modules in a running Python session, which is causing trouble for python-wasm. Here's a simple example to illustrate the problem:

~/upstream/memfs-js$ node
Welcome to Node.js v19.0.0.
Type ".help" for more information.
> require('nemfs').vol.fromJSON({'/x/y': '...'}); vol=require('.').vol; 0;
0
> vol.statSync('/x').mtime
2022-10-26T01:53:18.917Z
> vol.mkdirSync('/x/z')
undefined
> vol.statSync('/x').mtime
2022-10-26T01:53:18.917Z

Note that the mtime did not change. Now try the same on your normal filesystem:

/tmp$ rm -rf x
/tmp$ mkdir x; touch x/y
/tmp$ node
Welcome to Node.js v19.0.0.
Type ".help" for more information.
> require('fs').statSync('/tmp/x').mtime
2022-10-26T01:54:22.172Z
> require('fs').mkdirSync('/tmp/x/z')
undefined
> require('fs').statSync('/tmp/x').mtime
2022-10-26T01:54:52.265Z

Notice that the timestamp changed this time.

I haven't even begun to think about how to implement this in memfs, but I do think it's important and not doing so leads to subtle bugs, so I'll try...

[1] https://stackoverflow.com/questions/3451863/when-does-a-unix-directory-change-its-timestamp
[2] https://medium.com/@quoscient/mac-b-timestamps-across-posix-implementations-linux-openbsd-freebsd-1e2d5893e4f

williamstein added a commit to sagemathinc/memfs-js that referenced this issue Oct 26, 2022
- see #4
- I'm not 100% sure I got the posix semantics right.  This is
a lot better than doing absolutely nothing though!
- See streamich#869 to see
if there was any discussion on upstream.
@williamstein
Copy link
Contributor Author

Here is how I fixed this is @cowasm/memfs: sagemathinc@8454383

If you like this and agree with the semantics (?), let me know and I'll create a PR.

@G-Rath
Copy link
Collaborator

G-Rath commented Nov 3, 2022

@williamstein let's open a PR and go from there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants