From 8424e443a955ceb724ad75cf09ad439ac07335f9 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sun, 19 May 2019 13:04:42 +0200 Subject: [PATCH] Also read .yml ending configuration files Closes https://projects.torsion.org/witten/borgmatic/issues/178. --- borgmatic/config/collect.py | 5 +++-- tests/unit/config/test_collect.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/borgmatic/config/collect.py b/borgmatic/config/collect.py index 71caac3..59d7dfe 100644 --- a/borgmatic/config/collect.py +++ b/borgmatic/config/collect.py @@ -22,7 +22,7 @@ def collect_config_filenames(config_paths): ''' Given a sequence of config paths, both filenames and directories, resolve that to an iterable of files. Accomplish this by listing any given directories looking for contained config files - (ending with the ".yaml" extension). This is non-recursive, so any directories within the given + (ending with the ".yaml" or ".yml" 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 @@ -43,5 +43,6 @@ def collect_config_filenames(config_paths): for filename in sorted(os.listdir(path)): full_filename = os.path.join(path, filename) - if full_filename.endswith('.yaml') and not os.path.isdir(full_filename): + matching_filetype = full_filename.endswith('.yaml') or full_filename.endswith('.yml') + if matching_filetype and not os.path.isdir(full_filename): yield full_filename diff --git a/tests/unit/config/test_collect.py b/tests/unit/config/test_collect.py index 44d181a..2cb5b58 100644 --- a/tests/unit/config/test_collect.py +++ b/tests/unit/config/test_collect.py @@ -30,6 +30,21 @@ def test_collect_config_filenames_collects_given_files(): assert config_filenames == config_paths +def test_collect_config_filenames_collects_yml_file_endings(): + config_paths = ('config.yaml', '/etc/borgmatic.d') + mock_path = flexmock(module.os.path) + mock_path.should_receive('exists').and_return(True) + mock_path.should_receive('isdir').with_args('config.yaml').and_return(False) + mock_path.should_receive('isdir').with_args('/etc/borgmatic.d').and_return(True) + mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yml').and_return(False) + flexmock(module.os).should_receive('listdir') + flexmock(sys.modules['builtins']).should_receive('sorted').and_return(['foo.yml']) + + config_filenames = tuple(module.collect_config_filenames(config_paths)) + + assert config_filenames == ('config.yaml', '/etc/borgmatic.d/foo.yml') + + def test_collect_config_filenames_collects_files_from_given_directories_and_ignores_sub_directories(): config_paths = ('config.yaml', '/etc/borgmatic.d') mock_path = flexmock(module.os.path)