memfs
memfs copied to clipboard
"appendFile" doesn't throw an error if the path contains dot
Hi, memfs doesn't throw an error when you want to create file with fn "appendFile" with path containing dots.
Current test:
it('Reject when trying to write on a directory', () => {
const vol = new Volume();
const { promises } = vol;
vol.fromJSON({
'/foo': null,
});
return expect(promises.appendFile('/foo', 'bar')).rejects.toBeInstanceOf(Error);
});
src.: https://github.com/streamich/memfs/blob/master/src/tests/promises.test.ts#L263
Should be added one more test smth like:
it('Reject when trying to write on a file with non existing parental directory containing dots', () => {
const vol = new Volume();
const { promises } = vol;
vol.fromJSON();
return expect(promises.appendFile('/foo.ts/bar.ts', '...')).rejects.toBeInstanceOf(Error);
});
The problem is in the path: '/foo.ts/bar.ts'. The parental directory does not exist, but if you call:
const stats1 = await promises.lstat('/foo.ts')
stats1.isFile() // returns true, but should be false, it should be directory
const stats2 = await promises.lstat('/foo.ts/bar.ts')
stats2.isFile() // returns true
Correct behavior:
Should return an error ENOTDIR: not a directory, rmdir '.../foo.ts'