Queries with \ are path queries on Windows

This commit is contained in:
Adrian Sampson 2016-05-31 13:29:00 -07:00
parent 1eb03a0de5
commit 5b2fb8dcdc
3 changed files with 16 additions and 2 deletions

View file

@ -85,8 +85,14 @@ class PathQuery(dbcore.FieldQuery):
colon = query_part.find(':')
if colon != -1:
query_part = query_part[:colon]
return (os.sep in query_part and
os.path.exists(syspath(normpath(query_part))))
# Test both `sep` and `altsep` (i.e., both slash and backslash on
# Windows).
return (
(os.sep in query_part or
(os.altsep and os.altsep in query_part)) and
os.path.exists(syspath(normpath(query_part)))
)
def match(self, item):
path = item.path if self.case_sensitive else item.path.lower()

View file

@ -6,6 +6,11 @@ Changelog
Changelog goes here!
Some fixes for Windows:
* Queries are now detected as paths when they contain backslashes (in
addition to forward slashes). This only applies on Windows.
1.3.18 (May 31, 2016)
---------------------

View file

@ -569,7 +569,10 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin):
@patch('beets.library.os')
def test_path_sep_detection(self, mock_os):
mock_os.sep = '/'
mock_os.altsep = None
mock_os.path.exists = lambda p: True
is_path = beets.library.PathQuery.is_path_query
self.assertTrue(is_path('/foo/bar'))
self.assertTrue(is_path('foo/bar'))
self.assertTrue(is_path('foo/'))