Skip to content

Commit

Permalink
fix: don't fail on closing fd after reset has been called (#550) (#1081)
Browse files Browse the repository at this point in the history
* fix: don't fail on closing fd after reset has been called (#550)

* fix: only skip EBADF errors on async close and only when aborted

* fix: remove abortControllers and just call closeFile asynchronously from
close
  • Loading branch information
adiktofsugar authored Dec 30, 2024
1 parent f389874 commit ede0f4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/__tests__/volume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,23 @@ describe('volume', () => {
'/good': 'bye',
});
});
it('Open streams should not be affected', async () => {
const vol = new Volume();
const json = {
'/hello': 'world',
};
vol.fromJSON(json);
await new Promise((resolve, reject) => {
vol
.createReadStream('/hello')
.on('data', () => null)
.on('close', resolve)
.on('end', () => {
vol.reset();
})
.on('error', reject);
});
});
});
describe('.openSync(path, flags[, mode])', () => {
const vol = new Volume();
Expand Down
4 changes: 3 additions & 1 deletion src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,9 @@ export class Volume implements FsCallbackApi, FsSynchronousApi {

close(fd: number, callback: TCallback<void>) {
validateFd(fd);
this.wrapAsync(this.closeSync, [fd], callback);
const file = this.getFileByFdOrThrow(fd, 'close');
// NOTE: not calling closeSync because we can reset in between close and closeSync
this.wrapAsync(this.closeFile, [file], callback);
}

private openFileOrGetById(id: TFileId, flagsNum: number, modeNum?: number): File {
Expand Down

0 comments on commit ede0f4f

Please sign in to comment.