Przeglądaj źródła

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.
Thomas Waldmann 2 lat temu
rodzic
commit
2ef09eaa77
1 zmienionych plików z 11 dodań i 4 usunięć
  1. 11 4
      src/borg/testsuite/__init__.py

+ 11 - 4
src/borg/testsuite/__init__.py

@@ -42,14 +42,21 @@ except OSError:
 
 # The mtime get/set precision varies on different OS and Python versions
 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():
-    st_mtime_ns_round = -6
+    st_mtime_ns_round = -3  # 1us resolution
 else:
-    st_mtime_ns_round = -9
+    st_mtime_ns_round = -9  # 1s resolution
 
 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