config: fix save method when file exists and is writeable but not the directory
This commit is contained in:
parent
5a30541917
commit
c851e7aca7
1 changed files with 6 additions and 6 deletions
|
@ -671,17 +671,17 @@ class Config: # pylint: disable=too-many-instance-attributes
|
|||
filepath = filepath if filepath else self._filepath
|
||||
assert filepath, 'Configuration filepath is not set or provided'
|
||||
|
||||
# Checking access of target directory
|
||||
# Checking access of target file/directory
|
||||
dirpath = os.path.dirname(filepath)
|
||||
if not os.path.isdir(dirpath) or not os.access(dirpath, os.R_OK | os.W_OK | os.X_OK):
|
||||
if os.path.isfile(filepath):
|
||||
if not os.access(filepath, os.W_OK):
|
||||
log.error('Configuration file "%s" is not writable', filepath)
|
||||
return False
|
||||
elif not os.path.isdir(dirpath) or not os.access(dirpath, os.R_OK | os.W_OK | os.X_OK):
|
||||
log.error(
|
||||
'Configuration directory "%s" does not exist (or not writable)', dirpath)
|
||||
return False
|
||||
|
||||
if os.path.isfile(filepath) and not os.access(filepath, os.W_OK):
|
||||
log.error('Configuration file "%s" is not writable', filepath)
|
||||
return False
|
||||
|
||||
lines = ['#\n# %s configuration\n#\n' % self.appname]
|
||||
|
||||
for section_name in self._ordered_section_names:
|
||||
|
|
Loading…
Reference in a new issue