parent
2a8375a947
commit
9bf8ac2099
@ -4,6 +4,14 @@ Changelog
|
|||||||
|
|
||||||
This changelog is used to track all major changes to Mopidy.
|
This changelog is used to track all major changes to Mopidy.
|
||||||
|
|
||||||
|
v2.2.2 (UNRELEASED)
|
||||||
|
===================
|
||||||
|
|
||||||
|
Bug fix release.
|
||||||
|
|
||||||
|
- Files: Fix crash due to mix of text and bytes in paths that come from
|
||||||
|
``$XDG_CONFIG_HOME/user-dirs.dirs``. (Fixes: :issue:`1676`, :issue:`1725`)
|
||||||
|
|
||||||
|
|
||||||
v2.2.1 (2018-10-15)
|
v2.2.1 (2018-10-15)
|
||||||
===================
|
===================
|
||||||
|
|||||||
@ -53,15 +53,16 @@ def _get_user_dirs(xdg_config_dir):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
with open(dirs_file, 'rb') as fh:
|
with open(dirs_file, 'rb') as fh:
|
||||||
data = fh.read().decode('utf-8')
|
data = fh.read()
|
||||||
|
|
||||||
data = '[XDG_USER_DIRS]\n' + data
|
data = b'[XDG_USER_DIRS]\n' + data
|
||||||
data = data.replace('$HOME', os.path.expanduser('~'))
|
data = data.replace(b'$HOME', os.path.expanduser(b'~'))
|
||||||
data = data.replace('"', '')
|
data = data.replace(b'"', b'')
|
||||||
|
|
||||||
config = configparser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
config.readfp(io.StringIO(data))
|
config.readfp(io.BytesIO(data))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
k.upper(): os.path.abspath(v)
|
k.upper().decode('utf-8'): os.path.abspath(v)
|
||||||
for k, v in config.items('XDG_USER_DIRS') if v is not None}
|
for k, v in config.items('XDG_USER_DIRS') if v is not None
|
||||||
|
}
|
||||||
|
|||||||
@ -21,9 +21,10 @@ def test_cache_dir_default(environ):
|
|||||||
|
|
||||||
|
|
||||||
def test_cache_dir_from_env(environ):
|
def test_cache_dir_from_env(environ):
|
||||||
os.environ['XDG_CACHE_HOME'] = '/foo/bar'
|
os.environ['XDG_CACHE_HOME'] = b'/foo/bar'
|
||||||
|
|
||||||
assert xdg.get_dirs()['XDG_CACHE_DIR'] == '/foo/bar'
|
assert xdg.get_dirs()['XDG_CACHE_DIR'] == b'/foo/bar'
|
||||||
|
assert type(xdg.get_dirs()['XDG_CACHE_DIR']) == bytes
|
||||||
|
|
||||||
|
|
||||||
def test_config_dir_default(environ):
|
def test_config_dir_default(environ):
|
||||||
@ -31,9 +32,10 @@ def test_config_dir_default(environ):
|
|||||||
|
|
||||||
|
|
||||||
def test_config_dir_from_env(environ):
|
def test_config_dir_from_env(environ):
|
||||||
os.environ['XDG_CONFIG_HOME'] = '/foo/bar'
|
os.environ['XDG_CONFIG_HOME'] = b'/foo/bar'
|
||||||
|
|
||||||
assert xdg.get_dirs()['XDG_CONFIG_DIR'] == '/foo/bar'
|
assert xdg.get_dirs()['XDG_CONFIG_DIR'] == b'/foo/bar'
|
||||||
|
assert type(xdg.get_dirs()['XDG_CONFIG_DIR']) == bytes
|
||||||
|
|
||||||
|
|
||||||
def test_data_dir_default(environ):
|
def test_data_dir_default(environ):
|
||||||
@ -42,21 +44,23 @@ def test_data_dir_default(environ):
|
|||||||
|
|
||||||
|
|
||||||
def test_data_dir_from_env(environ):
|
def test_data_dir_from_env(environ):
|
||||||
os.environ['XDG_DATA_HOME'] = '/foo/bar'
|
os.environ['XDG_DATA_HOME'] = b'/foo/bar'
|
||||||
|
|
||||||
assert xdg.get_dirs()['XDG_DATA_DIR'] == '/foo/bar'
|
assert xdg.get_dirs()['XDG_DATA_DIR'] == b'/foo/bar'
|
||||||
|
assert type(xdg.get_dirs()['XDG_DATA_DIR']) == bytes
|
||||||
|
|
||||||
|
|
||||||
def test_user_dirs(environ, tmpdir):
|
def test_user_dirs(environ, tmpdir):
|
||||||
os.environ['XDG_CONFIG_HOME'] = str(tmpdir)
|
os.environ['XDG_CONFIG_HOME'] = str(tmpdir)
|
||||||
|
|
||||||
with open(os.path.join(str(tmpdir), 'user-dirs.dirs'), 'wb') as fh:
|
with open(os.path.join(str(tmpdir), 'user-dirs.dirs'), 'wb') as fh:
|
||||||
fh.write('# Some comments\n')
|
fh.write(b'# Some comments\n')
|
||||||
fh.write('XDG_MUSIC_DIR="$HOME/Music2"\n')
|
fh.write(b'XDG_MUSIC_DIR="$HOME/Music2"\n')
|
||||||
|
|
||||||
result = xdg.get_dirs()
|
result = xdg.get_dirs()
|
||||||
|
|
||||||
assert result['XDG_MUSIC_DIR'] == os.path.expanduser(b'~/Music2')
|
assert result['XDG_MUSIC_DIR'] == os.path.expanduser(b'~/Music2')
|
||||||
|
assert type(result['XDG_MUSIC_DIR']) == bytes
|
||||||
assert 'XDG_DOWNLOAD_DIR' not in result
|
assert 'XDG_DOWNLOAD_DIR' not in result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user