changeset 6998:ddfcefab8b97

merge with -stable
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sat, 06 Sep 2008 17:04:01 +0200
parents 4e62be0208d3 (current diff) 9c4e488f105e (diff)
children f1546aa94362
files hgext/inotify/__init__.py hgext/inotify/server.py mercurial/dispatch.py tests/hghave
diffstat 6 files changed, 83 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/inotify/__init__.py	Fri Sep 05 11:04:36 2008 +0200
+++ b/hgext/inotify/__init__.py	Sat Sep 06 17:04:01 2008 +0200
@@ -24,7 +24,10 @@
 
     class service:
         def init(self):
-            self.master = server.Master(ui, repo, timeout)
+            try:
+                self.master = server.Master(ui, repo, timeout)
+            except server.AlreadyStartedException, inst:
+                raise util.Abort(str(inst))
 
         def run(self):
             try:
@@ -55,14 +58,13 @@
                                           clean, 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'))
                     os.unlink(repo.join('inotify.sock'))
-                elif err[0] != errno.ENOENT:
-                    raise
-                if ui.configbool('inotify', 'autostart'):
+                if err[0] in (errno.ECONNREFUSED, errno.ENOENT) and \
+                        ui.configbool('inotify', 'autostart'):
                     query = None
                     ui.debug(_('(starting inotify server)\n'))
                     try:
@@ -76,16 +78,20 @@
                     except Exception, inst:
                         ui.warn(_('could not start inotify server: '
                                        '%s\n') % inst)
-                        ui.print_exc()
-
                     if query:
                         try:
                             return query(ui, repo, files or [], match,
                                          ignored, clean, unknown)
                         except socket.error, err:
                             ui.warn(_('could not talk to new inotify '
-                                           'server: %s\n') % err[1])
-                            ui.print_exc()
+                                           'server: %s\n') % err[-1])
+                else:
+                    ui.warn(_('failed to contact inotify server: %s\n')
+                             % err[-1])
+                ui.print_exc()
+                # replace by old status function
+                ui.warn(_('deactivating inotify\n'))
+                self.status = super(inotifydirstate, self).status
 
             return super(inotifydirstate, self).status(
                 match, ignored, clean, unknown)
--- a/hgext/inotify/server.py	Fri Sep 05 11:04:36 2008 +0200
+++ b/hgext/inotify/server.py	Sat Sep 06 17:04:01 2008 +0200
@@ -9,7 +9,7 @@
 from mercurial.i18n import _
 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
@@ -554,13 +554,31 @@
         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
 
@@ -633,6 +651,9 @@
         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
--- a/mercurial/dispatch.py	Fri Sep 05 11:04:36 2008 +0200
+++ b/mercurial/dispatch.py	Sat Sep 06 17:04:01 2008 +0200
@@ -90,7 +90,7 @@
             else:
                 raise
     except socket.error, inst:
-        ui.warn(_("abort: %s\n") % inst[1])
+        ui.warn(_("abort: %s\n") % inst[-1])
     except IOError, inst:
         if hasattr(inst, "code"):
             ui.warn(_("abort: %s\n") % inst)
--- a/tests/hghave	Fri Sep 05 11:04:36 2008 +0200
+++ b/tests/hghave	Sat Sep 06 17:04:01 2008 +0200
@@ -73,7 +73,14 @@
         except:
             return False
     finally:
-        os.remove(path)  
+        os.remove(path)
+
+def has_inotify():
+    try:
+        import hgext.inotify.linux.watcher
+        return True
+    except ImportError:
+        return False
 
 def has_fifo():
     return hasattr(os, "mkfifo")
@@ -148,14 +155,15 @@
     "git": (has_git, "git command line client"),
     "hotshot": (has_hotshot, "python hotshot module"),
     "icasefs": (has_icasefs, "case insensitive file system"),
+    "inotify": (has_inotify, "inotify extension support"),
     "lsprof": (has_lsprof, "python lsprof module"),
     "mtn": (has_mtn, "monotone client (> 0.31)"),
+    "pygments": (has_pygments, "Pygments source highlighting library"),
     "svn": (has_svn, "subversion client and admin tools"),
     "svn-bindings": (has_svn_bindings, "subversion python bindings"),
     "symlink": (has_symlink, "symbolic links"),
     "tla": (has_tla, "GNU Arch tla client"),
     "unix-permissions": (has_unix_permissions, "unix-style permissions"),
-    "pygments": (has_pygments, "Pygments source highlighting library"),
 }
 
 def list_features():
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-inotify-issue1208	Sat Sep 06 17:04:01 2008 +0200
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+"$TESTDIR/hghave" inotify || exit 80
+
+echo "[extensions]" >> $HGRCPATH
+echo "inotify=" >> $HGRCPATH
+
+p="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+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 -d --pid-file=hg.pid
+cat hg.pid >> "$DAEMON_PIDS"
+echo % status
+hg status
+
+kill `cat hg.pid`
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-inotify-issue1208.out	Sat Sep 06 17:04:01 2008 +0200
@@ -0,0 +1,9 @@
+% fail
+failed to contact inotify server: AF_UNIX path too long
+deactivating inotify
+abort: could not start server: File exists
+% inserve
+% status
+failed to contact inotify server: AF_UNIX path too long
+deactivating inotify
+? hg.pid