mercurial/posix.py
branchstable
changeset 42562 97ada9b8d51b
parent 41827 faa04f45b5fe
child 43076 2372284d9457
--- a/mercurial/posix.py	Wed Jul 03 10:06:39 2019 +0800
+++ b/mercurial/posix.py	Mon Jul 08 13:12:20 2019 -0400
@@ -30,7 +30,6 @@
 
 osutil = policy.importmod(r'osutil')
 
-posixfile = open
 normpath = os.path.normpath
 samestat = os.path.samestat
 try:
@@ -52,6 +51,19 @@
 umask = os.umask(0)
 os.umask(umask)
 
+if not pycompat.ispy3:
+    def posixfile(name, mode=r'r', buffering=-1):
+        fp = open(name, mode=mode, buffering=buffering)
+        # The position when opening in append mode is implementation defined, so
+        # make it consistent by always seeking to the end.
+        if r'a' in mode:
+            fp.seek(0, os.SEEK_END)
+        return fp
+else:
+    # The underlying file object seeks as required in Python 3:
+    # https://github.com/python/cpython/blob/v3.7.3/Modules/_io/fileio.c#L474
+    posixfile = open
+
 def split(p):
     '''Same as posixpath.split, but faster