chgserver: add "setumask2" command which uses correct message frame
authorYuya Nishihara <yuya@tcha.org>
Thu, 04 Oct 2018 23:25:55 +0900
changeset 40108 e5fbdc3659fc
parent 40107 212a52d8e9d8
child 40109 413b6b10fdd5
chgserver: add "setumask2" command which uses correct message frame The first 4 bytes should be a length field, not a value. Spotted while porting chg functions to the Rust one.
mercurial/chgserver.py
--- a/mercurial/chgserver.py	Tue Oct 09 22:29:10 2018 +0200
+++ b/mercurial/chgserver.py	Thu Oct 04 23:25:55 2018 +0900
@@ -19,7 +19,8 @@
 'setenv' command
     replace os.environ completely
 
-'setumask' command
+'setumask' command (DEPRECATED)
+'setumask2' command
     set umask
 
 'validate' command
@@ -452,8 +453,20 @@
         os.chdir(path)
 
     def setumask(self):
+        """Change umask (DEPRECATED)"""
+        # BUG: this does not follow the message frame structure, but kept for
+        # backward compatibility with old chg clients for some time
+        self._setumask(self._read(4))
+
+    def setumask2(self):
         """Change umask"""
-        mask = struct.unpack('>I', self._read(4))[0]
+        data = self._readstr()
+        if len(data) != 4:
+            raise ValueError('invalid mask length in setumask2 request')
+        self._setumask(data)
+
+    def _setumask(self, data):
+        mask = struct.unpack('>I', data)[0]
         _log('setumask %r\n' % mask)
         os.umask(mask)
 
@@ -488,7 +501,8 @@
                          'chdir': chdir,
                          'runcommand': runcommand,
                          'setenv': setenv,
-                         'setumask': setumask})
+                         'setumask': setumask,
+                         'setumask2': setumask2})
 
     if util.safehasattr(procutil, 'setprocname'):
         def setprocname(self):