From a14870ce4899a8aa38a2f38832bffe74b8490b78 Mon Sep 17 00:00:00 2001 From: Jesse Johnson Date: Wed, 19 Apr 2023 18:47:22 -0700 Subject: [PATCH] Expand source directories when checking for existence (#682). --- borgmatic/borg/create.py | 2 +- tests/unit/borg/test_create.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 8782dc6..7413dfc 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -314,7 +314,7 @@ def check_all_source_directories_exist(source_directories): missing_directories = [ source_directory for source_directory in source_directories - if not os.path.exists(source_directory) + if not all([os.path.exists(directory) for directory in expand_directory(source_directory)]) ] if missing_directories: raise ValueError(f"Source directories do not exist: {', '.join(missing_directories)}") diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index d2ab397..5011f48 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -2565,3 +2565,18 @@ def test_create_archive_with_non_existent_directory_and_source_directories_must_ storage_config={}, local_borg_version='1.2.3', ) + + +def test_check_all_source_directories_exist_with_glob_and_tilde_directories(): + flexmock(module).should_receive('expand_directory').with_args('foo*').and_return( + ('foo', 'food') + ) + flexmock(module).should_receive('expand_directory').with_args('~/bar').and_return( + ('/root/bar',) + ) + flexmock(module.os.path).should_receive('exists').and_return(False) + flexmock(module.os.path).should_receive('exists').with_args('foo').and_return(True) + flexmock(module.os.path).should_receive('exists').with_args('food').and_return(True) + flexmock(module.os.path).should_receive('exists').with_args('/root/bar').and_return(True) + + module.check_all_source_directories_exist(['foo*', '~/bar'])