Added Hash to plist file names (#2898)

This commit is contained in:
Falital 2020-11-13 15:52:24 +01:00 committed by GitHub
parent c7f816f986
commit 2e2d4a0055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 2 deletions

View File

@ -576,6 +576,16 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
mSettings->plistOutput = "./";
else if (!endsWith(mSettings->plistOutput,'/'))
mSettings->plistOutput += '/';
const std::string plistOutput = Path::toNativeSeparators(mSettings->plistOutput);
if (!FileLister::isDirectory(plistOutput))
{
std::string message("cppcheck: error: plist folder does not exist: \"");
message += plistOutput;
message += "\".";
printMessage(message);
return false;
}
}
// --project

View File

@ -64,7 +64,7 @@ static BOOL myFileExists(const std::string& path)
if (fa != INVALID_FILE_ATTRIBUTES && !(fa & FILE_ATTRIBUTE_DIRECTORY))
result = TRUE;
#else
const BOOL result = PathFileExistsA(path.c_str());
const BOOL result = PathFileExistsA(path.c_str()) && !PathIsDirectoryA(path.c_str());
#endif
return result;
}

View File

@ -516,7 +516,8 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
filename2 = filename.substr(filename.rfind('/') + 1);
else
filename2 = filename;
filename2 = mSettings.plistOutput + filename2.substr(0, filename2.find('.')) + ".plist";
std::size_t fileNameHash = std::hash<std::string>{}(filename);
filename2 = mSettings.plistOutput + filename2.substr(0, filename2.find('.')) + "_" + std::to_string(fileNameHash) + ".plist";
plistFile.open(filename2);
plistFile << ErrorLogger::plistHeader(version(), files);
}

View File

@ -173,6 +173,11 @@ public:
*/
static std::string stripDirectoryPart(const std::string &file);
/**
* @brief Checks if a File exists
* @param path Path to be checked if it is a File
* @return true if given path is a File
*/
static bool fileExists(const std::string &file);
};

View File

@ -106,6 +106,8 @@ private:
TEST_CASE(stdc99);
TEST_CASE(stdcpp11);
TEST_CASE(platform);
TEST_CASE(plistEmpty);
TEST_CASE(plistDoesNotExist);
TEST_CASE(suppressionsOld); // TODO: Create and test real suppression file
TEST_CASE(suppressions);
TEST_CASE(suppressionsNoFile);
@ -717,6 +719,22 @@ private:
ASSERT(settings.platformType == Settings::Win64);
}
void plistEmpty() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--plist-output=", "file.cpp"};
settings.plistOutput = "";
ASSERT(defParser.parseFromArgs(3, argv));
ASSERT(settings.plistOutput == "./");
}
void plistDoesNotExist() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--plist-output=./cppcheck_reports", "file.cpp"};
settings.plistOutput = "";
// Fails since folder pointed by --plist-output= does not exist
ASSERT_EQUALS(false, defParser.parseFromArgs(3, argv));
}
void suppressionsOld() {
// TODO: Fails because there is no suppr.txt file!
REDIRECT;

View File

@ -47,6 +47,7 @@ private:
TEST_CASE(isDirectory);
TEST_CASE(recursiveAddFiles);
TEST_CASE(fileExists);
}
void isDirectory() const {
@ -79,6 +80,11 @@ private:
// Make sure headers are not added..
ASSERT(files.find("lib/tokenize.h") == files.end());
}
void fileExists() const {
ASSERT_EQUALS(false, FileLister::fileExists("lib"));
ASSERT_EQUALS(true, FileLister::fileExists("readme.txt"));
}
};
REGISTER_TEST(TestFileLister)