hgext/inotify/server.py
changeset 12650 fed4bb2c8def
parent 11943 2d3cbcace897
child 15151 0d4f6e843b05
--- a/hgext/inotify/server.py	Fri Oct 08 21:43:21 2010 +0200
+++ b/hgext/inotify/server.py	Sat Oct 09 15:41:53 2010 +0200
@@ -332,18 +332,21 @@
         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: