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
A robust way to check for a case sensitive file system #1586
Conversation
Nice! This is a clever way to do the trick. There is one drawback, though: if, on a case-sensitive filesystem, both capitalizations happen to exist as separate files, it will look like a case-insensitive filesystem. Maybe we need an extra check to see whether they're the same inode? Also, since the check is somewhat generic, it would be great to move the logic to Finally, it looks like Travis is complaining about something. |
Well, I guess I missed this case... 😮 - fixed it but it is not easy for windows. Beets has to create a test file there. I also moved the method to The failing testcase checks if case sensitivity is detected correctly for windows and MacOS. This has to fail now... But I've got no clue how to write a test case for the new function. Any ideas? Or should I remove the tests? |
@@ -61,9 +60,9 @@ def __init__(self, field, pattern, fast=True, case_sensitive=None): | |||
""" | |||
super(PathQuery, self).__init__(field, pattern, fast) | |||
|
|||
# By default, the case sensitivity depends on the platform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is probably still relevant (although perhaps "platform" -> "filesystem"?).
Aha, thanks for continuing to dig. This does indeed look painful on Windows. I noticed that Python 3 added a https://hg.python.org/cpython/file/tip/Lib/genericpath.py#l87 |
And about the tests: it looks to me like most of the failures, like this one, are because |
# Conflicts: # docs/changelog.rst
I also read the error like you, but that's odd: |
Yeah, that's pretty strange. Do you get this error if you run the tests locally on your machine? |
…ome previously failed test cases.
Aha, I guess I found something 😄: Yes, the tests fail when executed locally, too. Stepping through the code (and especially into |
Ah! Good catch; it was an over-broad mock in the test harness. Thanks! I'll explore the behavior on Windows and check back in. |
I've added some more tests to test the case sensitivity detection for more cases. I also added some comments so we might be able to understand the testing code the next time we read it 😉 |
# Conflicts: # docs/changelog.rst
I had a look on the Python 3 implementation of |
😢 For reference, here's where The Watchdog project has reimplemented stat on Windows to get around this problem. There's discussion about it in gorakhargosh/watchdog#195. And here's a simpler implementation just for checking for the same file on Windows that also uses GetFileInformationByHandle. |
It looks like we can get almost there on Python 2 using
Alternatively, we could use What a mess! I would love to avoid creating a temporary file and then deleting it, which seems like asking for trouble in the case that permissions aren't exactly right, etc. |
I'm afraid these solutions will not work (as far as I can tell):
So we don't get the real case. I'll see if we can use the |
Thanks for looking into it. As always: what a mess! This post suggest a two-step process, long -> short -> long, can recover the correct case: http://stackoverflow.com/questions/2113822/python-getting-filename-case-as-stored-in-windows |
…itivity on windows instead of creating a file.
I have to admit that I misinterpreted the results of |
…the file system cas-sensitivity.
# Conflicts: # docs/changelog.rst
What about this one? Do you think it can be merged? |
A robust way to check for a case sensitive file system
This could match intuition a little more closely and also avoids a coupling with the configuration.
This should avoid problems when querying for Unicode paths.
Sorry for being so slow on this! I've finally merged, it with a few tweaks to the code and functionality. Most prominently, I changed the check to work on the path used in the query, rather than the library path, which I think should be slightly more predictable. |
Oops. I didn't take the laziness into account when planning that feature. The latest change seems to have broken something, though:
(Hmm. I replied by email to a different issue and my response ended up here. GitHub bug?) |
Oops! Thanks. The above commit should do it. |
This is a little improvement to find out if the file system is case sensitive or not. Until now, beets uses the operating system to determine this: On Windows, beets detected a case insensitive file system, on all other systems it is detected as case sensitive. At least this might be wrong: MacOS' HFS+ might be case sensitive or not. And what if the library is located on a FAT formated file system under Linux?
(In fact, the wrong detection was the reason I opened #1496.)