|
12 | 12 | from mediafile import MediaFile, UnreadableFileError |
13 | 13 |
|
14 | 14 | import beets |
15 | | -from beets import context, dbcore, logging, plugins, util |
| 15 | +from beets import dbcore, logging, plugins, util |
16 | 16 | from beets.dbcore import types |
| 17 | +from beets.dbcore.pathutils import normalize_path_for_db |
17 | 18 | from beets.util import ( |
18 | 19 | MoveOperation, |
19 | 20 | bytestring_path, |
@@ -104,19 +105,15 @@ def field_query( |
104 | 105 | if ( |
105 | 106 | cls._type(field).query is dbcore.query.PathQuery |
106 | 107 | and query_cls is not dbcore.query.PathQuery |
107 | | - and (music_dir := context.get_music_dir()) |
108 | 108 | ): |
109 | 109 | # Regex, exact, and string queries operate on the raw DB value, so |
110 | 110 | # strip the library prefix to match the stored relative path. |
111 | 111 | if isinstance(pattern, bytes): |
112 | | - prefix = os.path.join(music_dir, b"") |
113 | | - if pattern.startswith(prefix): |
114 | | - pattern = os.path.relpath(pattern, music_dir) |
| 112 | + pattern = normalize_path_for_db(pattern) |
115 | 113 | else: |
116 | | - music_dir_str = os.fsdecode(music_dir) |
117 | | - prefix = music_dir_str + os.sep |
118 | | - if pattern.startswith(prefix): |
119 | | - pattern = pattern.removeprefix(prefix) |
| 114 | + pattern = os.fsdecode( |
| 115 | + normalize_path_for_db(util.bytestring_path(pattern)) |
| 116 | + ) |
120 | 117 | if field in cls.shared_db_fields: |
121 | 118 | # This field exists in both tables, so SQLite will encounter |
122 | 119 | # an OperationalError if we try to use it in a query. |
|
0 commit comments