Skip to content

Commit

Permalink
fix: support calling utimes on a directory (#866)
Browse files Browse the repository at this point in the history
* 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 <Jones258@Gmail.com>
  • Loading branch information
williamstein and G-Rath authored Oct 29, 2022
1 parent 56eae5d commit 301f2d1
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 @@ -968,10 +968,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', () => {
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 301f2d1

Please sign in to comment.