From f20dbf73d9f8cbd4cc2b2311766335bb4893b411 Mon Sep 17 00:00:00 2001 From: William Stein Date: Tue, 25 Oct 2022 18:24:26 -0700 Subject: [PATCH 1/3] fix #391 -- "utimes" doesn't work for directories - "EISDIR: illegal operation on a directory, open ..." error - https://github.com/streamich/memfs/issues/391 --- src/__tests__/volume.test.ts | 13 ++++++++++--- src/volume.ts | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/__tests__/volume.test.ts b/src/__tests__/volume.test.ts index 53a1f8933..39c39f2c3 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 4f635324a..18cbf7801 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -1881,7 +1881,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 { From d59c1892dee1f46a09fa6a889ddb94155a06829d Mon Sep 17 00:00:00 2001 From: William Stein Date: Tue, 25 Oct 2022 20:21:47 -0700 Subject: [PATCH 2/3] run prettier --- src/__tests__/volume.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/volume.test.ts b/src/__tests__/volume.test.ts index 39c39f2c3..0f0c312d0 100644 --- a/src/__tests__/volume.test.ts +++ b/src/__tests__/volume.test.ts @@ -969,7 +969,7 @@ describe('volume', () => { 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)", () => { + 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); From 5fa2c7075750bebc9507d00aadce243dca580013 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 30 Oct 2022 08:55:04 +1300 Subject: [PATCH 3/3] test: adjust spec title --- src/__tests__/volume.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/volume.test.ts b/src/__tests__/volume.test.ts index 319cd68dd..7f393a31a 100644 --- a/src/__tests__/volume.test.ts +++ b/src/__tests__/volume.test.ts @@ -976,7 +976,7 @@ describe('volume', () => { 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)', () => { + it('Sets times on a directory', () => { vol.utimesSync('/foo', 1234, 12345); const stats = vol.statSync('/foo'); expect(Math.round(stats.atime.getTime() / 1000)).toBe(1234);