mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-27 08:24:35 +00:00
More robust mtime precision checks
This commit is contained in:
parent
2be5867c5f
commit
8e03738f4c
2 changed files with 20 additions and 8 deletions
|
@ -385,7 +385,7 @@ def daemonize():
|
|||
if sys.version < '3.3':
|
||||
# st_mtime_ns attribute only available in 3.3+
|
||||
def st_mtime_ns(st):
|
||||
return int(st.st_mtime * 10**9)
|
||||
return int(st.st_mtime * 1e9)
|
||||
|
||||
# unhexlify in < 3.3 incorrectly only accepts bytes input
|
||||
def unhexlify(data):
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
import filecmp
|
||||
import os
|
||||
import posix
|
||||
import sys
|
||||
import sysconfig
|
||||
import time
|
||||
import unittest
|
||||
from attic.helpers import st_mtime_ns
|
||||
from attic.xattr import get_all
|
||||
|
||||
# The mtime get/set precison varies on different OS and Python versions
|
||||
if 'HAVE_FUTIMENS' in posix._have_functions:
|
||||
st_mtime_ns_round = 0
|
||||
elif 'HAVE_UTIMES' in sysconfig.get_config_vars():
|
||||
st_mtime_ns_round = -3
|
||||
else:
|
||||
st_mtime_ns_round = -9
|
||||
|
||||
|
||||
has_mtime_ns = sys.version >= '3.3'
|
||||
utime_supports_fd = os.utime in getattr(os, 'supports_fd', {})
|
||||
|
@ -41,15 +52,16 @@ def _assert_dirs_equal_cmp(self, diff, fuse=False):
|
|||
if not fuse or not os.path.isdir(path1):
|
||||
# dir nlink is always 1 on our fuse fileystem
|
||||
attrs.append('st_nlink')
|
||||
if not os.path.islink(path1) or utime_supports_fd:
|
||||
# Fuse api is does not support ns precision
|
||||
attrs.append('st_mtime_ns' if has_mtime_ns and not fuse else 'st_mtime')
|
||||
d1 = [filename] + [getattr(s1, a) for a in attrs]
|
||||
d2 = [filename] + [getattr(s2, a) for a in attrs]
|
||||
# 'st_mtime precision is limited'
|
||||
if attrs[-1] == 'st_mtime':
|
||||
d1[-1] = round(d1[-1], 2)
|
||||
d2[-1] = round(d2[-1], 2)
|
||||
if not os.path.islink(path1) or utime_supports_fd:
|
||||
# llfuse does not provide ns precision for now
|
||||
if fuse:
|
||||
d1.append(round(st_mtime_ns(s1), -4))
|
||||
d2.append(round(st_mtime_ns(s2), -4))
|
||||
else:
|
||||
d1.append(round(st_mtime_ns(s1), st_mtime_ns_round))
|
||||
d2.append(round(st_mtime_ns(s2), st_mtime_ns_round))
|
||||
d1.append(self._get_xattrs(path1))
|
||||
d2.append(self._get_xattrs(path2))
|
||||
self.assert_equal(d1, d2)
|
||||
|
|
Loading…
Reference in a new issue