tschaub / mock-fs

Configurable mock for the fs module
https://npmjs.org/package/mock-fs
Other
906 stars 86 forks source link

Feature request: `noatime` to prevent `atime` being updated on file access #368

Closed bentorkington closed 1 year ago

bentorkington commented 1 year ago

Background: in normal use, even when one only reads from a filesystem, there is still one property that is modified: the atime property of files and directories. This of course is not the case when a filesystem is mounted read-only, or mounted with the noatime option on Linux.

Because one might use mock-fs to test a tool depends on all properties of items remaining stable (e.g. something that creates a tarball) it would be useful to emulate this noatime behaviour so that subsequent accesses produce exactly the same results.

Could this be achieved by an option that replaces Item.setATime() with a no-op?

3cp commented 1 year ago

You don't need mock-fs to add a feature.

JS allows you to monkey patch.

const Item = require('mock-fs/lib/item.js');
Item.prototype.setATime = function () {};

The noatime feature is probably little bit out of scope for mock-fs, as there are quite a few others options like nobrowse, rw, ro, nosuid, nodev, ...

bentorkington commented 1 year ago

JS allows you to monkey patch.

thanks, you're right, it's so easy to monkey-patch this that there's no need to add complication to mock-fs