From 08d6f83b2e3388d1ff342e64fe23668987f95202 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 9 Jun 2024 15:58:16 -0700 Subject: [PATCH] In the "spot" check, don't try to hash symlinked directories. --- NEWS | 1 + borgmatic/actions/check.py | 5 ++--- tests/unit/actions/test_check.py | 23 ++++++++++++----------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index 9cc13fd..24a50bb 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ the log level. * #874: Add the configured repository label as "repository_label" to the interpolated variables passed to before/after command hooks. + * In the "spot" check, don't try to hash symlinked directories. 1.8.11 * #815: Add optional Healthchecks auto-provisioning via "create_slug" option. diff --git a/borgmatic/actions/check.py b/borgmatic/actions/check.py index 6a96f2d..d27dced 100644 --- a/borgmatic/actions/check.py +++ b/borgmatic/actions/check.py @@ -300,8 +300,7 @@ def collect_spot_check_source_paths( ''' Given a repository configuration dict, a configuration dict, the local Borg version, global arguments as an argparse.Namespace instance, the local Borg path, and the remote Borg path, - collect the source paths that Borg would use in an actual create (but only include files and - symlinks). + collect the source paths that Borg would use in an actual create (but only include files). ''' stream_processes = any( borgmatic.hooks.dispatch.call_hooks( @@ -349,7 +348,7 @@ def collect_spot_check_source_paths( if path_line and path_line.startswith('- ') or path_line.startswith('+ ') ) - return tuple(path for path in paths if os.path.isfile(path) or os.path.islink(path)) + return tuple(path for path in paths if os.path.isfile(path)) BORG_DIRECTORY_FILE_TYPE = 'd' diff --git a/tests/unit/actions/test_check.py b/tests/unit/actions/test_check.py index 859d2b2..e00b6ef 100644 --- a/tests/unit/actions/test_check.py +++ b/tests/unit/actions/test_check.py @@ -520,7 +520,7 @@ def test_collect_spot_check_source_paths_without_working_directory_parses_borg_o ) == ('/etc/path', '/etc/other') -def test_collect_spot_check_source_paths_includes_symlinks_but_skips_directories(): +def test_collect_spot_check_source_paths_skips_directories(): flexmock(module.borgmatic.hooks.dispatch).should_receive('call_hooks').and_return( {'hook1': False, 'hook2': True} ) @@ -546,18 +546,19 @@ def test_collect_spot_check_source_paths_includes_symlinks_but_skips_directories 'warning: stuff\n- /etc/path\n+ /etc/dir\n? /nope', ) flexmock(module.os.path).should_receive('isfile').with_args('/etc/path').and_return(False) - flexmock(module.os.path).should_receive('islink').with_args('/etc/path').and_return(True) flexmock(module.os.path).should_receive('isfile').with_args('/etc/dir').and_return(False) - flexmock(module.os.path).should_receive('islink').with_args('/etc/dir').and_return(False) - assert module.collect_spot_check_source_paths( - repository={'path': 'repo'}, - config={'working_directory': '/'}, - local_borg_version=flexmock(), - global_arguments=flexmock(), - local_path=flexmock(), - remote_path=flexmock(), - ) == ('/etc/path',) + assert ( + module.collect_spot_check_source_paths( + repository={'path': 'repo'}, + config={'working_directory': '/'}, + local_borg_version=flexmock(), + global_arguments=flexmock(), + local_path=flexmock(), + remote_path=flexmock(), + ) + == () + ) def test_collect_spot_check_archive_paths_excludes_directories():