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

Discrepancy in close-after-unlink behavior #942

Open
dmurvihill opened this issue Aug 18, 2023 · 1 comment
Open

Discrepancy in close-after-unlink behavior #942

dmurvihill opened this issue Aug 18, 2023 · 1 comment

Comments

@dmurvihill
Copy link

The fs module accepts calls to FileHandle.close() when the underlying file no longer exists, while memfs throws ENOENT. I suspect this could be the root cause of #550 and #900.

Reproduction cases (ts-jest):

describe('memfs/fs parity', () => {
  const testPath = path.join(__dirname, 'my-test-file');
    
  it('fs does not error on close after delete', async () => {
    const f = await fs.open(testPath, 'w');
    await fs.unlink(testPath);
    await f.close();
  });

  it('memfs should not error on close after delete', async () => {
    const f = await memfs.fs.promises.open(testPath, 'w');
    await memfs.fs.promises.unlink(testPath);
    await f.close();
  });
});

Error message:

 FAIL  test/fs.spec.ts (5.259 s)
  ● memfs/fs parity › memfs should not error on close after delete

    ENOENT: no such file or directory, open '/Users/dolan/IdeaProjects/big-shuffle/test/my-test-file'

      at createError (node_modules/memfs/src/node/util.ts:138:17)
      at Volume.openFile (node_modules/memfs/src/volume.ts:684:38)
      at Volume.openBase (node_modules/memfs/src/volume.ts:696:23)
      at Immediate.<anonymous> (node_modules/memfs/src/volume.ts:516:25)
@G-Rath
Copy link
Collaborator

G-Rath commented Aug 18, 2023

Makes sense - happy to accept a PR for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants