memfs icon indicating copy to clipboard operation
memfs copied to clipboard

Support for case sensitivity settings

Open piotr-oles opened this issue 5 years ago • 8 comments

Hi! As you probably know, there are 2 options for case sensitivity:

  • Windows use case sensitive paths,
  • other systems like macOS or Linux use case insensitive paths

I checked how memfs behave and it seems that it uses case sensitive approach:

const { fs } = require('memfs');

fs.writeFileSync('/my/Case/sensitive/Path.txt', 'content');

console.log(fs.readFileSync('/my/case/sensitive/path.txt'));
// logs undefined
// if I would use native fs on macOS or Linux, I would get "content" logged
// so it's kind of inconsistency between memfs and fs

It would be nice if:

  1. there would be an option to configure it
  2. the default behavior would be to use system settings

piotr-oles avatar May 06 '20 20:05 piotr-oles

  1. there would be an option to configure it

Yes, it seems we could add support for case insensitive paths.

  1. the default behavior would be to use system settings

I'm not sure if memfs should "magically" change the way it handles paths; I would prefer it is set explicitly. But happy to hear opinions.

streamich avatar May 10 '20 22:05 streamich

I might be missing something, but:

As you probably know, there are 2 options for case sensitivity:

The OSs act the opposite way around from your list: Windows is case insensitive, while UNIX is case sensitive.

image

I'm not sure if memfs should "magically" change the way it handles paths

For now I agree with that - I think memfs should be careful adopting "magical" features since they tend to be very "gain this, lose that", but an explicit option could work.

I think in this case actually the OS side should be ignored, since the reason why fs is/isnt case-sensitive is because of the underlying OS/FS rather than node; aka it's not Node going "oh you're on Linux" and changing its behaviour; it's instead a result of the underlying API calls V8 makes to the native file system, which behaves accordingly.

Because of that, I think you could make a case for saying something like having the current behavior being the "default", and then implementing a ignoreCase option that causes memfs to just call toLowerCase on everything?

G-Rath avatar May 10 '20 23:05 G-Rath

On an aside: I think memfs should probably favor defaulting to unix behaviours since it already uses the unix file path format (i.e /my/path/ instead of C:\my\path).

That way you'd be less surprised - i.e if we had ignoreCase be based on the OS, then it would make it reasonable to also assume you could use C:\my\path when running on Windows, which you can't.

G-Rath avatar May 10 '20 23:05 G-Rath

I might be missing something, but:

As you probably know, there are 2 options for case sensitivity:

The OSs act the opposite way around from your list: Windows is case insensitive, while UNIX is case sensitive.

Yes, I was wrong about Windows, but still, macOS is case-insensitive 😃

Because of that, I think you could make a case for saying something like having the current behavior being the "default", and then implementing a ignoreCase option that causes memfs to just call toLowerCase on everything?

Yes, Implementing it just as a configuration option would be enough 👍

piotr-oles avatar May 12 '20 19:05 piotr-oles

macOS is case-insensitive

Interesting, that is very useful to know given that most of our devs at work are on macs while our servers are Ubuntu 😄 😬

G-Rath avatar May 12 '20 20:05 G-Rath

Is it something that I could expect to be implemented by one of the maintainers, or you would like to get a PR from me? 😃

piotr-oles avatar May 15 '20 09:05 piotr-oles

@piotr-oles PR from you :)

streamich avatar May 15 '20 09:05 streamich

Turns out this is not that hard to implement. I opened #632 to make case sensitivity configurable.

ajafff avatar Feb 09 '21 21:02 ajafff