diff --git a/src/Bundle.cpp b/src/Bundle.cpp index d20adc4..d46156b 100644 --- a/src/Bundle.cpp +++ b/src/Bundle.cpp @@ -455,15 +455,40 @@ const std::string& Bundle::getDataDirectory() return selectedBundle().dataDir; } + +template +void split(const std::string &s, char delim, Out result) { + std::istringstream iss(s); + std::string item; + while (std::getline(iss, item, delim)) { + *result++ = item; + } +} + +std::vector split(const std::string &s, char delim) { + std::vector elems; + split(s, delim, std::back_inserter(elems)); + return elems; +} + std::string Bundle::findFileByName(const std::string& relativePath) { + if (relativePath.empty()) + throw std::runtime_error("The path to the file is empty. relativePath = " + relativePath); + + LOG_DEBUG_S << "relativePath = " << relativePath << std::endl; + // remove any arguments, e.g. from syscall template + std::vector split_str = split(relativePath, ' '); + const std::string& relPath = split_str.at(0); + LOG_DEBUG_S << "relPath = " << relPath << std::endl; for(const SingleBundle &bundle : activeBundles) { - fs::path curPath = fs::path(bundle.path) / relativePath; + fs::path curPath = fs::path(bundle.path) / relPath; + fs::path fullPath = fs::path(bundle.path) / relativePath; if(boost::filesystem::exists(curPath)) - return curPath.string(); + return fullPath.string(); } - throw std::runtime_error("Could not find file " + relativePath); + throw std::runtime_error("Could not find file. relativePath = " + relativePath + ", relPath = " + relPath); } std::vector Bundle::findFilesByName(const std::string& relativePath)