From 7c048d198900dc8e1da4139fd7b92a2386e3dbb8 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 27 Aug 2017 10:01:49 -0700 Subject: [PATCH] Fix for traceback when "exclude_from" value is empty in configuration file. --- NEWS | 1 + borgmatic/borg/create.py | 2 +- borgmatic/tests/unit/borg/test_create.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 2df29ec..2e5abe7 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ 1.1.7.dev0 + * Fix for traceback when "exclude_from" value is empty in configuration file. * When pruning, make highest verbosity level list archives kept and pruned. * Clarification of Python 3 pip usage in documentation. diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 2696e75..5073cc5 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -36,7 +36,7 @@ def _make_exclude_flags(location_config, exclude_patterns_filename=None): Given a location config dict with various exclude options, and a filename containing any exclude patterns, return the corresponding Borg flags as a tuple. ''' - exclude_filenames = tuple(location_config.get('exclude_from', ())) + ( + exclude_filenames = tuple(location_config.get('exclude_from') or ()) + ( (exclude_patterns_filename,) if exclude_patterns_filename else () ) exclude_from_flags = tuple( diff --git a/borgmatic/tests/unit/borg/test_create.py b/borgmatic/tests/unit/borg/test_create.py index 6d2aa45..6f9b5a3 100644 --- a/borgmatic/tests/unit/borg/test_create.py +++ b/borgmatic/tests/unit/borg/test_create.py @@ -88,6 +88,16 @@ def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_excl assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes') +def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty(): + flexmock(module).should_receive('_write_exclude_file').and_return(None) + + exclude_flags = module._make_exclude_flags( + location_config={'exclude_from': None}, + ) + + assert exclude_flags == () + + def test_make_exclude_flags_includes_exclude_caches_when_true_in_config(): exclude_flags = module._make_exclude_flags( location_config={'exclude_caches': True},