runtime icon indicating copy to clipboard operation
runtime copied to clipboard

UseStaticFiles should provide a case insensitive option in StaticFileOptions

Open mchandler-manticore opened this issue 6 years ago • 32 comments

Is your feature request related to a problem? Please describe.

My team ran into an issue where we develop on windows with case insensitive file system and returning static files using lower case links but when deploying on linux (case sensitive file system) in docker the same links no longer worked as the files had camel case on disk

Describe the solution you'd like

Add a boolean value to StaticFileOptions to enable static files to resolve files on disk ignoring file system case thus having the same behavior on windows and linux.

Additional context

Example file: /wwwroot/MyTestFile.txt Link http://localhost/mytestfile.txt works on windows doesnt work on linux

mchandler-manticore avatar Apr 16 '20 19:04 mchandler-manticore

The file lookup is managed by the IFileProvider implemented by PhysicalFileProvider in this example. https://github.com/dotnet/runtime/blob/master/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs

Case in-sensitivity isn't something StaticFiles can fake from the top down, you'd need this option on the underlying file APIs first.

Recommend transferring this to Runtime.

Tratcher avatar Apr 16 '20 20:04 Tratcher

Transferring this to runtime. The change that would be needed here is to have a case-insensitive mode to file providers.

Having said that, we already know there are case-sensitive file systems in use (Linux, as you noted) and making the file providers case-insensitive even when on a case-sensitive file system is very tricky and disruptive.

analogrelay avatar Apr 17 '20 20:04 analogrelay

I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.

Dotnet-GitSync-Bot avatar Apr 17 '20 20:04 Dotnet-GitSync-Bot

It's not clear what the API request is here. Can you make a formal API request?

Also, keep in mind that even on windows you can now make the file system case-sensitive so the value of such a feature here might be diminished.

ericstj avatar Jul 09 '20 18:07 ericstj

I'm not going to back this at all, but in fact this is to my eyes a very clear item. API surface is something like bool ForceCaseInsensitive {get;set;} = false; Trying to provide case insensitive APIs in general is very hard for lots of obvious reasons, but it's easy enough to do on a pure reader. Or maybe ForceLowerCase is better; hard to tell.

jhudsoncedaron avatar Jul 16 '20 20:07 jhudsoncedaron

We have issues tracking this request on dotnet/runtime repo already: https://github.com/dotnet/runtime/issues/23871, https://github.com/dotnet/runtime/issues/14321, https://github.com/dotnet/runtime/issues/17873

@Tratcher what is the underlying API that would end up calling a new API that allows for checking case sensitivity?

maryamariyan avatar Oct 16 '20 23:10 maryamariyan

Here: https://github.com/dotnet/runtime/blob/75090807267d3a06c9ad806c6d33e773f69675bc/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs#L243-L265

Case sensitivity would be a new option on the PhysicalFileProvider, and it would use that when creating a new FileInfo.

Also here when listing the contents of directories: https://github.com/dotnet/runtime/blob/75090807267d3a06c9ad806c6d33e773f69675bc/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs#L307 https://github.com/dotnet/runtime/blob/75090807267d3a06c9ad806c6d33e773f69675bc/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/Internal/PhysicalDirectoryContents.cs#L61

Tratcher avatar Oct 16 '20 23:10 Tratcher

Seems like a new API addition for System.IO.

cc: @carlossanlop @Jozkee

maryamariyan avatar Oct 16 '20 23:10 maryamariyan

Any new information here?

DamianGuth avatar Jul 27 '22 06:07 DamianGuth

We came across this in our application as well. Any update on this would be appreciated

MarvinKlein1508 avatar Jul 27 '22 14:07 MarvinKlein1508

Yeah, any update on this would help a lot...

0x6DD8 avatar Jul 29 '22 13:07 0x6DD8

@MarvinKlein1508 , @0x6DD8 An implementation of static file provider is about 600 lines of mostly boilerplate code; maybe less in truly modern C#.

jhudsoncedaron avatar Jul 29 '22 14:07 jhudsoncedaron

After 3 years, there is still no solution for linux?

7702244 avatar Feb 10 '23 14:02 7702244

Is there a proposal?

davidfowl avatar Feb 10 '23 15:02 davidfowl

@davidfowl : That's trivial.

jhudsoncedaron avatar Feb 10 '23 15:02 jhudsoncedaron

@jhudsoncedaron Did you send a pull request with the solution?

davidfowl avatar Feb 10 '23 15:02 davidfowl

@davidfowl That's a different question. I'm not going to lift a finger unless it's approved first. A proposal is trivial. Getting a PR approved for a request that isn't approved first is not.

jhudsoncedaron avatar Feb 10 '23 15:02 jhudsoncedaron

I guess I missed the proposal. I re-read this a couple of times and I see this suggestion but I don't know what the end to end proposal is for this feature. How would it work?

davidfowl avatar Feb 10 '23 15:02 davidfowl

It's pretty clear that OP wants to develop on Windows and run the output on Linux. So you run the directory descent piecewise matching case insensitive by matching the output of directory enumeration. It would be easier if I could use my own libraries because System.IO.Directory is pretty bad; but that's a different problem.

jhudsoncedaron avatar Feb 10 '23 15:02 jhudsoncedaron

So the file provider enumerates the entire directory tree up front? If not, what happens in GetFileInfo?

davidfowl avatar Feb 10 '23 16:02 davidfowl