packages feed

hobbes 0.2.1 → 0.2.2

raw patch · 2 files changed

+29/−30 lines, 2 filesdep +fsnotifydep +system-filepathdep +textdep −hfsevents

Dependencies added: fsnotify, system-filepath, text

Dependencies removed: hfsevents

Files

Hobbes.hs view
@@ -6,12 +6,14 @@ import System.FilePath.GlobPattern (GlobPattern, (~~)) import System.IO -import System.OSX.FSEvents+import Filesystem.Path.CurrentOS (fromText, encodeString) -import Control.Monad (forever, when)-import Control.Exception (bracket)+import System.FSNotify++import Control.Monad (forever) import Control.Concurrent (threadDelay) +import Data.Text (pack) import Data.Bits ((.&.))  @@ -31,28 +33,22 @@ runWatcher :: FilePath -> IO () runWatcher path =   let (dir, glob) = splitFileName path-  in bracket-       (eventStreamCreate [dir] 1.0 True True True (handleEvent glob))-       (\es -> eventStreamDestroy es >> hPutStrLn stderr "Bye!")-       (const $ forever $ threadDelay 1000000)+  in withManager $ \m -> do+       watchTree m (fromText $ pack dir) (globModified glob) printPath+       forever $ threadDelay 1000000 -handleEvent :: GlobPattern -> Event -> IO ()-handleEvent glob evt = -  let fn      = takeFileName $ eventPath evt-      isMatch = isFileChange evt && fileMatchesGlob glob fn -  in when isMatch $ putStrLn $ eventPath evt+globModified :: GlobPattern -> Event -> Bool+globModified glob evt@(Added _ _)    = matchesGlob glob evt+globModified glob evt@(Modified _ _) = matchesGlob glob evt+globModified _ (Removed _ _)     = False +matchesGlob :: GlobPattern -> Event -> Bool+matchesGlob glob = fileMatchesGlob glob . takeFileName . encodeString . eventPath++printPath :: Event -> IO ()+printPath = putStrLn . encodeString . eventPath + fileMatchesGlob :: GlobPattern -> FilePath -> Bool fileMatchesGlob []   _  = True fileMatchesGlob "."  _  = True fileMatchesGlob glob fp = fp ~~ glob--isFileChange :: Event -> Bool-isFileChange evt = not $ hasFlag eventFlagItemRemoved -                   && hasFlag eventFlagItemIsFile -                   && any hasFlag [ eventFlagItemModified-                                  , eventFlagItemRenamed-                                  , eventFlagItemCreated-                                  ]-  where flags = eventFlags evt-        hasFlag f = flags .&. f /= 0
hobbes.cabal view
@@ -1,21 +1,24 @@ name:                hobbes-version:             0.2.1+version:             0.2.2 synopsis:            A small file watcher for OSX--- description:         +-- description: homepage:            http://github.com/jhickner/hobbes license:             BSD3 license-file:        LICENSE author:              Jason Hickner maintainer:          jhickner@gmail.com--- copyright:           +-- copyright: category:            System build-type:          Simple cabal-version:       >=1.8  executable hobbes   main-is:             Hobbes.hs-  -- other-modules:       -  build-depends:       base >= 4 && < 5, -                       filepath ==1.3.*, -                       filemanip ==0.3.*, -                       hfsevents ==0.1.*+  -- other-modules:+  build-depends:       base >= 4 && < 5,+                       filepath ==1.3.*,+                       system-filepath >= 0.4.7,+                       filemanip ==0.3.*,+                       fsnotify >= 0.0.11,+                       text >= 1.1.0.1+