Skip to content

Commit

Permalink
fix: support calling chmod on a directory (#870)
Browse files Browse the repository at this point in the history
* fix #558 -- chmodSync throws EISDIR for directories

- See #558

* restructure chmodSync tests
  • Loading branch information
williamstein committed Nov 3, 2022
1 parent 45973c3 commit 7c5999c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/__tests__/volume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,24 @@ describe('volume', () => {
}, 1);
});
});
describe('.chmodSync(path, mode)', () => {
it('works with directories', () => {
const vol = new Volume();
vol.mkdirSync('/dir');
vol.chmodSync('/dir', 0o666);
expect(vol.statSync('/dir').mode.toString(8)).toBe('40666');
vol.chmodSync('/dir', 0o777);
expect(vol.statSync('/dir').mode.toString(8)).toBe('40777');
});
it('works with files', () => {
const vol = new Volume();
vol.writeFileSync('/file', 'contents');
vol.chmodSync('/file', 0o666);
expect(vol.statSync('/file').mode.toString(8)).toBe('100666');
vol.chmodSync('/file', 0o777);
expect(vol.statSync('/file').mode.toString(8)).toBe('100777');
});
});
describe('.promises', () => {
it('Have a promises property', () => {
const vol = new Volume();
Expand Down
2 changes: 1 addition & 1 deletion src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ export class Volume {
}

private chmodBase(filename: string, modeNum: number) {
const fd = this.openSync(filename, 'r+');
const fd = this.openSync(filename, 'r');
try {
this.fchmodBase(fd, modeNum);
} finally {
Expand Down

0 comments on commit 7c5999c

Please sign in to comment.