diff mercurial/dirstateutils/timestamp.py @ 48379:08b060abd658

dirstate: move "get fs now" in the timestamp utility module We will need it during update. Differential Revision: https://phab.mercurial-scm.org/D11783
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 17 Nov 2021 12:24:00 +0100
parents 83d0bd45b662
children 9ae0353c9f5d
line wrap: on
line diff
--- a/mercurial/dirstateutils/timestamp.py	Wed Nov 17 10:26:48 2021 +0100
+++ b/mercurial/dirstateutils/timestamp.py	Wed Nov 17 12:24:00 2021 +0100
@@ -6,6 +6,7 @@
 from __future__ import absolute_import
 
 import functools
+import os
 import stat
 
 
@@ -54,6 +55,19 @@
         return self_subsec_nanos > other_subsec_nanos
 
 
+def get_fs_now(vfs):
+    """return a timestamp for "now" in the current vfs
+
+    This will raise an exception if no temporary files could be created.
+    """
+    tmpfd, tmpname = vfs.mkstemp()
+    try:
+        return mtime_of(os.fstat(tmpfd))
+    finally:
+        os.close(tmpfd)
+        vfs.unlink(tmpname)
+
+
 def zero():
     """
     Returns the `timestamp` at the Unix epoch.