fix fsevents rename handling

For both files and whole directories; also tested on moving whole dirs out
of and into the working copy.
This commit is contained in:
Joey Hess 2012-12-28 16:20:05 -04:00
parent 6e4ec17da4
commit 94d735c12a
2 changed files with 16 additions and 14 deletions

View file

@ -38,23 +38,28 @@ watchDir dir ignored hooks = do
if hasflag eventFlagItemIsDir if hasflag eventFlagItemIsDir
then runhook delDirHook Nothing then runhook delDirHook Nothing
else runhook delHook Nothing else runhook delHook Nothing
{- TODO deal with moving whole directories -} when (hasflag eventFlagItemCreated) $
when (hasflag eventFlagItemCreated || (hasflag eventFlagItemRenamed && not (hasflag eventFlagItemRemoved))) $ do maybe noop handleadd =<< getstatus (eventPath evt)
ms <- getstatus $ eventPath evt {- When a file or dir is renamed, a rename event is
case ms of - received for both its old and its new name. -}
Nothing -> noop when (hasflag eventFlagItemRenamed) $
Just s if hasflag eventFlagItemIsDir
| Files.isSymbolicLink s -> then ifM (doesDirectoryExist $ eventPath evt)
runhook addSymlinkHook ms ( scan $ eventPath evt
| Files.isRegularFile s -> , runhook delDirHook Nothing
runhook addHook ms )
| otherwise -> noop else maybe (runhook delHook Nothing) handleadd
=<< getstatus (eventPath evt)
when (hasflag eventFlagItemModified && not (hasflag eventFlagItemIsDir)) $ do when (hasflag eventFlagItemModified && not (hasflag eventFlagItemIsDir)) $ do
ms <- getstatus $ eventPath evt ms <- getstatus $ eventPath evt
runhook modifyHook ms runhook modifyHook ms
where where
hasflag f = eventFlags evt .&. f /= 0 hasflag f = eventFlags evt .&. f /= 0
runhook h s = maybe noop (\a -> a (eventPath evt) s) (h hooks) runhook h s = maybe noop (\a -> a (eventPath evt) s) (h hooks)
handleadd s
| Files.isSymbolicLink s = runhook addSymlinkHook $ Just s
| Files.isRegularFile s = runhook addHook $ Just s
| otherwise = noop
scan d = unless (ignoredPath ignored d) $ scan d = unless (ignoredPath ignored d) $
mapM_ go =<< dirContentsRecursive d mapM_ go =<< dirContentsRecursive d

View file

@ -15,9 +15,6 @@ available!
See [[bug|bugs/Issue_on_OSX_with_some_system_limits]]. (Does not affect See [[bug|bugs/Issue_on_OSX_with_some_system_limits]]. (Does not affect
OSX any longer). OSX any longer).
* The OSX FSEvents code is new and relatively untested. A known problem is
that it does not handle whole directory renames right.
## todo ## todo
* Run niced and ioniced? Seems to make sense, this is a background job. * Run niced and ioniced? Seems to make sense, this is a background job.