Implemented a much more robust way to check for a case sensitive filesystem

This commit is contained in:
Malte Ried 2015-09-01 10:57:02 +02:00
parent e32744a66a
commit 32bd7914e5
2 changed files with 13 additions and 2 deletions

View file

@ -61,9 +61,8 @@ class PathQuery(dbcore.FieldQuery):
"""
super(PathQuery, self).__init__(field, pattern, fast)
# By default, the case sensitivity depends on the platform.
if case_sensitive is None:
case_sensitive = platform.system() != 'Windows'
case_sensitive = self.is_filesystem_case_sensitive()
self.case_sensitive = case_sensitive
# Use a normalized-case pattern for case-insensitive matches.
@ -75,6 +74,16 @@ class PathQuery(dbcore.FieldQuery):
# As a directory (prefix).
self.dir_path = util.bytestring_path(os.path.join(self.file_path, b''))
@staticmethod
def is_filesystem_case_sensitive():
library_path = beets.config['directory'].get()
if os.path.exists(library_path):
# Check if the path to the library exists in lower and upper case
return not (os.path.exists(library_path.lower()) and
os.path.exists(library_path.upper()))
# By default, the case sensitivity depends on the platform.
return platform.system() != 'Windows'
@classmethod
def is_path_query(cls, query_part):
"""Try to guess whether a unicode query part is a path query.

View file

@ -27,6 +27,8 @@ Fixes:
option.
* The :ref:`list-cmd` command's help output now has a small query and format
string example. Thanks to :user:`pkess`. :bug:`1582`
* The check whether the file system is case sensitive or not could lead to
wrong results. It is much more robust now.
1.3.14 (August 2, 2015)