Kaynağa Gözat

Merge pull request #6537 from bket/1.1_fix_#2055

1.1 - Fix OpenBSD symlink mode test failure (#2055)
TW 3 yıl önce
ebeveyn
işleme
caba5bfa53
1 değiştirilmiş dosya ile 12 ekleme ve 5 silme
  1. 12 5
      src/borg/archive.py

+ 12 - 5
src/borg/archive.py

@@ -44,7 +44,6 @@ from .platform import acl_get, acl_set, set_flags, get_flags, swidth, hostname
 from .remote import cache_if_remote
 from .repository import Repository, LIST_SCAN_LIMIT
 
-has_lchmod = hasattr(os, 'lchmod')
 has_link = hasattr(os, 'link')
 
 flags_normal = os.O_RDONLY | getattr(os, 'O_BINARY', 0)
@@ -738,10 +737,18 @@ Utilization of max. archive size: {csize_max:.0%}
             pass
         if fd:
             os.fchmod(fd, item.mode)
-        elif not symlink:
-            os.chmod(path, item.mode)
-        elif has_lchmod:  # Not available on Linux
-            os.lchmod(path, item.mode)
+        else:
+            # To check whether a particular function in the os module accepts False for its
+            # follow_symlinks parameter, the in operator on supports_follow_symlinks should be
+            # used. However, os.chmod is special as some platforms without a working lchmod() do
+            # have fchmodat(), which has a flag that makes it behave like lchmod(). fchmodat()
+            # is ignored when deciding whether or not os.chmod should be set in
+            # os.supports_follow_symlinks. Work around this by using try/except.
+            try:
+                os.chmod(path, item.mode, follow_symlinks=False)
+            except (NotImplementedError, SystemError):
+                if not symlink:
+                    os.chmod(path, item.mode)
         mtime = item.mtime
         if 'atime' in item:
             atime = item.atime