OSDN Git Service

Idx cache can deal with deleting idx files.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 30 Jun 2009 12:44:06 +0000 (21:44 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 30 Jun 2009 12:44:06 +0000 (21:44 +0900)
src/thread_idx_cache.cxx
src/thread_idx_cache.hxx

index d2be297..9dea8e5 100644 (file)
@@ -132,11 +132,13 @@ boost::unordered_set<ThreadIdxCache::ThreadID> ThreadIdxCache::get_exist_ids(
 
 std::vector<ThreadIdxCache::ThreadID> ThreadIdxCache::get_deleted_ids(
     const boost::unordered_map<ThreadID, ThreadIdxCache>& caches,
-    const boost::unordered_set<ThreadID>& exist_ids) {
+    const boost::unordered_set<ThreadID>& exist_ids,
+    const std::string& prefix) {
   typedef std::pair<ThreadID, ThreadIdxCache> PairType;
   std::vector<ThreadID> deleted_ids;
   BOOST_FOREACH(const PairType& pair, caches) {
     const std::string& cached = pair.first;
+    if (prefix != cached.substr(0, 3)) continue;
     if (exist_ids.find(cached) == exist_ids.end())
       deleted_ids.push_back(cached);
   }
@@ -208,10 +210,9 @@ void ThreadIdxCache::idx_dir_scan(const boost::filesystem::path& idx_dir,
       directories[filename] = last_modified;
 
       const boost::unordered_set<ThreadID> exist_ids = get_exist_ids(sub_dir);
-      // TODO remove deleted ids.
-//      const std::vector<ThreadID> deleted_ids =
-//        get_deleted_ids(caches, exist_ids);
-//      remove_deleted_ids(caches, deleted_ids);
+      const std::vector<ThreadID> deleted_ids =
+        get_deleted_ids(caches, exist_ids, sub_dir.filename());
+      remove_deleted_ids(caches, deleted_ids);
       merge_idx(sub_dir, exist_ids, caches);
 
     }
index 94dc313..a666ec7 100644 (file)
@@ -73,7 +73,8 @@ private:
       const std::vector<ThreadID>& deleted_ids);
   static std::vector<ThreadID> get_deleted_ids(
       const boost::unordered_map<ThreadID, ThreadIdxCache>&,
-      const boost::unordered_set<ThreadID>& exist_ids);
+      const boost::unordered_set<ThreadID>& exist_ids,
+      const std::string& prefix);
   static boost::unordered_set<ThreadID> get_exist_ids(
         const boost::filesystem::path&);
   static std::vector<DirectoryTimeStamp> directory_timestamp_from_xml(