comparison 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
comparison
equal deleted inserted replaced
41288:17941fc53ae9 41289:593f6359681d
151 os.chmod(f, s | (s & 0o444) >> 2 & ~umask) 151 os.chmod(f, s | (s & 0o444) >> 2 & ~umask)
152 elif not x and sx: 152 elif not x and sx:
153 # Turn off all +x bits 153 # Turn off all +x bits
154 os.chmod(f, s & 0o666) 154 os.chmod(f, s & 0o666)
155 155
156 def copymode(src, dst, mode=None): 156 def copymode(src, dst, mode=None, enforcewritable=False):
157 '''Copy the file mode from the file at path src to dst. 157 '''Copy the file mode from the file at path src to dst.
158 If src doesn't exist, we're using mode instead. If mode is None, we're 158 If src doesn't exist, we're using mode instead. If mode is None, we're
159 using umask.''' 159 using umask.'''
160 try: 160 try:
161 st_mode = os.lstat(src).st_mode & 0o777 161 st_mode = os.lstat(src).st_mode & 0o777
164 raise 164 raise
165 st_mode = mode 165 st_mode = mode
166 if st_mode is None: 166 if st_mode is None:
167 st_mode = ~umask 167 st_mode = ~umask
168 st_mode &= 0o666 168 st_mode &= 0o666
169 os.chmod(dst, st_mode) 169
170 new_mode = st_mode
171
172 if enforcewritable:
173 new_mode |= stat.S_IWUSR
174
175 os.chmod(dst, new_mode)
170 176
171 def checkexec(path): 177 def checkexec(path):
172 """ 178 """
173 Check whether the given path is on a filesystem with UNIX-like exec flags 179 Check whether the given path is on a filesystem with UNIX-like exec flags
174 180