Skip to content

Commit

Permalink
fix #12771
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviggunne committed Nov 11, 2024
1 parent 31b8e7e commit 94d9ada
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
22 changes: 16 additions & 6 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> rpipes;
std::map<pid_t, std::string> childFile;
Expand Down Expand Up @@ -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();
}
}

Expand Down
4 changes: 4 additions & 0 deletions lib/filesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <unordered_set>
#include <utility>

#include <sys/types.h>
#include <sys/stat.h>

#include "xml.h"

#include "json.h"
Expand Down Expand Up @@ -194,28 +197,33 @@ 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")) {
std::map<std::string, std::string, cppcheck::stricmp> variables;
std::vector<SharedItemsProject> 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 {
Expand Down Expand Up @@ -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);
}
}
}
1 change: 1 addition & 0 deletions lib/importproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> mAllVSConfigs;
Expand Down

0 comments on commit 94d9ada

Please sign in to comment.