Patchwork [V2] chgserver: update the umask cache before each run

login
register
mail settings
Submitter Pulkit Goyal
Date March 31, 2020, 5:11 p.m.
Message ID <08a36f69ba2ade20096e.1585674710@workspace>
Download mbox | patch
Permalink /patch/45952/
State Accepted
Headers show

Comments

Pulkit Goyal - March 31, 2020, 5:11 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1585647693 -19800
#      Tue Mar 31 15:11:33 2020 +0530
# Node ID 08a36f69ba2ade20096ee882efa9c3e019032ea5
# Parent  588c91753fff6f10758a872b331b2f61e0413586
# EXP-Topic chg-test
chgserver: update the umask cache before each run

posix.py uses a global variable to store the umask value resulting in caching of
it when using chg. We need to update it before each command run as the umask can
change between commands.

This fixes test-inherit-mode.t with chg.
Yuya Nishihara - April 1, 2020, 12:50 p.m.
On Tue, 31 Mar 2020 22:41:50 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1585647693 -19800
> #      Tue Mar 31 15:11:33 2020 +0530
> # Node ID 08a36f69ba2ade20096ee882efa9c3e019032ea5
> # Parent  588c91753fff6f10758a872b331b2f61e0413586
> # EXP-Topic chg-test
> chgserver: update the umask cache before each run

Queued, thanks.

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -528,7 +528,7 @@  class chgcmdserver(commandserver.server)
     def _setumask(self, data):
         mask = struct.unpack(b'>I', data)[0]
         self.ui.log(b'chgserver', b'setumask %r\n', mask)
-        os.umask(mask)
+        util.setumask(mask)
 
     def runcommand(self):
         # pager may be attached within the runcommand session, which should
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -130,6 +130,16 @@  umask = platform.umask
 unlink = platform.unlink
 username = platform.username
 
+
+def setumask(val):
+    ''' updates the umask. used by chg server '''
+    if pycompat.iswindows:
+        return
+    os.umask(val)
+    global umask
+    platform.umask = umask = val & 0o777
+
+
 # small compat layer
 compengines = compression.compengines
 SERVERROLE = compression.SERVERROLE