diff mercurial/posix.py @ 41289:593f6359681d

update: fix edge-case with update.atomic-file and read-only files We used to create the tempfile with the original file mode. That means creating a read-only tempfile when the original file is read-only, which crash if we need to write on the tempfile. The file in the working directory ends up being writable with and without the atomic update config, so the behavior is the same.
author Boris Feld <boris.feld@octobus.net>
date Thu, 10 Jan 2019 14:57:01 +0100
parents 47e3f554df35
children 587a3c976892
line wrap: on
line diff
--- a/mercurial/posix.py	Wed Jan 16 16:49:15 2019 -0800
+++ b/mercurial/posix.py	Thu Jan 10 14:57:01 2019 +0100
@@ -153,7 +153,7 @@
         # Turn off all +x bits
         os.chmod(f, s & 0o666)
 
-def copymode(src, dst, mode=None):
+def copymode(src, dst, mode=None, enforcewritable=False):
     '''Copy the file mode from the file at path src to dst.
     If src doesn't exist, we're using mode instead. If mode is None, we're
     using umask.'''
@@ -166,7 +166,13 @@
         if st_mode is None:
             st_mode = ~umask
         st_mode &= 0o666
-    os.chmod(dst, st_mode)
+
+    new_mode = st_mode
+
+    if enforcewritable:
+        new_mode |= stat.S_IWUSR
+
+    os.chmod(dst, new_mode)
 
 def checkexec(path):
     """