ztail 1.2.0.1 → 1.2.0.2
raw patch · 4 files changed
+34/−24 lines, 4 filesdep ~hinotifydep ~time
Dependency ranges changed: hinotify, time
Files
- Main.hs +7/−7
- TailHandle.hs +23/−12
- TailTypes.hs +3/−3
- ztail.cabal +1/−2
Main.hs view
@@ -11,7 +11,7 @@ import qualified System.Console.GetOpt as Opt import System.Environment (getArgs) import System.Exit (ExitCode(..), exitSuccess, exitFailure, exitWith)-#ifdef INOTIFY+#ifdef VERSION_hinotify import qualified System.INotify as INotify #endif import System.IO.Error (ioeGetErrorType)@@ -34,7 +34,7 @@ { tailTarg = undefined -- read "-" , tailPollInterval = 5 , tailReopenInterval = 0-#ifdef INOTIFY+#ifdef VERSION_hinotify , tailPollINotify = True , tailReopenINotify = False #endif@@ -82,7 +82,7 @@ [ Opt.Option "i" ["interval"] (Opt.ReqArg (\i -> set_opt $ \p -> p { tailPollInterval = read i-#ifdef INOTIFY+#ifdef VERSION_hinotify , tailPollINotify = False #endif }) "INT")@@ -90,12 +90,12 @@ , Opt.Option "r" ["reopen"] (Opt.OptArg (\i -> set_opt $ \p -> p { tailReopenInterval = maybe (tailPollInterval p) read i-#ifdef INOTIFY+#ifdef VERSION_hinotify , tailReopenINotify = False #endif }) "INT") ("*check file name (like tail -F) every INT seconds or every poll [" ++ show (tailReopenInterval defaultTail) ++ "]")-#ifdef INOTIFY+#ifdef VERSION_hinotify , Opt.Option "I" ["inotify"] (Opt.OptArg (\i -> set_opt $ \p -> p { tailPollINotify = True@@ -185,7 +185,7 @@ emv <- newEmptyMVar count <- newIORef (length tails) errors <- newIORef False-#ifdef INOTIFY+#ifdef VERSION_hinotify inotify <- catchWhen ((UnsupportedOperation ==) . ioeGetErrorType) (Just <$> INotify.initINotify) @@ -203,7 +203,7 @@ tr = TailRuntime { trOutput = out , trAddTail = (atomicModifyIORef' count ((, ()) . succ) >>) . runt-#ifdef INOTIFY+#ifdef VERSION_hinotify , trINotify = inotify #endif }
TailHandle.hs view
@@ -19,7 +19,7 @@ import Foreign.Marshal.Alloc (allocaBytes) import Foreign.Ptr (Ptr, castPtr) import System.FilePath ((</>))-#ifdef INOTIFY+#ifdef VERSION_hinotify import qualified System.INotify as INotify #endif import System.IO.Error (isDoesNotExistError, isEOFError, isFullError)@@ -46,7 +46,7 @@ , thDirStream :: Maybe DirStream , thDirList :: Set.HashSet FilePath , thAgain :: Bool-#ifdef INOTIFY+#ifdef VERSION_hinotify , thPollWatch :: Maybe INotify.WatchDescriptor , thReopenWatch :: Maybe INotify.WatchDescriptor #endif@@ -74,7 +74,7 @@ closeTail :: TailHandle -> IO TailHandle closeTail th@TailHandle{ thFd = Nothing } = return th closeTail th@TailHandle{ thFd = Just fd } = do-#ifdef INOTIFY+#ifdef VERSION_hinotify mapM_ INotify.removeWatch (thPollWatch th) mapM_ INotify.removeWatch (thReopenWatch th) #endif@@ -83,7 +83,7 @@ { thFd = Nothing , thPos = 0 , thIno = Nothing-#ifdef INOTIFY+#ifdef VERSION_hinotify , thPollWatch = Nothing , thReopenWatch = Nothing #endif@@ -95,7 +95,7 @@ fdSeek fd AbsoluteSeek c $> th{ thPos = c } inotifyTail :: TailHandle -> IO TailHandle-#ifdef INOTIFY+#ifdef VERSION_hinotify inotifyTail th@TailHandle { thRuntime = TailRuntime{ trINotify = Just inotify } , thPoll = tid@@ -107,15 +107,26 @@ } } = do let sig (INotify.Modified {}) = Just SignalPoll sig (INotify.MovedSelf {}) = Just SignalReopen- sig (INotify.MovedOut { INotify.filePath = f }) | notdot f = Just $ SignalDelete f- sig (INotify.MovedIn { INotify.filePath = f }) | notdot f = Just $ SignalInsert f False- sig (INotify.Created { INotify.filePath = f }) | notdot f = Just $ SignalInsert f True- sig (INotify.Deleted { INotify.filePath = f }) | notdot f = Just $ SignalDelete f+ sig (INotify.MovedOut { INotify.filePath = f }) | notdot f = Just $ SignalDelete (fp f)+ sig (INotify.MovedIn { INotify.filePath = f }) | notdot f = Just $ SignalInsert (fp f) False+ sig (INotify.Created { INotify.filePath = f }) | notdot f = Just $ SignalInsert (fp f) True+ sig (INotify.Deleted { INotify.filePath = f }) | notdot f = Just $ SignalDelete (fp f) sig _ = Nothing+#if MIN_VERSION_hinotify(0,3,10)+ fp = BS.unpack+ notdot = maybe False (('.' /=) . fst) . BS.uncons +#else+ fp = id notdot "" = False notdot ('.':_) = False notdot _ = True- add l = INotify.addWatch inotify l path (mapM_ (throwTo tid) . sig)+#endif+ add l = INotify.addWatch inotify l (+#if MIN_VERSION_hinotify(0,3,10)+ BS.pack+#endif+ path+ ) (mapM_ (throwTo tid) . sig) poll <- justWhen (ipoll && pos >= 0) $ if isJust (thDirStream th) then add [INotify.OnlyDir, INotify.Move, INotify.Create, INotify.Delete]@@ -287,7 +298,7 @@ , thDirStream = Nothing , thDirList = Set.empty , thAgain = True-#ifdef INOTIFY+#ifdef VERSION_hinotify , thPollWatch = Nothing , thReopenWatch = Nothing #endif@@ -317,7 +328,7 @@ && (thFd th == Nothing || (thAgain th == False && thPos th /= -1 && tailPollInterval (thTail th) == 0-#ifdef INOTIFY+#ifdef VERSION_hinotify && thPollWatch th == Nothing && thReopenWatch th == Nothing #endif
TailTypes.hs view
@@ -18,7 +18,7 @@ import qualified Data.ByteString.Char8 as BS import qualified Data.Fixed as Fixed import Data.Monoid ((<>))-#ifdef INOTIFY+#ifdef VERSION_hinotify import qualified System.INotify as INotify #endif import System.Posix.Types (Fd)@@ -83,7 +83,7 @@ { tailTarg :: TailTarget , tailPollInterval :: !Interval , tailReopenInterval :: !Interval-#ifdef INOTIFY+#ifdef VERSION_hinotify , tailPollINotify :: !Bool , tailReopenINotify :: !Bool #endif@@ -102,7 +102,7 @@ data TailRuntime = TailRuntime { trOutput :: Output -> IO () , trAddTail :: Tail -> IO ()-#ifdef INOTIFY+#ifdef VERSION_hinotify , trINotify :: Maybe INotify.INotify #endif }
ztail.cabal view
@@ -1,5 +1,5 @@ Name: ztail-Version: 1.2.0.1+Version: 1.2.0.2 Author: Dylan Simon Maintainer: dylan@dylex.net License: BSD3@@ -37,4 +37,3 @@ unordered-containers == 0.2.* if flag(inotify) Build-Depends: hinotify >= 0.3.6 && < 0.4- CPP-Options: -DINOTIFY