#include #include #include #include #include #include void ProjectList::LoadFrom(const std::string& path) { utils::filesystem::LockFile lock(path); std::lock_guard guard(lock); std::ifstream in(path); Project current; while (in >> current.root_project >> current.configuration_file) { projects_.push_back(current); } } std::optional ProjectList::GetCurrentProject() { auto current_path = std::filesystem::current_path(); std::optional result; auto UpdateResult = [&result](Project p) { if (!result.has_value()) { result = p; } else { result = std::max(p, result.value()); } }; for (auto& project : projects_) { auto prefix_current_path = current_path; if (project.root_project == "/") { UpdateResult(project); continue; } while (prefix_current_path != "/") { if (prefix_current_path == project.root_project) { UpdateResult(project); } prefix_current_path = prefix_current_path.parent_path(); } } return result; }