Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subsumes fails in case insensitive file systems #194

Open
salva opened this issue Jun 16, 2017 · 6 comments
Open

subsumes fails in case insensitive file systems #194

salva opened this issue Jun 16, 2017 · 6 comments
Labels

Comments

@salva
Copy link

salva commented Jun 16, 2017

On Windows, where file systems are usually case insensitive, Tiny::Path::subsumes doesn't take that fact into account.

 path('C:\\WINDOWS')->subsumes('C:\\Windows\\system32')    --> fail
 path('C:\\windows')->subsumes('c:\\windows\\system32')    --> ok (note "C:" Vs "c:")

A workaround could be to use realpath, but it doesn't adjust the case accordingly with the file system. For instance:

path('c:\\windows')->realpath eq path('c:\\WINDOWS')->realpath --> fail

It this behavior is not fixed, at least if should be documented.

@salva
Copy link
Author

salva commented Jun 16, 2017

I have found that relative handles case insensitiveness correctly:

path("c:\\WiNdOwS\\System32")->relative("C:\\windows\\")    ---> 'System32'

@xdg
Copy link
Contributor

xdg commented Jun 16, 2017

Does this patch fix subsumes: https://gist.github.com/xdg/55fcb8ded88bce5073e1888c55cf4d3c

@salva
Copy link
Author

salva commented Jun 16, 2017

That fixes the issue for most cases including the one affecting me, but note that case-sensitiveness is not a property of the operating system but of the file system. So, there is a very edge case where subsume would report a false positive once that patch is applied.

For instance, a case sensitive file system for Windows I use almost daily is the VirtualBox shared folders one which I use to mount file systems from my main host Linux machine into guest Windows virtual machines.

Anyway, I am not saying you should fix that, just want to make you aware that case exists!

@xdg
Copy link
Contributor

xdg commented Jun 16, 2017

It's a hard to problem to address efficiently in general.

E.g. given a directory you don't have write access to, how do you tell if it's on a case-sensitive filesystem or not?

Maybe some general documentation about it would be a good idea.

@salva
Copy link
Author

salva commented Jun 19, 2017

E.g. given a directory you don't have write access to, how do you tell if it's on a case-sensitive filesystem or not?

There is a different approach for that: you can use Win32::GetLongPathName($path) to get the canonical file name as stored in the file system. Though, that only works for file/directories that already exist on the file system.

IMO, a good compromise would be to leave subsumes as it is and make realpath call GetLongPathName under the hood. subsumes is already documented to be dumb, not resolving symbolic links or relative paths so, case sensitiveness could also be added to that list. And it makes perfect sense to have realpath return the name as stored in the file system.

Other alternative that occurs to me, is to add shortpath and longpath methods into Path::Tiny (which would do nothing on non-windows systems), and let the user decide when to call them.

@xdg
Copy link
Contributor

xdg commented Jun 20, 2017

There's something appealing in that solution -- but since relative handles case insensitivity (albeit crudely), I sort of feel like subsumes ought to do the same.

Another approach -- possibly for both subsumes and relative -- might be to default to case insensitivity on Win32, but provide a force_case_sensitive option that users can pass for special cases.

@xdg xdg added the bug label Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants