Mercurial > hg
diff mercurial/util.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 | 7cda0cacbbf6 |
children | b141b5243b37 |
line wrap: on
line diff
--- a/mercurial/util.py Wed Jan 16 16:49:15 2019 -0800 +++ b/mercurial/util.py Thu Jan 10 14:57:01 2019 +0100 @@ -2045,7 +2045,7 @@ function if need.''' return path.split(pycompat.ossep) -def mktempcopy(name, emptyok=False, createmode=None): +def mktempcopy(name, emptyok=False, createmode=None, enforcewritable=False): """Create a temporary file with the same contents from name The permission bits are copied from the original file. @@ -2061,7 +2061,8 @@ # Temporary files are created with mode 0600, which is usually not # what we want. If the original file already exists, just copy # its mode. Otherwise, manually obey umask. - copymode(name, temp, createmode) + copymode(name, temp, createmode, enforcewritable) + if emptyok: return temp try: @@ -2204,7 +2205,9 @@ def __init__(self, name, mode='w+b', createmode=None, checkambig=False): self.__name = name # permanent name self._tempname = mktempcopy(name, emptyok=('w' in mode), - createmode=createmode) + createmode=createmode, + enforcewritable=('w' in mode)) + self._fp = posixfile(self._tempname, mode) self._checkambig = checkambig