diff --git a/NEWS b/NEWS index d9bbb4a8b..38e3b1511 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.7.4.dev0 + * #596: Fix special file detection when broken symlinks are encountered. + 1.7.3 * #357: Add "break-lock" action for removing any repository and cache locks leftover from Borg aborting. diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 13f794264..efe092fba 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -229,7 +229,11 @@ def special_file(path): Return whether the given path is a special file (character device, block device, or named pipe / FIFO). ''' - mode = os.stat(path).st_mode + try: + mode = os.stat(path).st_mode + except (FileNotFoundError, OSError): + return False + return stat.S_ISCHR(mode) or stat.S_ISBLK(mode) or stat.S_ISFIFO(mode) diff --git a/setup.py b/setup.py index c45c2ad03..4f496245e 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.7.3' +VERSION = '1.7.4.dev0' setup( diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index c12011399..4dd390bb1 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -338,6 +338,12 @@ def test_special_file_looks_at_file_type(character_device, block_device, fifo, e assert module.special_file('/dev/special') == expected_result +def test_special_file_treats_broken_symlink_as_non_special(): + flexmock(module.os).should_receive('stat').and_raise(FileNotFoundError) + + assert module.special_file('/broken/symlink') is False + + def test_any_parent_directories_treats_parents_as_match(): module.any_parent_directories('/foo/bar.txt', ('/foo', '/etc'))