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

readdir fails on empty directory if another fss fails #782

Closed
dy-dx opened this issue Feb 21, 2024 · 0 comments · Fixed by #787
Closed

readdir fails on empty directory if another fss fails #782

dy-dx opened this issue Feb 21, 2024 · 0 comments · Fixed by #787

Comments

@dy-dx
Copy link
Contributor

dy-dx commented Feb 21, 2024

The readdir method fails on an empty directory, if it is not present on the first filesystem.

Failing test case:

import { Volume } from 'memfs';

it('does not throw when directory is empty and first fs fails', () => {
  const vol = Volume.fromJSON({});
  const vol2 = Volume.fromJSON({
    '/foo': null,
  });

  const ufs = new Union();
  ufs.use(vol as any);
  ufs.use(vol2 as any);
  expect(() => ufs.readdirSync('/foo')).not.toThrow();
});

However, the test passes if the fs order is swapped:

it('does not throw when directory is empty and second fs fails', () => {
  const vol = Volume.fromJSON({
    '/foo': null,
  });
  const vol2 = Volume.fromJSON({});

  const ufs = new Union();
  ufs.use(vol as any);
  ufs.use(vol2 as any);
  expect(() => ufs.readdirSync('/foo')).not.toThrow();
});

It also passes if the directory is not empty:

it('does not throw when directory is not empty and first fs fails', () => {
  const vol = Volume.fromJSON({});
  const vol2 = Volume.fromJSON({
    '/foo/child': null,
  });

  const ufs = new Union();
  ufs.use(vol as any);
  ufs.use(vol2 as any);
  expect(() => ufs.readdirSync('/foo')).not.toThrow();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant