packages feed

tailfile-hinotify 1.0.0.2 → 1.0.0.3

raw patch · 3 files changed

+25/−39 lines, 3 filesdep +filepathPVP ok

version bump matches the API change (PVP)

Dependencies added: filepath

API changes (from Hackage documentation)

Files

lib/System/IO/TailFile.hs view
@@ -67,15 +67,14 @@                                               putMVar sem new))                    removeWatch                    (\_ -> withFile filepath ReadMode (\h -> -                              do if pristine then hSeek h SeekFromEnd 0-                                             else return ()+                              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 -> if size' < size -- truncation -                                           then hSeek h AbsoluteSeek 0-                                           else return ())+                         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'
tailfile-hinotify.cabal view
@@ -1,5 +1,5 @@ name:                tailfile-hinotify-version:             1.0.0.2+version:             1.0.0.3 synopsis:            Tail files in Unix, using hinotify.  description:         Tail files in Unix, using hinotify.  license:             MIT@@ -59,6 +59,7 @@                        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   default-language:    Haskell2010
tests/tests.hs view
@@ -17,6 +17,7 @@ import Test.Tasty.HUnit  import System.Directory+import System.FilePath((</>)) import System.IO import System.IO.Error import System.Process.Streaming@@ -26,28 +27,15 @@ main = defaultMain tests  tests :: TestTree-tests = testGroup "Tests" [ testCase "simple" testSimple+tests = testGroup "Tests" [ testCase "notExistingAtFirst" testNotExistingAtFirst                           , testCase "preexisting" testPreexisting                           , testCase "truncation" testTruncation                           , testCase "move" testMove-                          , testCase "notExistingAtFirst" testMove                           ] -testSimple :: IO ()-testSimple = -  do deleteFiles-     let content1 = "1 new content"-         content2 = "2 new content"-     bytes <- tailToIORef (\filepath -> -                              do catToFile filepath content1-                                 halfsec-                                 catToFile filepath content2)-                          filename1-     assertEqual "" (newlines [content1,content2]) bytes- testPreexisting :: IO () testPreexisting = -  do deleteFiles+  do (filename1,_) <- deleteFiles      Bytes.writeFile filename1 "previous content\n"      let content1 = "1 new content"          content2 = "2 new content"@@ -60,7 +48,7 @@  testTruncation :: IO () testTruncation = -  do deleteFiles+  do (filename1,_) <- deleteFiles      Bytes.writeFile filename1 "previous content\n"      let content1 = "1 new content"          content2 = "2 new content"@@ -75,7 +63,7 @@  testMove :: IO () testMove = -  do deleteFiles+  do (filename1,filename2) <- deleteFiles      let content1 = "1 new content"          content2 = "2 new content"      bytes <- tailToIORef (\filepath -> @@ -92,13 +80,11 @@  testNotExistingAtFirst :: IO () testNotExistingAtFirst = -  do deleteFiles+  do (filename1,_) <- deleteFiles      let content1 = "1 new content"          content2 = "2 new content"      bytes <- tailToIORef (\filepath -> -                              do halfsec-                                 halfsec-                                 catToFile filepath content1+                              do catToFile filepath content1                                  halfsec                                  catToFile filepath content2                                  halfsec@@ -119,26 +105,26 @@ halfsec :: IO () halfsec = threadDelay 5e5 -filename1 :: FilePath-filename1 = "/tmp/haskell_tailfile_test_1_387493423492347.txt"--filename2 :: FilePath-filename2 = "/tmp/haskell_tailfile_test_2_387493423492347.txt"- newlines :: [ByteString] -> ByteString newlines bs = mconcat . map (\b -> b <> "\n") $ bs -deleteFiles :: IO ()-deleteFiles = for_ [filename1,filename2]-                   (\filepath -> do _ <- tryJust (guard . isDoesNotExistError) -                                                 (removeFile filepath)-                                    pure ())+deleteFiles :: IO (FilePath,FilePath)+deleteFiles = do+    tmp <- getTemporaryDirectory  +    let (basename1,basename2) = ("haskell_tailfile_test_1_387493423492347.txt"+                                ,"haskell_tailfile_test_2_387493423492347.txt")+        (filename1,filename2) = (tmp </> basename1,tmp </> basename2)+    for_ [filename1,filename2]+         (\filepath -> do _ <- tryJust (guard . isDoesNotExistError) +                                       (removeFile filepath)+                          pure ())+    return (filename1,filename2)  tailToIORef :: (FilePath -> IO ()) -> FilePath -> IO Data.ByteString.ByteString tailToIORef writer filepath =   do ref <- newIORef mempty      let addToRef _ bytes = modifyIORef' ref (\b -> b <> bytes) -     runConceit (Conceit (Left <$> writer filepath)    +     runConceit (Conceit (Left <$> (halfsec *> halfsec *> writer filepath))                      *>                   _Conceit (tailFile filepath addToRef (pure ())))      readIORef ref