Patchwork [4,of,5] chgserver: add umask method

login
register
mail settings
Submitter Jun Wu
Date Feb. 15, 2016, 2:42 p.m.
Message ID <35ad63ce921c694c5063.1455547372@x1c>
Download mbox | patch
Permalink /patch/13201/
State Accepted
Headers show

Comments

Jun Wu - Feb. 15, 2016, 2:42 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1455546497 0
#      Mon Feb 15 14:28:17 2016 +0000
# Node ID 35ad63ce921c694c506304e36486063c1cc7f9c5
# Parent  d1444fdc143a66f041052701d5de27a3f13881d8
chgserver: add umask method

Before this patch, the server won't inherit umask from the client, which
will fail test-inherit-mode.t. This patch provides a way for the client
to change umask of the server, similar to chdir.
Yuya Nishihara - Feb. 16, 2016, 2:21 p.m.
On Mon, 15 Feb 2016 14:42:52 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1455546497 0
> #      Mon Feb 15 14:28:17 2016 +0000
> # Node ID 35ad63ce921c694c506304e36486063c1cc7f9c5
> # Parent  d1444fdc143a66f041052701d5de27a3f13881d8
> chgserver: add umask method
> 
> Before this patch, the server won't inherit umask from the client, which
> will fail test-inherit-mode.t. This patch provides a way for the client
> to change umask of the server, similar to chdir.
> 
> diff --git a/hgext/chgserver.py b/hgext/chgserver.py
> --- a/hgext/chgserver.py
> +++ b/hgext/chgserver.py
> @@ -289,6 +289,14 @@
>          _log('chdir to %r\n' % path)
>          os.chdir(path)
>  
> +    def umask(self):
> +        """Change umask"""
> +        mask = self._readstr()
> +        if mask is None:
> +            return
> +        _log('umask %r\n' % mask)
> +        os.umask(int(mask))

Command-server protocol is binary. Can it be a 32bit unsigned integer in
network byteorder?

And I think 'setumask' is better name as this 'umask' command doesn't return
the old value.
Jun Wu - Feb. 16, 2016, 2:55 p.m.
On 02/16/2016 02:21 PM, Yuya Nishihara wrote:
> Command-server protocol is binary. Can it be a 32bit unsigned integer
> in network byteorder?

Was a bit worried about sizeof(mode_t) > 4 on some strange OSes but
it looks pretty unlikely. Will include the change in V2.

> And I think 'setumask' is better name as this 'umask' command doesn't
> return the old value.

I think you mean 'getumask'. It is sadly a GNU extension. umask is more
portable.
Yuya Nishihara - Feb. 16, 2016, 3:45 p.m.
On Tue, 16 Feb 2016 14:55:15 +0000, Jun Wu wrote:
> On 02/16/2016 02:21 PM, Yuya Nishihara wrote:
> > Command-server protocol is binary. Can it be a 32bit unsigned integer
> > in network byteorder?
> 
> Was a bit worried about sizeof(mode_t) > 4 on some strange OSes but
> it looks pretty unlikely. Will include the change in V2.

Thanks.

> > And I think 'setumask' is better name as this 'umask' command doesn't
> > return the old value.
> 
> I think you mean 'getumask'. It is sadly a GNU extension. umask is more
> portable.

I meant the command should be called as 'setumask'.

FWIW, 'getumask' is vaporware. It isn't implemented yet but for GNU/Hurd.

Patch

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -289,6 +289,14 @@ 
         _log('chdir to %r\n' % path)
         os.chdir(path)
 
+    def umask(self):
+        """Change umask"""
+        mask = self._readstr()
+        if mask is None:
+            return
+        _log('umask %r\n' % mask)
+        os.umask(int(mask))
+
     def getpager(self):
         """Read cmdargs and write pager command to r-channel if enabled
 
@@ -341,7 +349,8 @@ 
     capabilities.update({'attachio': attachio,
                          'chdir': chdir,
                          'getpager': getpager,
-                         'setenv': setenv})
+                         'setenv': setenv,
+                         'umask': umask})
 
 # copied from mercurial/commandserver.py
 class _requesthandler(SocketServer.StreamRequestHandler):