Check that config is readable

Implement a check on file permissions for the config files that are loaded
and print debug if mopidy fails to load it due to missing file file permissions
This commit is contained in:
Lasse Bigum 2015-02-07 16:24:51 +01:00
parent a693993905
commit 4bf7a568d1
2 changed files with 17 additions and 0 deletions

View File

@ -148,6 +148,11 @@ def _load_file(parser, filename):
logger.debug(
'Loading config from %s failed; it does not exist', filename)
return
if not os.access(filename, os.R_OK):
logger.warning(
'Loading config from %s failed; read permission missing',
filename)
return
try:
logger.info('Loading config from %s', filename)

View File

@ -15,6 +15,18 @@ class LoadConfigTest(unittest.TestCase):
def test_load_nothing(self):
self.assertEqual({}, config._load([], [], []))
def test_load_missing_file(self):
file0 = path_to_data_dir('file0.conf')
result = config._load([file0], [], [])
self.assertEqual({}, result)
@mock.patch('os.access')
def test_load_nonreadable_file(self, access_mock):
access_mock.return_value = False
file1 = path_to_data_dir('file1.conf')
result = config._load([file1], [], [])
self.assertEqual({}, result)
def test_load_single_default(self):
default = b'[foo]\nbar = baz'
expected = {'foo': {'bar': 'baz'}}