diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index aa9e6059..84e7d80f 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -137,8 +137,10 @@ def validate_planned_backup_paths( # Return the subset of output paths that are special files but *not* contained within the # borgmatic runtime directory. The intent is to skip runtime paths that borgmatic uses for its # own bookkeeping, instead focusing on user-configured paths. - if not any_parent_directories(path, (borgmatic_runtime_directory,)) and special_file( - path, working_directory + if ( + find_special_files + and not any_parent_directories(path, (borgmatic_runtime_directory,)) + and special_file(path, working_directory) ): special_paths.append(path) @@ -273,7 +275,6 @@ def make_base_create_command( # noqa: PLR0912 logger.debug('Checking file paths Borg plans to include') - find_special_files = bool(stream_processes) special_file_paths = validate_planned_backup_paths( dry_run, create_flags + create_positional_arguments, @@ -282,10 +283,10 @@ def make_base_create_command( # noqa: PLR0912 local_path, working_directory, borgmatic_runtime_directory=borgmatic_runtime_directory, - find_special_files=find_special_files, + find_special_files=bool(stream_processes), ) - if find_special_files and config.get('read_special') is False: + if stream_processes and config.get('read_special') is False: logger.warning( 'Ignoring configured "read_special" value of false, as true is needed for database hooks.', ) diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index 377a84bd..a2d14b3a 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -1835,7 +1835,7 @@ def test_create_archive_calls_borg_with_working_directory(): ) -def test_validate_planned_backup_paths_finds_special_files(): +def test_validate_planned_backup_paths_returns_special_files(): flexmock(module.flags).should_receive('omit_flag').replace_with( lambda arguments, flag: arguments, ) @@ -1872,4 +1872,46 @@ def test_validate_planned_backup_paths_finds_special_files(): local_path=None, working_directory=None, borgmatic_runtime_directory='/run/borgmatic', + find_special_files=True, ) == ('/dev/foo', '/dev/baz') + + +def test_validate_planned_backup_paths_without_find_special_files_ignores_special_files(): + flexmock(module.flags).should_receive('omit_flag').replace_with( + lambda arguments, flag: arguments, + ) + flexmock(module.flags).should_receive('omit_flag_and_value').replace_with( + lambda arguments, flag: arguments, + ) + flexmock(module.environment).should_receive('make_environment').and_return(None) + flexmock(module).should_receive('execute_command_and_capture_output').and_yield( + '+ /dev/foo', + '- /run/borgmatic/bar', + '- /dev/baz', + '- /quux', + ) + flexmock(module.os.path).should_receive('exists').and_return(True) + flexmock(module).should_receive('any_parent_directories').replace_with( + lambda path, candidates: any(path.startswith(parent) for parent in candidates) + ) + flexmock(module).should_receive('special_file').never() + + assert ( + module.validate_planned_backup_paths( + dry_run=False, + create_command=('borg', 'create'), + config={}, + patterns=( + module.borgmatic.borg.pattern.Pattern('/dev/foo'), + module.borgmatic.borg.pattern.Pattern( + '/run/borgmatic/bar', module.borgmatic.borg.pattern.Pattern_type.ROOT + ), + module.borgmatic.borg.pattern.Pattern('/dev/baz'), + ), + local_path=None, + working_directory=None, + borgmatic_runtime_directory='/run/borgmatic', + find_special_files=False, + ) + == () + )