]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Storage/Impl.hs
Wrote many...
[Rakka.git] / Rakka / Storage / Impl.hs
index dd8b7c4c504f8ad40195334b8dbd3caa7eec86bb..5db3f9257b0297e2d99d0e6c38677db7fdebd46f 100644 (file)
@@ -66,12 +66,22 @@ startIndexManager lsdir repos mkDraft
       loop chan index
           = do req <- atomically $ readTChan chan
                case req of
+                 RebuildIndex
+                     -> do noticeM logger "Rebuilding the H.E. index..."
+                           closeDatabase index
+                           removeDirectoryRecursive indexDir
+                           index' <- openIndex indexDir revFile
+                           syncIndex' index' revFile repos mkDraft
+                           loop chan index'
+
                  SyncIndex
-                     -> syncIndex' index revFile repos mkDraft
+                     -> do syncIndex' index revFile repos mkDraft
+                           loop chan index
+
                  SearchIndex cond var
                      -> do result <- searchIndex index cond
                            atomically $ putTMVar var result
-               loop chan index
+                           loop chan index
 
 
 -- casket を R/W モードで開く。成功したらそのまま返し、失敗したら
@@ -85,8 +95,8 @@ openIndex indexDir revFile
                      return index
 
            Left err
-               -> do warningM logger ("Failed to open an H.E. index on "
-                                      ++ indexDir ++ ": " ++ show err)
+               -> do noticeM logger ("Failed to open an H.E. index on "
+                                     ++ indexDir ++ ": " ++ show err)
 
                      indexExists <- doesDirectoryExist indexDir
                      when indexExists
@@ -112,7 +122,8 @@ syncIndex' index revFile repos mkDraft
          newRev <- getCurrentRevNum repos
          debugM logger ("The repository revision is currently " ++ show newRev)
 
-         when (newRev /= oldRev) (syncIndex'' oldRev newRev)
+         when (oldRev == 0 || newRev /= oldRev)
+              $ syncIndex'' oldRev newRev
          return newRev
     where
       syncIndex'' :: RevNum -> RevNum -> IO ()