summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-09-30 13:11:26 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-09-30 13:11:26 -0400
commit142ba4db72679fa2b17eb4ae33ac7d9764a71b09 (patch)
tree6fdefc1db5f47ca738b62164bc393755ac6fed98
parentecb2ac7f26e5da76d3b69872c65c6ccb875f86dc (diff)
assistant: More robust inotify handling; avoid crashing if a directory cannot be read.
-rw-r--r--Utility/INotify.hs15
-rw-r--r--debian/changelog2
-rw-r--r--doc/todo/wishlist:_display_name_of_object_when_addWatcher_gets_a_permission_denied.mdwn5
3 files changed, 16 insertions, 6 deletions
diff --git a/Utility/INotify.hs b/Utility/INotify.hs
index e9071d906..ffdad8be3 100644
--- a/Utility/INotify.hs
+++ b/Utility/INotify.hs
@@ -54,11 +54,12 @@ watchDir i dir ignored hooks
-- scan come before real inotify events.
lock <- newLock
let handler event = withLock lock (void $ go event)
- void (addWatch i watchevents dir handler)
- `catchIO` failedaddwatch
- withLock lock $
- mapM_ scan =<< filter (not . dirCruft) <$>
- getDirectoryContents dir
+ flip catchNonAsync failedwatch $ do
+ void (addWatch i watchevents dir handler)
+ `catchIO` failedaddwatch
+ withLock lock $
+ mapM_ scan =<< filter (not . dirCruft) <$>
+ getDirectoryContents dir
where
recurse d = watchDir i d ignored hooks
@@ -149,12 +150,14 @@ watchDir i dir ignored hooks
-- disk full error.
| isFullError e =
case errHook hooks of
- Nothing -> throw e
+ Nothing -> error $ "failed to add inotify watch on directory " ++ dir ++ " (" ++ show e ++ ")"
Just hook -> tooManyWatches hook dir
-- The directory could have been deleted.
| isDoesNotExistError e = return ()
| otherwise = throw e
+ failedwatch e = hPutStrLn stderr $ "failed to add watch on directory " ++ dir ++ " (" ++ show e ++ ")"
+
tooManyWatches :: (String -> Maybe FileStatus -> IO ()) -> FilePath -> IO ()
tooManyWatches hook dir = do
sysctlval <- querySysctl [Param maxwatches] :: IO (Maybe Integer)
diff --git a/debian/changelog b/debian/changelog
index 79815bef6..6727315c0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -26,6 +26,8 @@ git-annex (4.20130921) UNRELEASED; urgency=low
yet knowing about the new remote.
* OSX: Bundled gpg upgraded, now compatible with config files
written by MacGPG.
+ * assistant: More robust inotify handling; avoid crashing if a directory
+ cannot be read.
-- Joey Hess <joeyh@debian.org> Sun, 22 Sep 2013 19:42:29 -0400
diff --git a/doc/todo/wishlist:_display_name_of_object_when_addWatcher_gets_a_permission_denied.mdwn b/doc/todo/wishlist:_display_name_of_object_when_addWatcher_gets_a_permission_denied.mdwn
index 004194a79..837f0a587 100644
--- a/doc/todo/wishlist:_display_name_of_object_when_addWatcher_gets_a_permission_denied.mdwn
+++ b/doc/todo/wishlist:_display_name_of_object_when_addWatcher_gets_a_permission_denied.mdwn
@@ -1 +1,6 @@
When addWatcher gets a permission denied, it would be helpful to display the name of the object on which the permission was denied, in the error message which shows in the webapp.
+
+> I have made the inotify code more robust; now it doesn't crash if it
+> cannot read a directory or a file, and only logs a warning, which includes
+> the directory name.
+> [[done]] --[[Joey]]