Patchwork [1,of,4] chgserver: narrow scope of chdir() to socket.bind()

login
register
mail settings
Submitter Yuya Nishihara
Date July 13, 2016, 12:09 p.m.
Message ID <4e4bf46112a5de1cccf3.1468411772@mimosa>
Download mbox | patch
Permalink /patch/15824/
State Accepted
Headers show

Comments

Yuya Nishihara - July 13, 2016, 12:09 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1463816579 -32400
#      Sat May 21 16:42:59 2016 +0900
# Node ID 4e4bf46112a5de1cccf339db1c9de4fb2f391085
# Parent  e5b4d79a9140c3d90e9b6aa22070351b73ef2d4c
chgserver: narrow scope of chdir() to socket.bind()

This helps extracting a utility function.

Patch

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -587,13 +587,13 @@  class AutoExitMixIn:  # use old-style to
             bakwdfd = os.open('.', os.O_DIRECTORY)
             os.chdir(dirname)
         self.socket.bind(basename)
-        self._socketstat = os.stat(basename)
-        # rename will replace the old socket file if exists atomically. the
-        # old server will detect ownership change and exit.
-        util.rename(basename, self.server_address)
         if bakwdfd:
             os.fchdir(bakwdfd)
             os.close(bakwdfd)
+        self._socketstat = os.stat(tempaddress)
+        # rename will replace the old socket file if exists atomically. the
+        # old server will detect ownership change and exit.
+        util.rename(tempaddress, self.server_address)
 
     def issocketowner(self):
         try: