jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.07k stars 217 forks source link

edge case: fs.stat throws 'ENOTDIR' instead of 'ENOENT' #205

Closed billiegoose closed 6 years ago

billiegoose commented 6 years ago

Edge case, maybe not worth fixing but worth posting on the Internet in case it helps someone.

On Node, if I have a file, say "README.txt" and do fs.stat('README.txt/.git') I will get ENOENT. However, because README.txt is an actual file, if you do fs.stat('README.txt/.git') in BrowserFS you end up getting a different error, 'ENOTDIR', directly from IndexedDBFileSystem.getDirListing.

jvilk commented 6 years ago

Ah, that is an interesting edge case. I'd accept a pull request for a fix.

billiegoose commented 6 years ago

I've got too much on my plate right now. But I find googling errors and finding the Github issue(s) people have made and the resulting discussions extremely useful, even if the issues are never closed. :)

jvilk commented 6 years ago

@wmhilton this is not a bug, and is FS dependent. For example, on my Mac, the following happens in Node v9.3.0:

> fs.statSync('README.md/fakefile')
Error: ENOTDIR: not a directory, stat 'README.md/fakefile'
    at Object.fs.statSync (fs.js:968:11)

Thus, I am closing this as invalid.

billiegoose commented 6 years ago

I can replicate that result. I get 'ENOTDIR' on a Mac and 'ENOENT' on Windows. So apparently what error to return is not well defined behavior.

Too bad file systems don't use HTTP statuses; then it would just be '404 Not Found'.