mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-16 16:02:33 +03:00
do not crash when config.yml is 0 bytes or empty of data
This commit is contained in:
parent
5267699d81
commit
40c77892a2
2 changed files with 13 additions and 0 deletions
|
@ -362,6 +362,8 @@ def read_config(opts=None):
|
||||||
logging.debug(_("Reading '{config_file}'").format(config_file=config_file))
|
logging.debug(_("Reading '{config_file}'").format(config_file=config_file))
|
||||||
with open(config_file, encoding='utf-8') as fp:
|
with open(config_file, encoding='utf-8') as fp:
|
||||||
config = yaml.safe_load(fp)
|
config = yaml.safe_load(fp)
|
||||||
|
if not config:
|
||||||
|
config = {}
|
||||||
elif os.path.exists(old_config_file):
|
elif os.path.exists(old_config_file):
|
||||||
logging.warning(_("""{oldfile} is deprecated, use {newfile}""")
|
logging.warning(_("""{oldfile} is deprecated, use {newfile}""")
|
||||||
.format(oldfile=old_config_file, newfile=config_file))
|
.format(oldfile=old_config_file, newfile=config_file))
|
||||||
|
|
|
@ -1675,6 +1675,17 @@ class CommonTest(unittest.TestCase):
|
||||||
self.assertIsNone(config.get('stats_server'))
|
self.assertIsNone(config.get('stats_server'))
|
||||||
self.assertIsNotNone(config.get('char_limits'))
|
self.assertIsNotNone(config.get('char_limits'))
|
||||||
|
|
||||||
|
def test_with_zero_size_config(self):
|
||||||
|
"""It should set defaults if config file has nothing in it"""
|
||||||
|
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
|
||||||
|
os.chdir(testdir)
|
||||||
|
open('config.yml', 'w').close()
|
||||||
|
self.assertTrue(os.path.exists('config.yml'))
|
||||||
|
self.assertFalse(os.path.exists('config.py'))
|
||||||
|
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||||
|
self.assertIsNone(config.get('stats_server'))
|
||||||
|
self.assertIsNotNone(config.get('char_limits'))
|
||||||
|
|
||||||
def test_with_config_yml(self):
|
def test_with_config_yml(self):
|
||||||
"""Make sure it is possible to use config.yml alone."""
|
"""Make sure it is possible to use config.yml alone."""
|
||||||
testdir = tempfile.mkdtemp(
|
testdir = tempfile.mkdtemp(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue