Mercurial > hg
comparison hgext/inotify/server.py @ 9900:8939900073a8 stable
inotify: improve error messages
* prefix messages by inotify-(client|server)
* make sure that all warning and abort messages use the same format.
* in the case where inotify.sock is an old broken symlink, say so and abort
instead of trying to overwrite the already existing link
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Thu, 19 Nov 2009 11:06:01 +0900 |
parents | 97eda2133a9b |
children | 2e7902158af9 25e572394f5c |
comparison
equal
deleted
inserted
replaced
9899:be574a37a8ae | 9900:8939900073a8 |
---|---|
689 self.realsockpath = None | 689 self.realsockpath = None |
690 try: | 690 try: |
691 self.sock.bind(self.sockpath) | 691 self.sock.bind(self.sockpath) |
692 except socket.error, err: | 692 except socket.error, err: |
693 if err[0] == errno.EADDRINUSE: | 693 if err[0] == errno.EADDRINUSE: |
694 raise AlreadyStartedException(_('could not start server: %s') | 694 raise AlreadyStartedException( _('cannot start: socket is ' |
695 % err[1]) | 695 'already bound')) |
696 if err[0] == "AF_UNIX path too long": | 696 if err[0] == "AF_UNIX path too long": |
697 if os.path.islink(self.sockpath) and \ | |
698 not os.path.exists(self.sockpath): | |
699 raise util.Abort('inotify-server: cannot start: ' | |
700 '.hg/inotify.sock is a broken symlink') | |
697 tempdir = tempfile.mkdtemp(prefix="hg-inotify-") | 701 tempdir = tempfile.mkdtemp(prefix="hg-inotify-") |
698 self.realsockpath = os.path.join(tempdir, "inotify.sock") | 702 self.realsockpath = os.path.join(tempdir, "inotify.sock") |
699 try: | 703 try: |
700 self.sock.bind(self.realsockpath) | 704 self.sock.bind(self.realsockpath) |
701 os.symlink(self.realsockpath, self.sockpath) | 705 os.symlink(self.realsockpath, self.sockpath) |
704 os.unlink(self.realsockpath) | 708 os.unlink(self.realsockpath) |
705 except: | 709 except: |
706 pass | 710 pass |
707 os.rmdir(tempdir) | 711 os.rmdir(tempdir) |
708 if inst.errno == errno.EEXIST: | 712 if inst.errno == errno.EEXIST: |
709 raise AlreadyStartedException(_('could not start server: %s') | 713 raise AlreadyStartedException(_('cannot start: tried ' |
710 % inst.strerror) | 714 'linking .hg/inotify.sock to a temporary socket but' |
715 ' .hg/inotify.sock already exists')) | |
711 raise | 716 raise |
712 else: | 717 else: |
713 raise | 718 raise |
714 self.sock.listen(5) | 719 self.sock.listen(5) |
715 self.fileno = self.sock.fileno | 720 self.fileno = self.sock.fileno |
839 class service(object): | 844 class service(object): |
840 def init(self): | 845 def init(self): |
841 try: | 846 try: |
842 self.master = master(ui, dirstate, root, timeout) | 847 self.master = master(ui, dirstate, root, timeout) |
843 except AlreadyStartedException, inst: | 848 except AlreadyStartedException, inst: |
844 raise util.Abort(str(inst)) | 849 raise util.Abort("inotify-server: %s" % inst) |
845 | 850 |
846 def run(self): | 851 def run(self): |
847 try: | 852 try: |
848 self.master.run() | 853 self.master.run() |
849 finally: | 854 finally: |