mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-26 07:53:58 +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:
parent
b233dbb4db
commit
2ef09eaa77
1 changed files with 11 additions and 4 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue