[PATCH] chgserver: update the umask cache before each run

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] chgserver: update the umask cache before each run

Pulkit Goyal
# HG changeset patch
# User Pulkit Goyal <[hidden email]>
# Date 1585647693 -19800
#      Tue Mar 31 15:11:33 2020 +0530
# Node ID 74566de0d15595223b5e11e98f1535b5c9df736c
# 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.

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -531,6 +531,8 @@ class chgcmdserver(commandserver.server)
         os.umask(mask)
 
     def runcommand(self):
+        # updates the umask cache in util.py and posix.py
+        util.updateumask()
         # pager may be attached within the runcommand session, which should
         # be detached at the end of the session. otherwise the pager wouldn't
         # receive EOF.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -130,6 +130,17 @@ umask = platform.umask
 unlink = platform.unlink
 username = platform.username
 
+
+def updateumask():
+    ''' updates the umask cache. used by chg server '''
+    val = os.umask(0)
+    os.umask(val)
+    global umask
+    umask = val
+    if not pycompat.iswindows:
+        platform.umask = val
+
+
 # small compat layer
 compengines = compression.compengines
 SERVERROLE = compression.SERVERROLE

_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] chgserver: update the umask cache before each run

Yuya Nishihara
On Tue, 31 Mar 2020 15:20:52 +0530, Pulkit Goyal wrote:

> # HG changeset patch
> # User Pulkit Goyal <[hidden email]>
> # Date 1585647693 -19800
> #      Tue Mar 31 15:11:33 2020 +0530
> # Node ID 74566de0d15595223b5e11e98f1535b5c9df736c
> # 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.
>
> diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
> --- a/mercurial/chgserver.py
> +++ b/mercurial/chgserver.py
> @@ -531,6 +531,8 @@ class chgcmdserver(commandserver.server)
>          os.umask(mask)
>  
>      def runcommand(self):
> +        # updates the umask cache in util.py and posix.py
> +        util.updateumask()
>          # pager may be attached within the runcommand session, which should
>          # be detached at the end of the session. otherwise the pager wouldn't
>          # receive EOF.
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -130,6 +130,17 @@ umask = platform.umask
>  unlink = platform.unlink
>  username = platform.username
>  
> +
> +def updateumask():
> +    ''' updates the umask cache. used by chg server '''
> +    val = os.umask(0)
> +    os.umask(val)
> +    global umask
> +    umask = val
> +    if not pycompat.iswindows:
> +        platform.umask = val

Can't we make chgcmdserver._setumask() to update the cache?
It should be better than temporarily changing the process umask to 0.

  def setumask(mask):
      if iswindows:
          return
      global umask
      os.umask(mask)
      platform.umask = umask = mask & 0o777  # or os.umask(mask) again to get the current value
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel