tailfile-hinotify 1.0.0.3 → 2.0.0.0
raw patch · 6 files changed
+72/−57 lines, 6 filesdep +pipes-transducedep +textdep ~asyncdep ~foldldep ~hinotifyPVP ok
version bump matches the API change (PVP)
Dependencies added: pipes-transduce, text
Dependency ranges changed: async, foldl, hinotify, pipes, streaming, streaming-eversion
API changes (from Hackage documentation)
Files
- ChangeLog.md +7/−0
- lib/System/IO/TailFile.hs +22/−19
- lib/System/IO/TailFile/Foldl.hs +5/−4
- lib/System/IO/TailFile/Pipes.hs +6/−6
- lib/System/IO/TailFile/Streaming.hs +6/−6
- tailfile-hinotify.cabal +26/−22
ChangeLog.md view
@@ -0,0 +1,7 @@+# Changelog++## 2.0.0.0++- Pull request #4 by @ocharles: Compatibility with versions of hinotify >=+ 0.3.10 that changed the filepath representation.+
lib/System/IO/TailFile.hs view
@@ -1,4 +1,4 @@-{-| Tail files in Linux. +{-| Tail files in Linux. The functions in this module do not use any particular streaming library. They just accept an initial state and a monadic update function.@@ -9,14 +9,17 @@ {-# language BangPatterns #-} module System.IO.TailFile (tailFile) where -import Data.Foldable-import Data.Monoid-import qualified Data.ByteString-import Data.ByteString.Lazy.Internal (defaultChunkSize) import Control.Concurrent (threadDelay) import Control.Concurrent.MVar-import Control.Monad import Control.Exception+import Control.Monad+import qualified Data.ByteString+import Data.ByteString (ByteString)+import Data.ByteString.Lazy.Internal (defaultChunkSize)+import Data.Foldable+import Data.Monoid+import qualified Data.Text+import qualified Data.Text.Encoding import System.INotify import System.IO (withFile ,IOMode(ReadMode)@@ -26,7 +29,7 @@ import System.IO.Error (isDoesNotExistError) {-| Tail a file, while keeping an internal state.- + If the file doesn't exist, `tailFile` will poll for it until it is found. If `tailFile` detects the file has been moved or renamed, it goes back to@@ -37,27 +40,27 @@ Data already existing in the file before `tailFile` is invoked is ignored. -}-tailFile :: FilePath +tailFile :: FilePath -> (a -> Data.ByteString.ByteString -> IO a) -- ^ State update function. -> IO a -- ^ Monadic action for getting the initial state. -> IO void -- ^ The result action never returns!-tailFile filepath callback initial = withINotify (\i -> +tailFile filepath callback initial = withINotify (\i -> do state <- initial loop i state) where loop i = let go pristine a = do ea' <- tryJust (guard . isDoesNotExistError) (watchFile pristine i a)- case ea' of + case ea' of Left () -> do threadDelay 5e5 go False a -- reuse the state Right a' -> go False a' in go True- watchFile pristine i a = + watchFile pristine i a = do sem <- newMVar mempty- bracket (addWatch i - [Modify,MoveSelf,DeleteSelf] - filepath + bracket (addWatch i+ [Modify,MoveSelf,DeleteSelf]+ (Data.Text.Encoding.encodeUtf8 (Data.Text.pack filepath)) (\event -> let stop = Any (case event of MovedSelf {} -> True Deleted {} -> True@@ -66,20 +69,20 @@ new <- evaluate $ old <> stop putMVar sem new)) removeWatch- (\_ -> withFile filepath ReadMode (\h -> - do when pristine + (\_ -> withFile filepath ReadMode (\h ->+ do when pristine (hSeek h SeekFromEnd 0) sleeper sem h a)) sleeper sem h = let go ms a = do event <- takeMVar sem- size' <- hFileSize h - for_ ms (\size -> when (size' < size) -- truncation + size' <- hFileSize h+ for_ ms (\size -> when (size' < size) -- truncation (hSeek h AbsoluteSeek 0)) !a' <- drainBytes h a if getAny event then return a' else go (Just size') a' in go Nothing- drainBytes h = + drainBytes h = let go a = do c <- Data.ByteString.hGetSome h defaultChunkSize if Data.ByteString.null c then do return a
lib/System/IO/TailFile/Foldl.hs view
@@ -1,15 +1,16 @@-{-| Tail files in Unix, using folds form the @foldl@ package. +{-| Tail files in Unix, using folds form the @foldl@ package. -} module System.IO.TailFile.Foldl where -import qualified Data.ByteString+import Data.ByteString (ByteString) import qualified Control.Foldl as L import qualified System.IO.TailFile {-| Like 'System.IO.TailFile.tailFile', but it takes a 'L.FoldM'.- + The @done@ part of the fold is never invoked. -}-tailFile :: FilePath -> L.FoldM IO Data.ByteString.ByteString void -> IO void+tailFile :: FilePath+ -> L.FoldM IO Data.ByteString.ByteString void -> IO void tailFile path = L.impurely (\step initial _ -> System.IO.TailFile.tailFile path step initial)
lib/System/IO/TailFile/Pipes.hs view
@@ -1,18 +1,18 @@-{-| Tail files in Unix, using types from the @pipes@ package. +{-| Tail files in Unix, using types from the @pipes@ package. -} {-# language RankNTypes #-} module System.IO.TailFile.Pipes where -import qualified Data.ByteString-import Pipes-import Streaming.Eversion.Pipes+import Data.ByteString (ByteString)+import Pipes+import Streaming.Eversion.Pipes import qualified System.IO.TailFile.Foldl {-| Tail a file with a function that consumes a 'Producer'. -}-tailFile :: FilePath -- ^ +tailFile :: FilePath -> (forall t r. (MonadTrans t, MonadIO (t IO)) => Producer Data.ByteString.ByteString (t IO) r -> t IO (void, r)) -- ^ Scary type, but any resonably polymorphic (say, over 'MonadIO') function that consumes a 'Producer' can go here. -> IO void-tailFile path consumer = System.IO.TailFile.Foldl.tailFile path (evertMIO consumer) +tailFile path consumer = System.IO.TailFile.Foldl.tailFile path (evertMIO consumer)
lib/System/IO/TailFile/Streaming.hs view
@@ -1,17 +1,17 @@-{-| Tail files in Unix, using types from the @streraming@ package. +{-| Tail files in Unix, using types from the @streraming@ package. -} {-# language RankNTypes #-} module System.IO.TailFile.Streaming where -import qualified Data.ByteString-import Streaming-import Streaming.Eversion+import Data.ByteString (ByteString)+import Streaming+import Streaming.Eversion import qualified System.IO.TailFile.Foldl {-| Tail a file with a function that consumes a 'Stream'. -}-tailFile :: FilePath -- ^ +tailFile :: FilePath -> (forall t r. (MonadTrans t, MonadIO (t IO)) => Stream (Of Data.ByteString.ByteString) (t IO) r -> t IO (Of void r)) -- ^ Scary type, but any resonably polymorphic (say, over 'MonadIO') function that consumes a 'Stream' can go here. -> IO void-tailFile path consumer = System.IO.TailFile.Foldl.tailFile path (evertMIO consumer) +tailFile path consumer = System.IO.TailFile.Foldl.tailFile path (evertMIO consumer)
tailfile-hinotify.cabal view
@@ -1,7 +1,7 @@ name: tailfile-hinotify-version: 1.0.0.3-synopsis: Tail files in Unix, using hinotify. -description: Tail files in Unix, using hinotify. +version: 2.0.0.0+synopsis: Tail files in Unix, using hinotify.+description: Tail files in Unix, using hinotify. license: MIT license-file: LICENSE author: Daniel Diaz@@ -20,20 +20,21 @@ location: https://github.com/danidiaz/tailfile-hinotify.git library- exposed-modules: + exposed-modules: System.IO.TailFile System.IO.TailFile.Foldl System.IO.TailFile.Streaming System.IO.TailFile.Pipes build-depends:- base >= 4.6 && < 5,- hinotify >= 0.3.9 && < 0.4,- bytestring >= 0.9.2.1 && <0.11,- async >= 2.0 && < 2.2,- foldl >= 1.1 && < 1.3,- streaming >= 0.1.4 && < 0.2,- pipes >= 4.3.0 && < 4.4,- streaming-eversion >= 0.3.1.0 && < 0.4+ base >= 4.6 && < 5,+ hinotify >= 0.3.10 && < 0.5,+ bytestring >= 0.9.2.1 && < 0.11,+ async >= 2.0 && < 2.3,+ foldl >= 1.4,+ streaming >= 0.1.4 && < 0.3,+ pipes >= 4.3.0 && < 4.4,+ streaming-eversion >= 0.3.1.0 && < 0.5,+ text hs-source-dirs: lib default-language: Haskell2010 ghc-options: -Wall@@ -42,24 +43,27 @@ type: exitcode-stdio-1.0 hs-source-dirs: tests, lib main-is: tests.hs- other-modules: + other-modules: System.IO.TailFile System.IO.TailFile.Foldl System.IO.TailFile.Streaming System.IO.TailFile.Pipes build-depends: base >= 4.6 && < 5,- hinotify >= 0.3.9 && < 0.4,- bytestring >= 0.9.2.1 && <0.11,- async >= 2.0 && < 2.2,- foldl >= 1.1 && < 1.3,- streaming >= 0.1.4 && < 0.2,- pipes >= 4.3.0 && < 4.4,- streaming-eversion >= 0.3.1.0 && < 0.4,- directory >= 1.3.0.0, + hinotify >= 0.3.10,+ bytestring >= 0.9.2.1 && < 0.11,+ async >= 2.0 && < 2.3,+ foldl >= 1.4,+ streaming >= 0.1.4 && < 0.3,+ pipes >= 4.3.0 && < 4.5,+ pipes-transduce >= 0.4.4,+ streaming-eversion >= 0.3.1.0 && < 0.5,+ directory >= 1.3.0.0, conceit >= 0.4.0.0, process-streaming >= 0.9.1.2, filepath >= 1.4.0.0, tasty >= 0.10.1.1,- tasty-hunit >= 0.9.2+ tasty-hunit >= 0.9.2,+ text default-language: Haskell2010+