comparison hgext/chgserver.py @ 29529:02de1dbd4f6e

chgserver: narrow scope of chdir() to socket.bind() This helps extracting a utility function.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 21 May 2016 16:42:59 +0900
parents e5b4d79a9140
children 3239e2fdd2e2
comparison
equal deleted inserted replaced
29528:9c3786713926 29529:02de1dbd4f6e
585 bakwdfd = None 585 bakwdfd = None
586 if dirname: 586 if dirname:
587 bakwdfd = os.open('.', os.O_DIRECTORY) 587 bakwdfd = os.open('.', os.O_DIRECTORY)
588 os.chdir(dirname) 588 os.chdir(dirname)
589 self.socket.bind(basename) 589 self.socket.bind(basename)
590 self._socketstat = os.stat(basename)
591 # rename will replace the old socket file if exists atomically. the
592 # old server will detect ownership change and exit.
593 util.rename(basename, self.server_address)
594 if bakwdfd: 590 if bakwdfd:
595 os.fchdir(bakwdfd) 591 os.fchdir(bakwdfd)
596 os.close(bakwdfd) 592 os.close(bakwdfd)
593 self._socketstat = os.stat(tempaddress)
594 # rename will replace the old socket file if exists atomically. the
595 # old server will detect ownership change and exit.
596 util.rename(tempaddress, self.server_address)
597 597
598 def issocketowner(self): 598 def issocketowner(self):
599 try: 599 try:
600 stat = os.stat(self.server_address) 600 stat = os.stat(self.server_address)
601 return (stat.st_ino == self._socketstat.st_ino and 601 return (stat.st_ino == self._socketstat.st_ino and