Skip to content

Commit

Permalink
fix #2 -- utimesSync doesn't work on directories
Browse files Browse the repository at this point in the history
- also is upstream streamich#391
  • Loading branch information
williamstein committed Oct 26, 2022
1 parent f567206 commit 671af81
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 @@ -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 {
Expand Down

0 comments on commit 671af81

Please sign in to comment.