# HG changeset patch # User Nicolas Dumazet # Date 2010-10-09 13:41:53 # Node ID fed4bb2c8defa4d535063668152c126dc38a4a31 # Parent 6c0e1aee1b195e6b8690ed8c32d267e82fa262cb inotify: raise correct error if server is already started in a deep repository When path is too long to be an Unix socket address, we create a socket in a temporary directory and link from the long path to the shorter one. But checks in server code at startup were insufficient in this case, and used to raise an unclear "tried linking .hg/inotify.sock to a temporary socket but .hg/inotify.sock already exists" diff --git a/hgext/inotify/server.py b/hgext/inotify/server.py --- a/hgext/inotify/server.py +++ b/hgext/inotify/server.py @@ -332,18 +332,21 @@ class socketlistener(object): self.repowatcher = repowatcher self.sock = socket.socket(socket.AF_UNIX) self.sockpath = join(root, '.hg/inotify.sock') - self.realsockpath = None + + self.realsockpath = self.sockpath + if os.path.islink(self.sockpath): + if os.path.exists(self.sockpath): + self.realsockpath = os.readlink(self.sockpath) + else: + raise util.Abort('inotify-server: cannot start: ' + '.hg/inotify.sock is a broken symlink') try: - self.sock.bind(self.sockpath) + self.sock.bind(self.realsockpath) except socket.error, err: if err.args[0] == errno.EADDRINUSE: raise AlreadyStartedException(_('cannot start: socket is ' 'already bound')) if err.args[0] == "AF_UNIX path too long": - if os.path.islink(self.sockpath) and \ - not os.path.exists(self.sockpath): - raise util.Abort('inotify-server: cannot start: ' - '.hg/inotify.sock is a broken symlink') tempdir = tempfile.mkdtemp(prefix="hg-inotify-") self.realsockpath = os.path.join(tempdir, "inotify.sock") try: diff --git a/tests/test-inotify-issue1208.t b/tests/test-inotify-issue1208.t --- a/tests/test-inotify-issue1208.t +++ b/tests/test-inotify-issue1208.t @@ -26,4 +26,11 @@ status $ hg status ? hg.pid + +if we try to start twice the server, make sure we get a correct error + + $ hg inserve -d --pid-file=hg2.pid + abort: inotify-server: cannot start: socket is already bound + abort: child process failed to start + [255] $ kill `cat hg.pid`