From 427bfe8cbf0b7d06bbc6051b256898b69acebdb4 Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Sat, 24 Dec 2022 18:20:14 +0100 Subject: [PATCH] library/PathQuery: fix lower-casing --- beets/library.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/beets/library.py b/beets/library.py index c3b11113c..be6d9817a 100644 --- a/beets/library.py +++ b/beets/library.py @@ -64,21 +64,27 @@ class PathQuery(dbcore.FieldQuery): """ super().__init__(field, pattern, fast) + path = util.normpath(pattern) + # By default, the case sensitivity depends on the filesystem # that the query path is located on. if case_sensitive is None: - path = util.normpath(pattern) - case_sensitive = beets.util.case_sensitive(path) + case_sensitive = util.case_sensitive(path) self.case_sensitive = case_sensitive # Use a normalized-case pattern for case-insensitive matches. if not case_sensitive: - pattern = pattern.lower() + # We need to lowercase the entire path, not just the pattern. + # In particular, on Windows, the drive letter is otherwise not + # lowercased. + # This also ensures that the `match()` method below and the SQL + # from `col_clause()` do the same thing. + path = path.lower() # Match the path as a single file. - self.file_path = util.normpath(pattern) + self.file_path = path # As a directory (prefix). - self.dir_path = os.path.join(self.file_path, b'') + self.dir_path = os.path.join(path, b'') @classmethod def is_path_query(cls, query_part):