[PATCH] update: fix edge-case with update.atomic-file and read-only files

Yuya Nishihara yuya at tcha.org
Sun Jan 13 21:25:24 EST 2019


On Sun, 13 Jan 2019 10:28:33 +0100, Boris FELD wrote:
> On 12/01/2019 04:32, Yuya Nishihara wrote:
> >>          self._tempname = mktempcopy(name, emptyok=('w' in mode),
> >>                                      createmode=createmode)
> >> +
> >> +        # If we are gonna write on the tempfile, we need to make sure we have
> >> +        # the permission to do so
> >> +        if 'w' in mode and os.path.isfile(name):
> >> +            oldstat = filestat.frompath(name)
> >> +            newstat = oldstat.stat.st_mode | stat.S_IWUSR
> >> +            os.chmod(self._tempname, newstat)
> > Isn't it better to add an option for mktempcopy() to forcibly flag S_IWUSR
> > bit on?
> 
> I was hesitant between the two designs. I give a try to the mktempcopy
> modification design thanks to your comment and it seems better.
> 
> I'm not familiar with how Windows handle file permissions but I see that
> copymode for windows does nothing. Should we also avoid enforcing the
> writable bit on Windows platform?

Maybe no. If we didn't copy the file mode, the temporary file should be
writable.


More information about the Mercurial-devel mailing list