]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Storage/Impl.hs
Code cleanup
[Rakka.git] / Rakka / Storage / Impl.hs
index 442c412fb4966f906598155227c115dec48e75e2..bedc9eaa2808d3142e5d4abf91cd00d724369401 100644 (file)
@@ -12,6 +12,7 @@ module Rakka.Storage.Impl
 
 import           Control.Concurrent
 import           Control.Concurrent.STM
+import           Control.Exception
 import           Control.Monad
 import           Data.Maybe
 import           Data.Set (Set)
@@ -68,9 +69,7 @@ findAllPages repos rev = do reposPages   <- findAllPagesInRevision repos rev
 findChangedPages :: Repository -> RevNum -> RevNum -> IO (Set PageName)
 findChangedPages repos 0      newRev = findAllPages repos newRev
 findChangedPages repos oldRev newRev
-    = mapM (findChangedPagesAtRevision repos) [oldRev + 1 .. newRev]
-      >>=
-      return . S.unions
+    = liftM S.unions (mapM (findChangedPagesAtRevision repos) [oldRev + 1 .. newRev])
 
 
 getDirContents' :: Repository -> PageName -> Maybe RevNum -> IO [PageName]
@@ -109,7 +108,7 @@ startIndexManager :: FilePath -> Repository -> (Page -> IO Document) -> IO (TCha
 startIndexManager lsdir repos mkDraft
     = do chan  <- newTChanIO
          index <- openIndex indexDir revFile
-         forkIO (loop chan index)
+         _     <- forkIO (loop chan index `finally` closeDatabase index)
          return chan
     where
       indexDir = lsdir </> "index"
@@ -210,13 +209,11 @@ searchIndex index cond
       fromId words docId
           = do uri     <- getDocURI index docId
                rev     <- unsafeInterleaveIO $
-                          getDocAttr index docId "rakka:revision"
-                          >>=
-                          return . read . fromJust
+                          liftM (read . fromJust)
+                                (getDocAttr index docId "rakka:revision")
                lastMod <- unsafeInterleaveIO $
-                          getDocAttr index docId "@mdate"
-                          >>=
-                          return . zonedTimeToUTC . fromJust . parseW3CDateTime . fromJust
+                          liftM (zonedTimeToUTC . fromJust . parseW3CDateTime . fromJust)
+                                (getDocAttr index docId "@mdate")
                summary <- unsafeInterleaveIO $
                           getDocAttr index docId "rakka:summary"
                snippet <- unsafeInterleaveIO $
@@ -267,7 +264,7 @@ updateIndexRev revFile f = withFile revFile ReadWriteMode update
                     rev  <- if eof then
                                 return 0
                             else
-                                hGetLine h >>= return . read
+                                liftM read (hGetLine h)
                     rev' <- f rev
                     hSeek h AbsoluteSeek 0
                     hSetFileSize h 0