1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-25 23:43:49 +00:00

same_ts_ns: add a timestamp comparison function

also: HAVE_UTIMES means 1us resolution (*)

(*) at least as far as the utimes() call is concerned.

Whether there are other limitations has to be seen.
This commit is contained in:
Thomas Waldmann 2023-02-10 17:58:46 +01:00
parent b233dbb4db
commit 2ef09eaa77
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -42,14 +42,21 @@
# The mtime get/set precision varies on different OS and Python versions # The mtime get/set precision varies on different OS and Python versions
if posix and "HAVE_FUTIMENS" in getattr(posix, "_have_functions", []): if posix and "HAVE_FUTIMENS" in getattr(posix, "_have_functions", []):
st_mtime_ns_round = 0 st_mtime_ns_round = 0 # 1ns resolution
elif "HAVE_UTIMES" in sysconfig.get_config_vars(): elif "HAVE_UTIMES" in sysconfig.get_config_vars():
st_mtime_ns_round = -6 st_mtime_ns_round = -3 # 1us resolution
else: else:
st_mtime_ns_round = -9 st_mtime_ns_round = -9 # 1s resolution
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 # 10us - strange: only >1 microsecond resolution here?
def same_ts_ns(ts_ns1, ts_ns2):
"""compare 2 timestamps (both in nanoseconds) whether they are (roughly) equal"""
diff_ts = int(abs(ts_ns1 - ts_ns2))
diff_max = 10 ** (-st_mtime_ns_round)
return diff_ts <= diff_max
@contextmanager @contextmanager