Mercurial > hg
comparison hgext/inotify/server.py @ 6997:9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
If we can't create the unix socket because the path is too long
we create the socket in a temporary directory and symlink it into
the repo.
Fix issue1208
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sat, 06 Sep 2008 14:11:33 +0200 |
parents | bf727bab38b9 |
children | ddfcefab8b97 |
comparison
equal
deleted
inserted
replaced
6996:fecf060f32a1 | 6997:9c4e488f105e |
---|---|
7 # of the GNU General Public License, incorporated herein by reference. | 7 # of the GNU General Public License, incorporated herein by reference. |
8 | 8 |
9 from mercurial.i18n import gettext as _ | 9 from mercurial.i18n import gettext as _ |
10 from mercurial import osutil, ui, util | 10 from mercurial import osutil, ui, util |
11 import common | 11 import common |
12 import errno, os, select, socket, stat, struct, sys, time | 12 import errno, os, select, socket, stat, struct, sys, tempfile, time |
13 | 13 |
14 try: | 14 try: |
15 import linux as inotify | 15 import linux as inotify |
16 from linux import watcher | 16 from linux import watcher |
17 except ImportError: | 17 except ImportError: |
554 self.repo = repo | 554 self.repo = repo |
555 self.watcher = watcher | 555 self.watcher = watcher |
556 self.timeout = timeout | 556 self.timeout = timeout |
557 self.sock = socket.socket(socket.AF_UNIX) | 557 self.sock = socket.socket(socket.AF_UNIX) |
558 self.sockpath = self.repo.join('inotify.sock') | 558 self.sockpath = self.repo.join('inotify.sock') |
559 self.realsockpath = None | |
559 try: | 560 try: |
560 self.sock.bind(self.sockpath) | 561 self.sock.bind(self.sockpath) |
561 except socket.error, err: | 562 except socket.error, err: |
562 if err[0] == errno.EADDRINUSE: | 563 if err[0] == errno.EADDRINUSE: |
563 raise AlreadyStartedException(_('could not start server: %s') \ | 564 raise AlreadyStartedException(_('could not start server: %s') |
564 % err[1]) | 565 % err[1]) |
565 raise | 566 if err[0] == "AF_UNIX path too long": |
567 tempdir = tempfile.mkdtemp(prefix="hg-inotify-") | |
568 self.realsockpath = os.path.join(tempdir, "inotify.sock") | |
569 try: | |
570 self.sock.bind(self.realsockpath) | |
571 os.symlink(self.realsockpath, self.sockpath) | |
572 except (OSError, socket.error), inst: | |
573 try: | |
574 os.unlink(self.realsockpath) | |
575 except: | |
576 pass | |
577 os.rmdir(tempdir) | |
578 if inst.errno == errno.EEXIST: | |
579 raise AlreadyStartedException(_('could not start server: %s') | |
580 % inst.strerror) | |
581 raise | |
582 else: | |
583 raise | |
566 self.sock.listen(5) | 584 self.sock.listen(5) |
567 self.fileno = self.sock.fileno | 585 self.fileno = self.sock.fileno |
568 | 586 |
569 def handle_timeout(self): | 587 def handle_timeout(self): |
570 pass | 588 pass |
633 | 651 |
634 def shutdown(self): | 652 def shutdown(self): |
635 self.sock.close() | 653 self.sock.close() |
636 try: | 654 try: |
637 os.unlink(self.sockpath) | 655 os.unlink(self.sockpath) |
656 if self.realsockpath: | |
657 os.unlink(self.realsockpath) | |
658 os.rmdir(os.path.dirname(self.realsockpath)) | |
638 except OSError, err: | 659 except OSError, err: |
639 if err.errno != errno.ENOENT: | 660 if err.errno != errno.ENOENT: |
640 raise | 661 raise |
641 | 662 |
642 class Master(object): | 663 class Master(object): |