Disallow to modify a template if changes cannot be written on disk. Fixes #1695

This commit is contained in:
grossmj committed 2020-01-08 05:35:46 +08:00
1 parent a47fa83cec
commit 98f5454ccb
3 files changed
+22 -3

No files matched your search

+14
View File
@@ -132,6 +132,20 @@ class Controller:
self._computes = {}
self._projects = {}
def check_can_write_config(self):
"""
Check if the controller configuration can be written on disk
:returns: boolean
"""
try:
os.makedirs(os.path.dirname(self._config_file), exist_ok=True)
if not os.access(self._config_file, os.W_OK):
raise aiohttp.web.HTTPConflict(text="Change rejected, cannot write to controller configuration file '{}'".format(self._config_file))
except OSError as e:
raise aiohttp.web.HTTPConflict(text="Change rejected: {}".format(e))
def save(self):
"""
Save the controller configuration on disk