瀏覽代碼

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

Dan Helfman 2 年之前
父節點
當前提交
953277a066
共有 4 個文件被更改,包括 15 次插入2 次删除
  1. 3 0
      NEWS
  2. 5 1
      borgmatic/borg/create.py
  3. 1 1
      setup.py
  4. 6 0
      tests/unit/borg/test_create.py

+ 3 - 0
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.

+ 5 - 1
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)
 
 

+ 1 - 1
setup.py

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

+ 6 - 0
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'))