inotify: deactivate inotify status on failure
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Sat, 06 Sep 2008 12:49:20 +0200
changeset 6996 fecf060f32a1
parent 6995 25619b72f86a
child 6997 9c4e488f105e
inotify: deactivate inotify status on failure workaround issue1208, add test fix traceback handling (socket.error is a singleton in this case)
hgext/inotify/__init__.py
tests/hghave
tests/test-inotify-issue1208
tests/test-inotify-issue1208.out
--- a/hgext/inotify/__init__.py	Sat Sep 06 12:48:52 2008 +0200
+++ b/hgext/inotify/__init__.py	Sat Sep 06 12:49:20 2008 +0200
@@ -63,9 +63,8 @@
                     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:
@@ -79,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,
                                          list_ignored, list_clean, list_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(
                 files, match or util.always, list_ignored, list_clean,
--- a/tests/hghave	Sat Sep 06 12:48:52 2008 +0200
+++ b/tests/hghave	Sat Sep 06 12:49:20 2008 +0200
@@ -57,6 +57,13 @@
     finally:
         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")
 
@@ -129,14 +136,15 @@
     "fifo": (has_fifo, "named pipes"),
     "git": (has_git, "git command line client"),
     "hotshot": (has_hotshot, "python hotshot module"),
+    "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 12:49:20 2008 +0200
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+"$TESTDIR/hghave" inotify || exit 80
+
+echo "[extensions]" >> $HGRCPATH
+echo "inotify=" >> $HGRCPATH
+
+p="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+hg init $p
+cd $p
+
+echo % inserve
+hg inserve
+echo % status
+hg status
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-inotify-issue1208.out	Sat Sep 06 12:49:20 2008 +0200
@@ -0,0 +1,5 @@
+% inserve
+abort: AF_UNIX path too long
+% status
+failed to contact inotify server: AF_UNIX path too long
+deactivating inotify