Patchwork [2,of,4] inotify: don't fall over just because of a dangling symlink

login
register
mail settings
Submitter Bryan O'Sullivan
Date Dec. 19, 2012, 6:47 p.m.
Message ID <d1828f471b089e81496f.1355942841@fedora>
Download mbox | patch
Permalink /patch/200/
State Accepted
Commit cd53e40ab0e2ab9eff4f67508bc47b2a09d5c311
Headers show

Comments

Bryan O'Sullivan - Dec. 19, 2012, 6:47 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1355880812 28800
# Node ID d1828f471b089e81496fd56beba7d040d307fb2c
# Parent  c8dfa0f461967438222e919afe39ef175a5bb7f6
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.

Patch

diff --git a/hgext/inotify/server.py b/hgext/inotify/server.py
--- a/hgext/inotify/server.py
+++ b/hgext/inotify/server.py
@@ -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:
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
@@ -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