diff --git a/NEWS b/NEWS index 7b07fe5f4..6ee552cc5 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ 1.2.1.dev0 * Skip before/after backup hooks when only doing --prune, --check, --list, and/or --info. * #38, #76: Upgrade ruamel.yaml compatibility version range and fix support for Python 3.7. + * #77: Skip non-"*.yaml" config filenames in /etc/borgmatic.d/ so as not to parse backup files, + editor swap files, etc. 1.2.0 * #61: Support for Borg --list option via borgmatic command-line to list all archives. diff --git a/borgmatic/config/collect.py b/borgmatic/config/collect.py index 02ccc9dc5..47f0ef46e 100644 --- a/borgmatic/config/collect.py +++ b/borgmatic/config/collect.py @@ -12,7 +12,8 @@ def collect_config_filenames(config_paths): ''' Given a sequence of config paths, both filenames and directories, resolve that to just an iterable of files. Accomplish this by listing any given directories looking for contained config - files. This is non-recursive, so any directories within the given directories are ignored. + files (ending with the ".yaml" extension). This is non-recursive, so any directories within the + given directories are ignored. Return paths even if they don't exist on disk, so the user can find out about missing configuration paths. However, skip a default config path if it's missing, so the user doesn't @@ -32,5 +33,5 @@ def collect_config_filenames(config_paths): for filename in os.listdir(path): full_filename = os.path.join(path, filename) - if not os.path.isdir(full_filename): + if full_filename.endswith('.yaml') and not os.path.isdir(full_filename): yield full_filename diff --git a/borgmatic/config/validate.py b/borgmatic/config/validate.py index 795a07dd6..bdbbbf782 100644 --- a/borgmatic/config/validate.py +++ b/borgmatic/config/validate.py @@ -10,6 +10,7 @@ from ruamel import yaml logger = logging.getLogger(__name__) + def schema_filename(): ''' Path to the installed YAML configuration schema file, used to validate and parse the diff --git a/borgmatic/tests/unit/config/test_collect.py b/borgmatic/tests/unit/config/test_collect.py index 65acbf8ee..d573ae018 100644 --- a/borgmatic/tests/unit/config/test_collect.py +++ b/borgmatic/tests/unit/config/test_collect.py @@ -32,6 +32,21 @@ def test_collect_config_filenames_collects_files_from_given_directories_and_igno ) +def test_collect_config_filenames_collects_files_from_given_directories_and_ignores_non_yaml_filenames(): + config_paths = ('/etc/borgmatic.d',) + mock_path = flexmock(module.os.path) + mock_path.should_receive('exists').and_return(True) + mock_path.should_receive('isdir').with_args('/etc/borgmatic.d').and_return(True) + mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False) + mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar.yaml~').and_return(False) + mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.txt').and_return(False) + flexmock(module.os).should_receive('listdir').and_return(['foo.yaml', 'bar.yaml~', 'baz.txt']) + + config_filenames = tuple(module.collect_config_filenames(config_paths)) + + assert config_filenames == ('/etc/borgmatic.d/foo.yaml',) + + def test_collect_config_filenames_skips_etc_borgmatic_config_dot_yaml_if_it_does_not_exist(): config_paths = ('config.yaml', '/etc/borgmatic/config.yaml') mock_path = flexmock(module.os.path)