inotify: don't fall over just because of a dangling symlink
authorBryan O'Sullivan <bryano@fb.com>
Tue, 18 Dec 2012 17:33:32 -0800
changeset 18096 cd53e40ab0e2
parent 18095 8cbe0fed0c1f
child 18097 ae54cff742e2
inotify: don't fall over just because of a dangling symlink Previously, the inotify server failed to start if .hg/inotify.sock was a symlink that pointed to a non-existent path. This behaviour does not seem to make any sense. Now, if we encounter a broken symlink, we unlink it and continue.
hgext/inotify/server.py
tests/test-inotify-issue1208.t
--- a/hgext/inotify/server.py	Wed Dec 19 10:40:34 2012 -0800
+++ b/hgext/inotify/server.py	Tue Dec 18 17:33:32 2012 -0800
@@ -338,8 +338,7 @@
             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')
+                os.unlink(self.sockpath)
         try:
             self.sock.bind(self.realsockpath)
         except socket.error, err:
--- a/tests/test-inotify-issue1208.t	Wed Dec 19 10:40:34 2012 -0800
+++ b/tests/test-inotify-issue1208.t	Tue Dec 18 17:33:32 2012 -0800
@@ -6,16 +6,11 @@
   $ hg init $p
   $ cd $p
 
-fail
+dangling symlink should be deleted
 
   $ ln -sf doesnotexist .hg/inotify.sock
-  $ hg st
-  abort: inotify-server: cannot start: .hg/inotify.sock is a broken symlink
-  inotify-client: could not start inotify server: child process failed to start
-  $ hg inserve
-  abort: inotify-server: cannot start: .hg/inotify.sock is a broken symlink
-  [255]
-  $ rm .hg/inotify.sock
+  $ hg --config inotify.pidfile=../hg.pid st
+  $ kill `cat ../hg.pid`
 
 inserve