diff --git a/hgext/inotify/__init__.py b/hgext/inotify/__init__.py --- a/hgext/inotify/__init__.py +++ b/hgext/inotify/__init__.py @@ -58,7 +58,7 @@ def reposetup(ui, repo): list_clean, list_unknown) if result is not None: return result - except socket.error, err: + except (OSError, socket.error), err: if err[0] == errno.ECONNREFUSED: ui.warn(_('(found dead inotify server socket; ' 'removing it)\n')) diff --git a/hgext/inotify/server.py b/hgext/inotify/server.py --- a/hgext/inotify/server.py +++ b/hgext/inotify/server.py @@ -9,7 +9,7 @@ from mercurial.i18n import gettext as _ from mercurial import osutil, ui, util import common -import errno, os, select, socket, stat, struct, sys, time +import errno, os, select, socket, stat, struct, sys, tempfile, time try: import linux as inotify @@ -556,13 +556,31 @@ class Server(object): self.timeout = timeout self.sock = socket.socket(socket.AF_UNIX) self.sockpath = self.repo.join('inotify.sock') + self.realsockpath = None try: self.sock.bind(self.sockpath) except socket.error, err: if err[0] == errno.EADDRINUSE: - raise AlreadyStartedException(_('could not start server: %s') \ + raise AlreadyStartedException(_('could not start server: %s') % err[1]) - raise + if err[0] == "AF_UNIX path too long": + tempdir = tempfile.mkdtemp(prefix="hg-inotify-") + self.realsockpath = os.path.join(tempdir, "inotify.sock") + try: + self.sock.bind(self.realsockpath) + os.symlink(self.realsockpath, self.sockpath) + except (OSError, socket.error), inst: + try: + os.unlink(self.realsockpath) + except: + pass + os.rmdir(tempdir) + if inst.errno == errno.EEXIST: + raise AlreadyStartedException(_('could not start server: %s') + % inst.strerror) + raise + else: + raise self.sock.listen(5) self.fileno = self.sock.fileno @@ -635,6 +653,9 @@ class Server(object): self.sock.close() try: os.unlink(self.sockpath) + if self.realsockpath: + os.unlink(self.realsockpath) + os.rmdir(os.path.dirname(self.realsockpath)) except OSError, err: if err.errno != errno.ENOENT: raise diff --git a/tests/test-inotify-issue1208 b/tests/test-inotify-issue1208 --- a/tests/test-inotify-issue1208 +++ b/tests/test-inotify-issue1208 @@ -9,7 +9,16 @@ p="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx hg init $p cd $p +echo % fail +ln -sf doesnotexist .hg/inotify.sock +hg st +hg inserve +rm .hg/inotify.sock + echo % inserve -hg inserve +hg inserve -d --pid-file=hg.pid +cat hg.pid >> "$DAEMON_PIDS" echo % status hg status + +kill `cat hg.pid` diff --git a/tests/test-inotify-issue1208.out b/tests/test-inotify-issue1208.out --- a/tests/test-inotify-issue1208.out +++ b/tests/test-inotify-issue1208.out @@ -1,5 +1,9 @@ +% fail +failed to contact inotify server: AF_UNIX path too long +deactivating inotify +abort: could not start server: File exists % inserve -abort: AF_UNIX path too long % status failed to contact inotify server: AF_UNIX path too long deactivating inotify +? hg.pid