Show More
@@ -15,7 +15,6 b' 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 | |
@@ -555,46 +554,6 b' class cachestat(object):' | |||||
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) |
General Comments 0
You need to be logged in to leave comments.
Login now