Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't fail on closing fd after reset has been called (#550) #1081

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -821,7 +821,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