unionfs icon indicating copy to clipboard operation
unionfs copied to clipboard

readdir fails on empty directory if another fss fails

Open dy-dx opened this issue 1 year ago • 0 comments

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();
});

dy-dx avatar Feb 21 '24 21:02 dy-dx