-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
"utimes" doesn't work for directories: "EISDIR: illegal operation on a directory, open ..." error #391
Comments
I've also run into this issue. Any solutions? |
This seems related to #58. Maybe |
For what it is worth, here is how I fixed this in my fork (following your suggestions above, and adding a test): ~/upstream/memfs-js$ git show HEAD
commit 671af81ba00e546a10581217f43d32f2406dec6b (HEAD -> main)
Author: William Stein <[email protected]>
Date: Tue Oct 25 17:56:15 2022 -0700
fix #2 -- utimesSync doesn't work on directories
- also is upstream https://github.com/streamich/memfs/issues/391
diff --git a/src/__tests__/volume.test.ts b/src/__tests__/volume.test.ts
index 53a1f89..39c39f2 100644
--- a/src/__tests__/volume.test.ts
+++ b/src/__tests__/volume.test.ts
@@ -961,10 +961,17 @@ describe('volume', () => {
});
describe('.utimesSync(path, atime, mtime)', () => {
const vol = new Volume();
+ vol.mkdirSync('/foo');
it('Set times on file', () => {
- vol.writeFileSync('/lol', '12345');
- vol.utimesSync('/lol', 1234, 12345);
- const stats = vol.statSync('/lol');
+ vol.writeFileSync('/foo/lol', '12345');
+ vol.utimesSync('/foo/lol', 1234, 12345);
+ const stats = vol.statSync('/foo/lol');
+ expect(Math.round(stats.atime.getTime() / 1000)).toBe(1234);
+ expect(Math.round(stats.mtime.getTime() / 1000)).toBe(12345);
+ });
+ it("Sets times on a directory (see https://github.com/streamich/memfs/issues/391)", () => {
+ vol.utimesSync('/foo', 1234, 12345);
+ const stats = vol.statSync('/foo');
expect(Math.round(stats.atime.getTime() / 1000)).toBe(1234);
expect(Math.round(stats.mtime.getTime() / 1000)).toBe(12345);
});
diff --git a/src/volume.ts b/src/volume.ts
index b34860e..e4b05e8 100644
--- a/src/volume.ts
+++ b/src/volume.ts
@@ -1882,7 +1882,7 @@ export class Volume {
}
private utimesBase(filename: string, atime: number, mtime: number) {
- const fd = this.openSync(filename, 'r+');
+ const fd = this.openSync(filename, 'r');
try {
this.futimesBase(fd, atime, mtime);
} finally { |
- also is upstream streamich#391
@williamstein I'm happy to review a pull request if you want to open one 🙂 |
Cool! I will. |
- "EISDIR: illegal operation on a directory, open ..." error - streamich#391
OK, I created #866 for this. |
Thanks, I'll have a look once I'm off work - it seems like you need to apply prettier to your PRs too. |
Done. This memfs codebase is some unusually good quality code. Thanks for maintaining it! |
* fix #391 -- "utimes" doesn't work for directories - "EISDIR: illegal operation on a directory, open ..." error - #391 * run prettier * test: adjust spec title Co-authored-by: Gareth Jones <[email protected]>
🎉 This issue has been resolved in version 3.4.9 🎉 The release is available on: Your semantic-release bot 📦🚀 |
utimes
callsutimesBase
which usesopenSync
call internally butopenSync
call on a directory obviously throwsEISDIR
error.memfs/src/volume.ts
Lines 1771 to 1778 in 674a1e7
The text was updated successfully, but these errors were encountered: