35 namespace sfs = std::filesystem;
38 if (!sfs::is_directory(p)) {
40 "The path given is not a directory: ") << db_dir;
52 std::vector<sfs::directory_entry> subdirs;
53 std::copy(sfs::directory_iterator(p),
54 sfs::directory_iterator(),
55 std::back_inserter(subdirs));
57 auto dir_iter = subdirs.begin();
58 while (dir_iter != subdirs.end()) {
59 const std::string archive_fulldir = dir_iter->path().string();
60 createArchivePlaceholderForExistingDatabase_(archive_fulldir);
70 void saveTo(
const std::string & dir);
80 void createArchivePlaceholderForExistingDatabase_(
81 const std::string & archive_fulldir)
83 std::vector<std::string> split;
84 boost::split(split, archive_fulldir, boost::is_any_of(
"/"));
85 const std::string archive_name = split.back();
86 archive_placeholder_dirs_[archive_name] = archive_fulldir;
95 std::vector<std::string> getLazyLoadedRootNames_()
const override {
96 std::vector<std::string> names;
97 names.reserve(archive_placeholder_dirs_.size());
98 for (
const auto & dir : archive_placeholder_dirs_) {
99 names.emplace_back(dir.first);
108 void onNamedRootRequest_(
const std::string & root_name)
override {
109 auto iter = archive_placeholder_dirs_.find(root_name);
110 if (iter != archive_placeholder_dirs_.end()) {
111 loadArchiveFspartaxistingDatabase_(iter->second);
112 archive_placeholder_dirs_.erase(iter);
117 void recursSetParentForChildNodes_(ArchiveNode * parent)
const {
118 for (
auto & child : parent->getChildren()) {
119 child->setParent(parent);
120 recursSetParentForChildNodes_(child.get());
127 void loadArchiveFspartaxistingDatabase_(
const std::string & archive_fulldir)
129 std::shared_ptr<RootArchiveNode> root(
new RootArchiveNode);
131 const std::string meta_filename = archive_fulldir +
"/archive_tree.bin";
132 std::ifstream fin(meta_filename, std::ios::binary);
134 throw SpartaException(
135 "Unable to open archive file for read: ") << meta_filename;
138 boost::archive::binary_iarchive ia(fin);
143 const std::string binary_filename = archive_fulldir +
"/values.bin";
144 root->setMetadataValue(
"output_filename", binary_filename);
149 std::shared_ptr<ArchiveController> controller(
150 new OfflineArchiveController(archive_fulldir));
151 root->setArchiveController(controller);
154 recursSetParentForChildNodes_(root.get());
161 std::vector<std::string> split;
162 boost::split(split, archive_fulldir, boost::is_any_of(
"/"));
163 const std::string archive_name = split.back();
167 std::unordered_map<std::string, std::string> archive_placeholder_dirs_;