Browse Source

os.utime on py 3.4+ always supports fd and follow_symlinks

Thomas Waldmann 9 years ago
parent
commit
fe8762ad28
2 changed files with 9 additions and 16 deletions
  1. 2 6
      borg/archive.py
  2. 7 10
      borg/testsuite/__init__.py

+ 2 - 6
borg/archive.py

@@ -37,8 +37,6 @@ CHUNKER_PARAMS = (CHUNK_MIN_EXP, CHUNK_MAX_EXP, HASH_MASK_BITS, HASH_WINDOW_SIZE
 # chunker params for the items metadata stream, finer granularity
 # chunker params for the items metadata stream, finer granularity
 ITEMS_CHUNKER_PARAMS = (12, 16, 14, HASH_WINDOW_SIZE)
 ITEMS_CHUNKER_PARAMS = (12, 16, 14, HASH_WINDOW_SIZE)
 
 
-utime_supports_fd = os.utime in getattr(os, 'supports_fd', {})
-utime_supports_follow_symlinks = os.utime in getattr(os, 'supports_follow_symlinks', {})
 has_lchmod = hasattr(os, 'lchmod')
 has_lchmod = hasattr(os, 'lchmod')
 has_lchflags = hasattr(os, 'lchflags')
 has_lchflags = hasattr(os, 'lchflags')
 
 
@@ -385,12 +383,10 @@ Number of files: {0.stats.nfiles}'''.format(self)
         else:
         else:
             # old archives only had mtime in item metadata
             # old archives only had mtime in item metadata
             atime = mtime
             atime = mtime
-        if fd and utime_supports_fd:  # Python >= 3.3
+        if fd:
             os.utime(fd, None, ns=(atime, mtime))
             os.utime(fd, None, ns=(atime, mtime))
-        elif utime_supports_follow_symlinks:  # Python >= 3.3
+        else:
             os.utime(path, None, ns=(atime, mtime), follow_symlinks=False)
             os.utime(path, None, ns=(atime, mtime), follow_symlinks=False)
-        elif not symlink:
-            os.utime(path, (atime / 1e9, mtime / 1e9))
         acl_set(path, item, self.numeric_owner)
         acl_set(path, item, self.numeric_owner)
         # Only available on OS X and FreeBSD
         # Only available on OS X and FreeBSD
         if has_lchflags and b'bsdflags' in item:
         if has_lchflags and b'bsdflags' in item:

+ 7 - 10
borg/testsuite/__init__.py

@@ -30,8 +30,6 @@ else:
 if sys.platform.startswith('netbsd'):
 if sys.platform.startswith('netbsd'):
     st_mtime_ns_round = -4  # only >1 microsecond resolution here?
     st_mtime_ns_round = -4  # only >1 microsecond resolution here?
 
 
-utime_supports_fd = os.utime in getattr(os, 'supports_fd', {})
-
 
 
 class BaseTestCase(unittest.TestCase):
 class BaseTestCase(unittest.TestCase):
     """
     """
@@ -78,14 +76,13 @@ class BaseTestCase(unittest.TestCase):
                 d1[4] = None
                 d1[4] = None
             if not stat.S_ISCHR(d2[1]) and not stat.S_ISBLK(d2[1]):
             if not stat.S_ISCHR(d2[1]) and not stat.S_ISBLK(d2[1]):
                 d2[4] = None
                 d2[4] = None
-            if not os.path.islink(path1) or utime_supports_fd:
-                # Older versions of llfuse do not support ns precision properly
-                if fuse and not have_fuse_mtime_ns:
-                    d1.append(round(s1.st_mtime_ns, -4))
-                    d2.append(round(s2.st_mtime_ns, -4))
-                else:
-                    d1.append(round(s1.st_mtime_ns, st_mtime_ns_round))
-                    d2.append(round(s2.st_mtime_ns, st_mtime_ns_round))
+            # Older versions of llfuse do not support ns precision properly
+            if fuse and not have_fuse_mtime_ns:
+                d1.append(round(s1.st_mtime_ns, -4))
+                d2.append(round(s2.st_mtime_ns, -4))
+            else:
+                d1.append(round(s1.st_mtime_ns, st_mtime_ns_round))
+                d2.append(round(s2.st_mtime_ns, st_mtime_ns_round))
             d1.append(get_all(path1, follow_symlinks=False))
             d1.append(get_all(path1, follow_symlinks=False))
             d2.append(get_all(path2, follow_symlinks=False))
             d2.append(get_all(path2, follow_symlinks=False))
             self.assert_equal(d1, d2)
             self.assert_equal(d1, d2)