From 94d9ada714b2af81cf91b9e7bdcbe2107fc8d68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 10 Nov 2024 15:06:26 +0100 Subject: [PATCH] fix #12771 --- cli/processexecutor.cpp | 22 ++++++++++++++++------ lib/filesettings.h | 4 ++++ lib/importproject.cpp | 25 +++++++++++++++++++++++++ lib/importproject.h | 1 + 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index c242eb426f8c..1f27664dc0b4 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -234,9 +234,12 @@ unsigned int ProcessExecutor::check() unsigned int fileCount = 0; unsigned int result = 0; - const std::size_t totalfilesize = std::accumulate(mFiles.cbegin(), mFiles.cend(), std::size_t(0), [](std::size_t v, const FileWithDetails& p) { - return v + p.size(); + std::size_t totalfilesize = std::accumulate(mFileSettings.cbegin(), mFileSettings.cend(), std::size_t(0), [](std::size_t v, const FileSettings& fs) { + return v + fs.filesize(); }); + for (const auto &f : mFiles) { + totalfilesize += f.size(); + } std::list rpipes; std::map childFile; @@ -331,11 +334,18 @@ unsigned int ProcessExecutor::check() std::size_t size = 0; if (p != pipeFile.cend()) { pipeFile.erase(p); - const auto fs = std::find_if(mFiles.cbegin(), mFiles.cend(), [&name](const FileWithDetails& entry) { - return entry.path() == name; + const auto fs = std::find_if(mFileSettings.cbegin(), mFileSettings.cend(), [&name](const FileSettings& entry) { + return entry.filename() == name.substr(0, name.find(' ')); }); - if (fs != mFiles.end()) { - size = fs->size(); + if (fs == mFileSettings.cend()) { + const auto fwd = std::find_if(mFiles.cbegin(), mFiles.cend(), [&name](const FileWithDetails &entry) { + return entry.path() == name.substr(0, name.find(' ')); + }); + if (fwd != mFiles.cend()) { + size = fwd->size(); + } + } else { + size = fs->filesize(); } } diff --git a/lib/filesettings.h b/lib/filesettings.h index 75bf8faaa501..6e5d31c14706 100644 --- a/lib/filesettings.h +++ b/lib/filesettings.h @@ -86,6 +86,10 @@ struct CPPCHECKLIB FileSettings { { return file.spath(); } + std::size_t filesize() const + { + return file.size(); + } std::string defines; // TODO: handle differently std::string cppcheckDefines() const { diff --git a/lib/importproject.cpp b/lib/importproject.cpp index e44f7ad70f47..eeebd3899826 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -37,6 +37,9 @@ #include #include +#include +#include + #include "xml.h" #include "json.h" @@ -194,11 +197,13 @@ ImportProject::Type ImportProject::import(const std::string &filename, Settings if (endsWith(filename, ".json")) { if (importCompileCommands(fin)) { setRelativePaths(filename); + setFileSizes(); return ImportProject::Type::COMPILE_DB; } } else if (endsWith(filename, ".sln")) { if (importSln(fin, mPath, fileFilters)) { setRelativePaths(filename); + setFileSizes(); return ImportProject::Type::VS_SLN; } } else if (endsWith(filename, ".vcxproj")) { @@ -206,16 +211,19 @@ ImportProject::Type ImportProject::import(const std::string &filename, Settings std::vector sharedItemsProjects; if (importVcxproj(filename, variables, emptyString, fileFilters, sharedItemsProjects)) { setRelativePaths(filename); + setFileSizes(); return ImportProject::Type::VS_VCXPROJ; } } else if (endsWith(filename, ".bpr")) { if (importBcb6Prj(filename)) { setRelativePaths(filename); + setFileSizes(); return ImportProject::Type::BORLAND; } } else if (settings && endsWith(filename, ".cppcheck")) { if (importCppcheckGuiProject(fin, settings)) { setRelativePaths(filename); + setFileSizes(); return ImportProject::Type::CPPCHECK_GUI; } } else { @@ -1497,3 +1505,20 @@ bool ImportProject::sourceFileExists(const std::string &file) { return Path::isFile(file); } + +void ImportProject::setFileSizes() +{ + for (auto &fs : fileSettings) { + int statResult; +#ifdef _WIN32 + struct _stat statBuf; + statResult = _stat(fs.filename().c_str(), &statBuf); +#else + struct stat statBuf; + statResult = stat(fs.filename().c_str(), &statBuf); +#endif + if (statResult == 0) { + fs.file = FileWithDetails(fs.file.path(), statBuf.st_size); + } + } +} diff --git a/lib/importproject.h b/lib/importproject.h index 8c4c171e38c2..1dce2534032f 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -117,6 +117,7 @@ class CPPCHECKLIB WARN_UNUSED ImportProject { static void printError(const std::string &message); void setRelativePaths(const std::string &filename); + void setFileSizes(); std::string mPath; std::set mAllVSConfigs;