isomorphic-git / lightning-fs

A lean and fast 'fs' for the browser
MIT License
487 stars 48 forks source link

It is possible to write in a directory as if it was a file #119

Closed elegaanz closed 1 year ago

elegaanz commented 1 year ago

writeFile will happily write to a path that is currently a directory. The children of the directory will be kept, but its type will become 'file' and thus any subsequent operation will throw ENOTDIR.

Here is a minimal example.

import FS from "@isomorphic-git/lightning-fs";

const fs = new FS("demo");
const pfs = fs.promises;

const main = async () => {
  await pfs.mkdir("/foo");
  await pfs.writeFile("/foo", "bar");
  await pfs.readdir("/foo"); // throws ENOTDIR
};

main();

In Node, the following error is thrown by writeFile: Uncaught [Error: EISDIR: illegal operation on a directory, open 'test']

jcubic commented 1 year ago

Thanks for the report, do you want to contribute and throw an error if the path is a directory?

elegaanz commented 1 year ago

I can try to make a PR in the next days hours, yes.