From e93354a846d4e9836bff75e93fe4d24540b2d6b6 Mon Sep 17 00:00:00 2001 From: rh5user Date: Thu, 4 Nov 2021 11:40:24 +0100 Subject: [PATCH 1/2] remove arguments from the path to check file existence --- src/Bundle.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Bundle.cpp b/src/Bundle.cpp index d20adc4..7d63208 100644 --- a/src/Bundle.cpp +++ b/src/Bundle.cpp @@ -455,15 +455,39 @@ 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; if(boost::filesystem::exists(curPath)) return curPath.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) From 2e16cae553ef892135d6bf5c084bcedac02c2fa9 Mon Sep 17 00:00:00 2001 From: rh5user Date: Thu, 4 Nov 2021 18:24:41 +0100 Subject: [PATCH 2/2] return the full path with argument --- src/Bundle.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Bundle.cpp b/src/Bundle.cpp index 7d63208..d46156b 100644 --- a/src/Bundle.cpp +++ b/src/Bundle.cpp @@ -484,8 +484,9 @@ std::string Bundle::findFileByName(const std::string& relativePath) for(const SingleBundle &bundle : activeBundles) { 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 = " + relativePath + ", relPath = " + relPath); }