Skip to content

Commit

Permalink
Load the autoconf file only if it exists
Browse files Browse the repository at this point in the history
Added a guarding statement that loads the barman.auto.conf file only if
the file exists.
Improved warning messages in the load_config_file method, adding a
specific one in the case the file is not found.

Signed-off-by: Giulio Calacoci <giulio.calacoci@enterprisedb.com>
  • Loading branch information
gcalacoci committed Mar 14, 2024
1 parent 26ed480 commit 3b7b1d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
7 changes: 4 additions & 3 deletions barman/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1994,9 +1994,10 @@ def global_config(args):

# Load additional configuration files
config.load_configuration_files_directory()
config.load_config_file(
"%s/.barman.auto.conf" % config.get("barman", "barman_home")
)
# Handle the autoconf file, load it only if exists
autoconf_path = "%s/.barman.auto.conf" % config.get("barman", "barman_home")
if os.path.exists(autoconf_path):
config.load_config_file(autoconf_path)
# We must validate the configuration here in order to have
# both output and logging configured
config.validate_global_config()
Expand Down
30 changes: 17 additions & 13 deletions barman/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,20 +1336,24 @@ def load_configuration_files_directory(self):

def load_config_file(self, cfile):
filename = os.path.basename(cfile)
if os.path.isfile(cfile):
# Load a file
_logger.debug("Including configuration file: %s", filename)
self._config.read_config(cfile)
if self._is_global_config_changed():
msg = (
"the configuration file %s contains a not empty [barman] section"
% filename
)
_logger.fatal(msg)
raise SystemExit("FATAL: %s" % msg)
if os.path.exists(cfile):
if os.path.isfile(cfile):
# Load a file
_logger.debug("Including configuration file: %s", filename)
self._config.read_config(cfile)
if self._is_global_config_changed():
msg = (
"the configuration file %s contains a not empty [barman] section"
% filename
)
_logger.fatal(msg)
raise SystemExit("FATAL: %s" % msg)
else:
# Add an warning message that a file has been discarded
_logger.warn("Discarding configuration file: %s (not a file)", filename)
else:
# Add an info that a file has been discarded
_logger.warn("Discarding configuration file: %s (not a file)", filename)
# Add an warning message that a file has been discarded
_logger.warn("Discarding configuration file: %s (not found)", filename)

def _is_model(self, name):
"""
Expand Down

0 comments on commit 3b7b1d2

Please sign in to comment.