OSDN Git Service

divide idx to sub directories for preventing from scanning all files.
[fukui-no-namari/dialektos.git] / src / thread_idx.cxx
index c35a22f..d9f09c8 100644 (file)
@@ -29,6 +29,7 @@
 #include <fstream>
 #include <string>
 #include <iostream>
+#include "misc.hxx"
 
 
 namespace dialektos {
@@ -36,7 +37,12 @@ namespace dialektos {
 ThreadIdx::ThreadIdx() : title_(), line_count_(0), last_modified_(), etag_()
 {}
 
-void ThreadIdx::to_xml(const boost::filesystem::path& xml) {
+void ThreadIdx::to_xml(const boost::filesystem::path& _xml) {
+  const std::string prefix = _xml.filename().substr(0, 3);
+  const boost::filesystem::path xml =
+    _xml.parent_path() / prefix / _xml.filename();
+
+  if (!misc::create_directories(xml.parent_path())) return;
   std::ofstream ofs(xml.file_string().c_str());
   try {
     boost::archive::xml_oarchive oa(ofs);
@@ -47,9 +53,13 @@ void ThreadIdx::to_xml(const boost::filesystem::path& xml) {
   ofs.close();
 }
 
-ThreadIdx ThreadIdx::from_xml(const boost::filesystem::path& xml) {
+ThreadIdx ThreadIdx::from_xml(const boost::filesystem::path& _xml) {
   ThreadIdx idx;
 
+  const std::string prefix = _xml.filename().substr(0, 3);
+  const boost::filesystem::path xml =
+    _xml.parent_path() / prefix / _xml.filename();
+
   if (!boost::filesystem::exists(xml) ||
       !boost::filesystem::is_regular_file(xml))
     return idx;