Add case sensitive check (independent of file system)
Original issue by @matz3
A file called test.js on the file system can be loaded from the server with different cases like Test.js or TEsT.js when using a case insensitive files system (Windows, Mac).
This can cause problems as local development works fine but when deploying to a linux based server the file can't be found anymore.
Background
Tomcat had a caseSensitive configuration with default true to do a case sensitive check also for case insensitive file systems. This config has been removed with Tomcat 7 to always enable this behavior.
See: http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
Affected components
- [ ] ui5-builder
- [ ] ui5-server
- [ ] ui5-cli
- [x] ui5-fs
- [ ] ui5-project
- [ ] ui5-logger
Possible solutions include:
- Use
readdir(dirname)and compare the result with the requested file name- Doesn't necessary catch case errors in the path leading up to that directory, like
/resources/SAP/UI/core/Core.js
- Doesn't necessary catch case errors in the path leading up to that directory, like
- Use
fs.realpath.native(path)to resolve the requested path. This worked in my tests whilefs.realpathdid not. More testing/understanding is needed here.
Things from the Node.js documentation on Working with Different Filesystems to consider:
Instead of keeping a list of every known filesystem and behavior (which is always going to be incomplete), you can probe the filesystem to see how it actually behaves.
If you know that the filesystem does not preserve case, then you should be prepared to see ABC in a directory listing when your program creates abc. But if you know that the filesystem does preserve case, then you should consider ABC to be a different filename to abc, when detecting file renames or if the filesystem is case-sensitive.
What's interesting here is the following scenario (which needs to be confirmed):
I have an application with a dependency to sap/ui/Core. My file system is Non-case-preserving (e.g. FAT16). This means that, depending on the solution for the issue above, the request would need to be created for /resources/SAP/UI/CORE.JS (the first part of the URL is "virtual").
Reg. your last comment: I'm not aware of any file system that works like that. Either they completely ignore case (DOS, older Windows), or they preserve case but do not distinguish files by case (FAT on Windows since maybe 3.11 or so, NTFS, default configuration on macOS). Linux and macOS in a non-default configuration are really case sensitive, they allow multiple files in the same folder that only differ in case. But when deployment (git clone, deploy to server, copy step, whatever...) create a file with a specific spelling (e.g. sap/ui/core/Core.js) it should on all relevant file systems be possible to read the file by the exact same name. The issue here IMO is only about accessing it with a different name.
Hi just solved this issue in the serve static package of express. I Used the way described here https://stackoverflow.com/a/54036097/4182487 it recurses up all the folders to check the whole path.