Skip to content

Commit

Permalink
fix streamich#391 -- "utimes" doesn't work for directories
Browse files Browse the repository at this point in the history
- "EISDIR: illegal operation on a directory, open ..." error
- streamich#391
  • Loading branch information
williamstein committed Oct 26, 2022
1 parent dd3828a commit f20dbf7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/__tests__/volume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f20dbf7

Please sign in to comment.