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

Watch directory for new files #116

Closed
jacobalberty opened this issue Mar 8, 2018 · 4 comments
Closed

Watch directory for new files #116

jacobalberty opened this issue Mar 8, 2018 · 4 comments
Labels

Comments

@jacobalberty
Copy link

jacobalberty commented Mar 8, 2018

the memfs.watch() function doesn't seem to work on directories. The following code works as expected:

var fs = require('fs');
if (fs.vol) fs.vol.fromJSON({ '/tmp': {}});
var fswatcher = fs.watch('/tmp', console.log);
fs.writeFileSync('/tmp/test.file', 'test data');
fs.unlinkSync('/tmp/test.file');
setTimeout(() => {fswatcher.close()}, 500);

Producing the output:

rename test.file
change test.file
rename test.file

but change it to use memfs instead::

var fs = require('memfs');
if (fs.vol) fs.vol.fromJSON({ '/tmp': {}});
var fswatcher = fs.watch('/tmp', console.log);
fs.writeFileSync('/tmp/test.file', 'test data');
fs.unlinkSync('/tmp/test.file');
setTimeout(() => {fswatcher.close()}, 500);

and I get no output.

EDIT: Changed the test code to be a little simpler and make the two cases much closer to each other with only a single line change.

@alexpts
Copy link

alexpts commented Aug 27, 2021

Is there any progress?

@williamstein
Copy link
Contributor

I just noticed that memfs doesn't properly update directory timestamps (as it should according to POSIX) when files are added/removed in a directory. This is probably related to your problem. I'll at least make an issue about this.

@williamstein
Copy link
Contributor

I don't think my #869 is relevant. However, I just tried your example with the current version of memfs (from this repo at least) and it worked fine for me, and did show output. Maybe this bug is fixed?

@streamich
Copy link
Owner

Closing as per #116 (comment) it might be fixed. Please re-open, if not.

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

No branches or pull requests

4 participants