follow-file 0.0.1.1 → 0.0.1.2
raw patch · 2 files changed
+24/−10 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- follow-file.cabal +4/−1
- src/System/File/Follow.hs +20/−9
follow-file.cabal view
@@ -1,5 +1,5 @@ Name: follow-file-Version: 0.0.1.1+Version: 0.0.1.2 Author: Athan Clark <athan.clark@gmail.com> Maintainer: Athan Clark <athan.clark@gmail.com> License: BSD3@@ -18,10 +18,13 @@ GHC-Options: -Wall Exposed-Modules: System.File.Follow Build-Depends: base >= 4.8 && < 5+ , attoparsec+ , attoparsec-path , bytestring , directory , hinotify , path+ , text , unix , utf8-string , vector
src/System/File/Follow.hs view
@@ -11,6 +11,9 @@ import qualified Data.ByteString.Internal as BS import qualified Data.ByteString.UTF8 as BS8 import qualified Data.Vector as V+import qualified Data.Text as T+import Data.Attoparsec.Text (parseOnly, endOfInput)+import Data.Attoparsec.Path (relFilePath) import Control.Monad (when) import Control.Exception (bracket) import Path (Path, Abs, File, filename, parent, toFilePath, parseRelFile)@@ -55,12 +58,20 @@ stop = do writeIORef positionRef 0 f mempty- addWatch inotify [Modify, Create, Delete] (toFilePath $ parent file) $ \e -> case e of- Created {filePath} | parseRelFile filePath == Just (filename file) -> go- | otherwise -> pure ()- Deleted {filePath} | parseRelFile filePath == Just (filename file) -> stop- | otherwise -> pure ()- Modified {maybeFilePath} | ( maybeFilePath >>= parseRelFile- ) == Just (filename file) -> go- | otherwise -> pure ()- _ -> pure ()+ addWatch inotify [Modify, Create, Delete] (toFilePath $ parent file) $ \e ->+ let isFile filePath = parseOnly (relFilePath <* endOfInput) (T.pack filePath) == Right (filename file)+ in case e of+ Created {filePath} | isFile filePath -> go+ | otherwise -> pure ()+ Deleted {filePath} | isFile filePath -> stop+ | otherwise -> pure ()+ Modified {maybeFilePath} | (isFile <$> maybeFilePath) == Just True -> go+ | otherwise -> pure ()+ MovedIn {filePath} | isFile filePath -> go+ | otherwise -> pure ()+ MovedOut {filePath} | isFile filePath -> go+ | otherwise -> pure ()+ DeletedSelf -> error "containing folder deleted"+ Unmounted -> error "containing folder unmounted"+ QOverflow -> error "queue overflow"+ _ -> pure ()