Fixing issue1542, adding a relevant test
authorNicolas Dumazet <nicdumz.commits@gmail.com>
Thu, 26 Mar 2009 19:01:06 +0900
changeset 7892 67e59a9886d5
parent 7891 3e0c28145e6a
child 7893 606723f4a327
Fixing issue1542, adding a relevant test inotify is smart enough to notify you about any changes in a directory, even if you only watch the directory, and none if its contents: the recursive add_watch I added was unnecessary. The only thing that matters here is the recursive status update on directory deletion. And scan() has to be called _before_ the deferred call is registered. (race condition: depending on the times, the previous patch could apparently fail on the provided test. It's not the case anymore.)
hgext/inotify/server.py
tests/test-inotify-issue1542
tests/test-inotify-issue1542.out
--- a/hgext/inotify/server.py	Wed Mar 11 20:28:09 2009 +0100
+++ b/hgext/inotify/server.py	Thu Mar 26 19:01:06 2009 +0900
@@ -304,6 +304,11 @@
                         dd[fn] = status
             else:
                 d.pop(fn, None)
+        elif not status:
+            # a directory is being removed, check its contents
+            for subfile, b in oldstatus.copy().iteritems():
+                self.updatestatus(wfn + '/' + subfile, None)
+
 
     def check_deleted(self, key):
         # Files that had been deleted but were present in the dirstate
@@ -473,8 +478,7 @@
 
         if evt.mask & inotify.IN_ISDIR:
             self.scan(wpath)
-        else:
-            self.schedule_work(wpath, 'd')
+        self.schedule_work(wpath, 'd')
 
     def process_modify(self, wpath, evt):
         if self.ui.debugflag:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-inotify-issue1542	Thu Mar 26 19:01:06 2009 +0900
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+"$TESTDIR/hghave" inotify || exit 80
+
+hg init
+
+touch a
+mkdir dir
+touch dir/b
+touch dir/c
+
+echo "[extensions]" >> $HGRCPATH
+echo "inotify=" >> $HGRCPATH
+
+hg add dir/c
+
+echo % inserve
+hg inserve -d --pid-file=hg.pid 2>&1
+cat hg.pid >> "$DAEMON_PIDS"
+
+hg st
+
+echo % moving dir out
+mv dir ../tmp-test-inotify-issue1542
+
+echo % status
+hg st
+
+sleep 1
+echo "Are we able to kill the service? if not, the service died on some error"
+kill `cat hg.pid`
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-inotify-issue1542.out	Thu Mar 26 19:01:06 2009 +0900
@@ -0,0 +1,11 @@
+% inserve
+A dir/c
+? a
+? dir/b
+? hg.pid
+% moving dir out
+% status
+! dir/c
+? a
+? hg.pid
+Are we able to kill the service? if not, the service died on some error