diff --git a/mylib/config.py b/mylib/config.py index 498efdd..c154f47 100644 --- a/mylib/config.py +++ b/mylib/config.py @@ -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: