Fix special file detection when broken symlinks are encountered (#596).

This commit is contained in:
Dan Helfman 2022-10-14 09:41:08 -07:00
parent e2002b5488
commit 953277a066
4 changed files with 15 additions and 2 deletions

3
NEWS
View File

@ -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.

View File

@ -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)

View File

@ -1,6 +1,6 @@
from setuptools import find_packages, setup
VERSION = '1.7.3'
VERSION = '1.7.4.dev0'
setup(

View File

@ -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'))