comparison mercurial/posix.py @ 27362:c220434a3461

posix: remove unixdomainserver class It's no longer used since the removal of the inotify extension.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 21 Nov 2015 16:21:52 +0900
parents b0d90fef16b6
children c7129ed280b8
comparison
equal deleted inserted replaced
27361:29f50344fa83 27362:c220434a3461
13 import grp 13 import grp
14 import os 14 import os
15 import pwd 15 import pwd
16 import re 16 import re
17 import select 17 import select
18 import socket
19 import stat 18 import stat
20 import sys 19 import sys
21 import tempfile 20 import tempfile
22 import unicodedata 21 import unicodedata
23 22
553 return not self == other 552 return not self == other
554 553
555 def executablepath(): 554 def executablepath():
556 return None # available on Windows only 555 return None # available on Windows only
557 556
558 class unixdomainserver(socket.socket):
559 def __init__(self, join, subsystem):
560 '''Create a unix domain socket with the given prefix.'''
561 super(unixdomainserver, self).__init__(socket.AF_UNIX)
562 sockname = subsystem + '.sock'
563 self.realpath = self.path = join(sockname)
564 if os.path.islink(self.path):
565 if os.path.exists(self.path):
566 self.realpath = os.readlink(self.path)
567 else:
568 os.unlink(self.path)
569 try:
570 self.bind(self.realpath)
571 except socket.error as err:
572 if err.args[0] == 'AF_UNIX path too long':
573 tmpdir = tempfile.mkdtemp(prefix='hg-%s-' % subsystem)
574 self.realpath = os.path.join(tmpdir, sockname)
575 try:
576 self.bind(self.realpath)
577 os.symlink(self.realpath, self.path)
578 except (OSError, socket.error):
579 self.cleanup()
580 raise
581 else:
582 raise
583 self.listen(5)
584
585 def cleanup(self):
586 def okayifmissing(f, path):
587 try:
588 f(path)
589 except OSError as err:
590 if err.errno != errno.ENOENT:
591 raise
592
593 okayifmissing(os.unlink, self.path)
594 if self.realpath != self.path:
595 okayifmissing(os.unlink, self.realpath)
596 okayifmissing(os.rmdir, os.path.dirname(self.realpath))
597
598 def statislink(st): 557 def statislink(st):
599 '''check whether a stat result is a symlink''' 558 '''check whether a stat result is a symlink'''
600 return st and stat.S_ISLNK(st.st_mode) 559 return st and stat.S_ISLNK(st.st_mode)
601 560
602 def statisexec(st): 561 def statisexec(st):