Fix path handling in hidden module

Probably fixes #2168.
This commit is contained in:
Adrian Sampson 2016-08-13 09:54:25 -04:00
parent 0833c82075
commit 162bf6a594
2 changed files with 8 additions and 9 deletions

View file

@ -20,7 +20,7 @@ import os
import stat
import ctypes
import sys
import six
import beets.util
def _is_hidden_osx(path):
@ -28,7 +28,7 @@ def _is_hidden_osx(path):
This uses os.lstat to work out if a file has the "hidden" flag.
"""
file_stat = os.lstat(path)
file_stat = os.lstat(beets.util.syspath(path))
if hasattr(file_stat, 'st_flags') and hasattr(stat, 'UF_HIDDEN'):
return bool(file_stat.st_flags & stat.UF_HIDDEN)
@ -46,7 +46,7 @@ def _is_hidden_win(path):
hidden_mask = 2
# Retrieve the attributes for the file.
attrs = ctypes.windll.kernel32.GetFileAttributesW(path)
attrs = ctypes.windll.kernel32.GetFileAttributesW(beets.util.syspath(path))
# Ensure we have valid attribues and compare them against the mask.
return attrs >= 0 and attrs & hidden_mask
@ -57,11 +57,12 @@ def _is_hidden_dot(path):
Files starting with a dot are seen as "hidden" files on Unix-based OSes.
"""
return os.path.basename(path).startswith('.')
return os.path.basename(path).startswith(b'.')
def is_hidden(path):
"""Return whether or not a file is hidden.
"""Return whether or not a file is hidden. `path` should be a
bytestring filename.
This method works differently depending on the platform it is called on.
@ -74,10 +75,6 @@ def is_hidden(path):
On any other operating systems (i.e. Linux), it uses `is_hidden_dot` to
work out if a file is hidden.
"""
# Convert the path to unicode if it is not already.
if not isinstance(path, six.text_type):
path = path.decode('utf-8')
# Run platform specific functions depending on the platform
if sys.platform == 'darwin':
return _is_hidden_osx(path) or _is_hidden_dot(path)

View file

@ -46,6 +46,8 @@ And there are a few bug fixes too:
* :doc:`/plugins/play`: Fix ``$args`` getting passed verbatim to the play
command if it was set in the configuration but ``-A`` or ``--args`` was
omitted.
* With :ref:`ignore_hidden` enabled, non-UTF-8 filenames would cause a crash.
This is fixed. :bug:`2168`
The last release, 1.3.19, also erroneously reported its version as "1.3.18"
when you typed ``beet version``. This has been corrected.