From 3e26e70d0c188641efa978d777202064c7200b99 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 10 Nov 2017 21:33:29 -0800 Subject: [PATCH] Fix for incorrect /etc/borgmatic.d/ configuration path probing on macOS. --- NEWS | 4 +++- borgmatic/config/collect.py | 8 +++++--- borgmatic/tests/unit/config/test_collect.py | 13 +++++++++++++ setup.py | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 71086dc..3285b91 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ -1.1.11.dev0 +1.1.11 * #25: Add "ssh_command" to configuration for specifying a custom SSH command or options. + * Fix for incorrect /etc/borgmatic.d/ configuration path probing on macOS. This problem manifested + as an error on startup: "[Errno 2] No such file or directory: '/etc/borgmatic.d'". 1.1.10 * Pass several Unix signals through to child processes like Borg. This means that Borg now properly diff --git a/borgmatic/config/collect.py b/borgmatic/config/collect.py index 4b8b88e..871f69a 100644 --- a/borgmatic/config/collect.py +++ b/borgmatic/config/collect.py @@ -11,13 +11,15 @@ def collect_config_filenames(config_paths): files. 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 /etc/borgmatic.d if it's missing, so the user doesn't have to - create it unless they need it. + configuration paths. However, skip a default config path if it's missing, so the user doesn't + have to create a default config path unless they need it. ''' + real_default_config_paths = set(map(os.path.realpath, DEFAULT_CONFIG_PATHS)) + for path in config_paths: exists = os.path.exists(path) - if os.path.realpath(path) in DEFAULT_CONFIG_PATHS and not exists: + if os.path.realpath(path) in real_default_config_paths and not exists: continue if not os.path.isdir(path) or not exists: diff --git a/borgmatic/tests/unit/config/test_collect.py b/borgmatic/tests/unit/config/test_collect.py index c2572c8..65acbf8 100644 --- a/borgmatic/tests/unit/config/test_collect.py +++ b/borgmatic/tests/unit/config/test_collect.py @@ -58,6 +58,19 @@ def test_collect_config_filenames_skips_etc_borgmatic_dot_d_if_it_does_not_exist assert config_filenames == ('config.yaml',) +def test_collect_config_filenames_skips_non_canonical_etc_borgmatic_dot_d_if_it_does_not_exist(): + config_paths = ('config.yaml', '/etc/../etc/borgmatic.d') + mock_path = flexmock(module.os.path) + mock_path.should_receive('exists').with_args('config.yaml').and_return(True) + mock_path.should_receive('exists').with_args('/etc/../etc/borgmatic.d').and_return(False) + mock_path.should_receive('isdir').with_args('config.yaml').and_return(False) + mock_path.should_receive('isdir').with_args('/etc/../etc/borgmatic.d').and_return(True) + + config_filenames = tuple(module.collect_config_filenames(config_paths)) + + assert config_filenames == ('config.yaml',) + + def test_collect_config_filenames_includes_other_directory_if_it_does_not_exist(): config_paths = ('config.yaml', '/my/directory') mock_path = flexmock(module.os.path) diff --git a/setup.py b/setup.py index 4ab4601..e175f45 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages -VERSION = '1.1.11.dev0' +VERSION = '1.1.11' setup(