| author | LennartKolmodin <> | 2012-10-28 12:00:00 (GMT) |
|---|---|---|
| committer | hdiff <hdiff@luite.com> | 2012-10-28 12:00:00 (GMT) |
| commit | 1e15b1ae98469093b7709ff4b4c7d4c0318f33b2 (patch) (side-by-side diff) | |
| tree | 55a6b07e983a8c7a8e615b113835374e03e5da7a | |
| parent | b51224b97909a535b72716066c729289facb66ff (diff) | |
version 0.3.30.3.3
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | README.html | 247 | ||||
| -rw-r--r-- | README.md (renamed from README) | 68 | ||||
| -rwxr-xr-x[-rw-r--r--] | Setup.lhs | 0 | ||||
| -rw-r--r-- | hinotify.cabal | 18 | ||||
| -rw-r--r-- | src/System/INotify.hsc | 37 | ||||
| -rw-r--r-- | src/System/INotify/Masks.hsc | 2 | ||||
| -rwxr-xr-x[-rw-r--r--] | tests/test-all | 0 |
8 files changed, 70 insertions, 306 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f13843 --- a/dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +dist +_darcs +tests/*.hi +tests/*.o diff --git a/README.html b/README.html deleted file mode 100644 index a1cc9c5..0000000 --- a/README.html +++ b/dev/null @@ -1,247 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> - <title>hinotify: inotify for Haskell</title> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> - <meta name="generator" content="pandoc" /> - <meta name="author" content="Lennart Kolmodin - '+''+e+''+''); - // --> - kolmodin at gmail dot com" /> - <meta name="date" content="December 26, 2007–2011" /> - <link rel="stylesheet" href="hinotify.css" type="text/css" /> -</head> -<body> -<h1 class="title">hinotify: inotify for Haskell</h1> -<div id="TOC" -><ul - ><li - ><a href="#about" - >About</a - ></li - ><li - ><a href="#news" - >News</a - ></li - ><li - ><a href="#api" - >API</a - ></li - ><li - ><a href="#download" - >Download</a - ></li - ><li - ><a href="#author" - >Author</a - ></li - ><li - ><a href="#legal" - >Legal</a - ></li - ></ul - ></div -> -<div id="about" -><h2 - ><a href="#TOC" - >About</a - ></h2 - ><p - >hinotify, a library to <a href="http://www.kernel.org/pub/linux/kernel/people/rml/inotify/" - >inotify</a - > which has been part of the Linux kernel since 2.6.13.</p - ><p - >inotify provides file system event notification, simply add a watcher to a file or directory and get an event when it is accessed or modified.</p - ><p - >This module is named <code - >hinotify</code - >.</p - ><p - >See example code in the <code - >examples</code - > directory, distributed with the source code.</p - ></div -><div id="news" -><h2 - ><a href="#TOC" - >News</a - ></h2 - ><p - ><strong - >hinotify 0.3.2</strong - ></p - ><ul - ><li - >Make each <code - >WatchDescriptor</code - > contain its <code - >INotify</code - >. Changes to the function types:</li - ></ul - ><blockquote - ><pre - ><code - > -removeWatch :: INotify -> WatchDescriptor -> IO () - +removeWatch :: WatchDescriptor -> IO () -</code - ></pre - ></blockquote - ><ul - ><li - >Fix typo in declaration of <code - >Deleted</code - > in <code - >data Event</code - >;</li - ></ul - ><blockquote - ><pre - ><code - > - { isDirecotry :: Bool - + { isDirectory :: Bool -</code - ></pre - ></blockquote - ><p - ><strong - >hinotify 0.3.1</strong - ></p - ><ul - ><li - >Use <code - >inotify.h</code - > from <code - >glibc</code - > rather than from the linux headers, as recommended upstream.</li - ></ul - ><p - ><strong - >hinotify 0.3</strong - ></p - ><ul - ><li - >Compiles with GHC 6.12, GHC 6.10.4, GHC 6.8.2 and GHC 6.6.1</li - ></ul - ><p - ><strong - >hinotify 0.2</strong - ></p - ><ul - ><li - >Updates to the API<ul - ><li - >Function names is now in semiCamelCase</li - ><li - >Restructure event parameters to make it more consistent</li - ></ul - ></li - ><li - >Small test suit in <code - >tests/</code - ></li - ><li - >Compiles with GHC 6.8.2 and GHC 6.6.1</li - ><li - >Requires Cabal 1.2</li - ></ul - ><dl - ><dt - ><strong - >hinotify 0.1</strong - ></dt - ><dd - >Initial release</dd - ></dl - ></div -><div id="api" -><h2 - ><a href="#TOC" - >API</a - ></h2 - ><p - >The API basically consists of:</p - ><pre - ><code - >initINotify :: IO INotify -addWatch :: INotify - -> [EventVariety] -- different events to listen on - -> FilePath -- file/directory to watch - -> (Event -> IO ()) -- event handler - -> IO WatchDescriptor -removeWatch :: WatchDescriptor -> IO () -</code - ></pre - ><p - >A sample program:</p - ><pre - ><code - >import System.Directory -import System.IO - -import System.INotify - -main :: IO () -main = do - inotify <- initINotify - print inotify - home <- getHomeDirectory - wd <- addWatch - inotify - [Open,Close,Access,Modify,Move] - home - print - print wd - putStrLn "Listens to your home directory. Hit enter to terminate." - getLine - removeWatch wd -</code - ></pre - ></div -><div id="download" -><h2 - ><a href="#TOC" - >Download</a - ></h2 - ><p - >The code is available via the <a href="http://code.haskell.org/hinotify/" - >homepage</a - >, and via darcs:</p - ><pre - ><code - >darcs get --partial http://code.haskell.org/hinotify/ -</code - ></pre - ><p - >The <a href="http://hackage.haskell.org/packages/archive/hinotify/latest/doc/html/System-INotify.html" - >API</a - > is available online.</p - ><p - >I’m most grateful for feedback on the API, and what else you might have to suggest.</p - ></div -><div id="author" -><h2 - ><a href="#TOC" - >Author</a - ></h2 - ><p - >Lennart Kolmodin</p - ><p - ><code - >kolmodin at gmail.com</code - ></p - ></div -><div id="legal" -><h2 - ><a href="#TOC" - >Legal</a - ></h2 - ><p - >This software is released under a BSD-style license. See LICENSE for more details.</p - ><p - >Copyright © 2007–2011 Lennart Kolmodin</p - ></div -> -</body> -</html> - @@ -1,6 +1,5 @@ -% hinotify: inotify for Haskell -% Lennart Kolmodin <kolmodin@gmail.com> -% December 26, 2007-2011 +hinotify: inotify for Haskell +============================= About ----- @@ -59,43 +58,46 @@ API The API basically consists of: - initINotify :: IO INotify - addWatch :: INotify - -> [EventVariety] -- different events to listen on - -> FilePath -- file/directory to watch - -> (Event -> IO ()) -- event handler - -> IO WatchDescriptor - removeWatch :: WatchDescriptor -> IO () +```haskell +initINotify :: IO INotify +addWatch :: INotify + -> [EventVariety] -- different events to listen on + -> FilePath -- file/directory to watch + -> (Event -> IO ()) -- event handler + -> IO WatchDescriptor +removeWatch :: WatchDescriptor -> IO () +``` A sample program: - import System.Directory - import System.IO - - import System.INotify - - main :: IO () - main = do - inotify <- initINotify - print inotify - home <- getHomeDirectory - wd <- addWatch - inotify - [Open,Close,Access,Modify,Move] - home - print - print wd - putStrLn "Listens to your home directory. Hit enter to terminate." - getLine - removeWatch wd - +```haskell +import System.Directory +import System.IO + +import System.INotify + +main :: IO () +main = do + inotify <- initINotify + print inotify + home <- getHomeDirectory + wd <- addWatch + inotify + [Open,Close,Access,Modify,Move] + home + print + print wd + putStrLn "Listens to your home directory. Hit enter to terminate." + getLine + removeWatch wd +``` Download -------- The code is available via the [homepage], and via darcs: - darcs get --partial http://code.haskell.org/hinotify/ + git clone https://github.com/kolmodin/hinotify.git The [API] is available online. @@ -115,8 +117,8 @@ Legal This software is released under a BSD-style license. See LICENSE for more details. -Copyright © 2007-2011 Lennart Kolmodin +Copyright © 2007-2012 Lennart Kolmodin -[homepage]: http://code.haskell.org/hinotify/ +[homepage]: https://github.com/kolmodin/hinotify.git [API]: http://hackage.haskell.org/packages/archive/hinotify/latest/doc/html/System-INotify.html diff --git a/Setup.lhs b/Setup.lhs index 0901d60..0901d60 100644..100755 --- a/Setup.lhs +++ b/Setup.lhs diff --git a/hinotify.cabal b/hinotify.cabal index e7f763d..fda6e15 100644 --- a/hinotify.cabal +++ b/hinotify.cabal @@ -1,7 +1,7 @@ name: hinotify -version: 0.3.2 +version: 0.3.3 build-type: Simple -synopsis: Haskell binding to INotify +synopsis: Haskell binding to inotify description: . This library provides a wrapper to the Linux Kernel's inotify feature, @@ -9,13 +9,17 @@ description: accessed or modified. . category: System -homepage: http://code.haskell.org/hinotify/README.html +homepage: https://github.com/kolmodin/hinotify.git license: BSD3 license-file: LICENSE author: Lennart Kolmodin maintainer: Lennart Kolmodin <kolmodin@gmail.com> -extra-source-files: README -cabal-version: >= 1.2 +extra-source-files: README.md +cabal-version: >= 1.6 + +source-repository head + type: git + location: git://github.com/kolmodin/hinotify.git flag split-base description: Choose the new smaller, split-up base package. @@ -23,7 +27,7 @@ flag split-base library build-depends: unix if flag(split-base) - build-depends: base >= 3 && < 5, containers, directory + build-depends: base >= 4.3.0.0 && < 5, containers, directory else build-depends: base < 3 extensions: ForeignFunctionInterface @@ -33,6 +37,6 @@ library other-modules: System.INotify.Masks - ghc-options: -Wall + ghc-options: -Wall hs-source-dirs: src diff --git a/src/System/INotify.hsc b/src/System/INotify.hsc index ff81247..286f114 100644 --- a/src/System/INotify.hsc +++ b/src/System/INotify.hsc @@ -1,9 +1,9 @@ ----------------------------------------------------------------------------- -- | -- Module : System.INotify --- Copyright : (c) Lennart Kolmodin 2006 +-- Copyright : (c) Lennart Kolmodin 2006-2012 -- License : BSD3 --- Maintainer : kolmodin@dtek.chalmers.se +-- Maintainer : kolmodin@gmail.com -- Stability : experimental -- Portability : hc portable, linux only -- @@ -37,16 +37,14 @@ module System.INotify import Prelude hiding (init) import Control.Monad import Control.Concurrent -import Control.Concurrent.MVar -import Control.Exception (bracket) +import Control.Exception as E (bracket, catch, SomeException) import Data.Maybe import Data.Map (Map) import qualified Data.Map as Map import Foreign.C -import Foreign.Marshal +import Foreign.Marshal hiding (void) import Foreign.Ptr import Foreign.Storable -import System.Directory import System.IO import System.IO.Error #if __GLASGOW_HASKELL__ >= 612 @@ -56,6 +54,7 @@ import GHC.IO.Device (IODeviceType(Stream)) import GHC.Handle import System.Posix.Internals #endif +import System.Posix.Files import System.INotify.Masks @@ -187,16 +186,13 @@ initINotify = do addWatch :: INotify -> [EventVariety] -> FilePath -> (Event -> IO ()) -> IO WatchDescriptor addWatch inotify@(INotify _ fd em _ _) masks fp cb = do - is_dir <- doesDirectoryExist fp - when (not is_dir) $ do - file_exist <- doesFileExist fp - when (not file_exist) $ do - -- it's not a directory, and not a file... - -- it doesn't exist - ioError $ mkIOError doesNotExistErrorType - "can't watch what isn't there" - Nothing - (Just fp) + catch_IO (void $ + (if (NoSymlink `elem` masks) then getSymbolicLinkStatus else getFileStatus) + fp) $ \_ -> + ioError $ mkIOError doesNotExistErrorType + "can't watch what isn't there!" + Nothing + (Just fp) let mask = joinMasks (map eventVarietyToMask masks) wd <- withCString fp $ \fp_c -> throwErrnoIfMinus1 "addWatch" $ @@ -213,6 +209,9 @@ addWatch inotify@(INotify _ fd em _ _) masks fp cb = do modifyMVar_ em $ \em' -> return (Map.insert wd event em') return (WatchDescriptor inotify wd) where + -- catch_IO is same as catchIOError from base >= 4.5.0.0 + catch_IO :: IO a -> (IOError -> IO a) -> IO a + catch_IO = E.catch eventVarietyToMask ev = case ev of Access -> inAccess @@ -313,13 +312,15 @@ inotify_start_thread h em = do runHandler (_, e@QOverflow) = do -- send overflows to all handlers handlers <- readMVar em flip mapM_ (Map.elems handlers) $ \handler -> - catch (handler e) (\_ -> return ()) -- supress errors + E.catch (handler e) ignore_failure -- supress errors runHandler (wd, event) = do handlers <- readMVar em let handlerM = Map.lookup wd handlers case handlerM of Nothing -> putStrLn "runHandler: couldn't find handler" -- impossible? - Just handler -> catch (handler event) (\_ -> return ()) + Just handler -> E.catch (handler event) ignore_failure + ignore_failure :: SomeException -> IO () + ignore_failure _ = return () killINotify :: INotify -> IO () killINotify (INotify h _ _ tid1 tid2) = diff --git a/src/System/INotify/Masks.hsc b/src/System/INotify/Masks.hsc index 5758851..339762f 100644 --- a/src/System/INotify/Masks.hsc +++ b/src/System/INotify/Masks.hsc @@ -44,7 +44,7 @@ data Mask maskIsSet :: Mask -> CUInt -> Bool maskIsSet mask cuint = value mask .&. cuint > 0 - + value :: Mask -> CUInt value (UserSpace i) = i value (Extra i) = i diff --git a/tests/test-all b/tests/test-all index 06b0dae..06b0dae 100644..100755 --- a/tests/test-all +++ b/tests/test-all |
