syncqt: Catch fs exceptions that happen when clearing staging directory

Pick-to: 6.5 6.6
Change-Id: I1617f0940e1b1d892d321fc6f5df11262ee1f288
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2023-09-05 15:11:31 +02:00
parent a86fb92d4b
commit 9f3e7aaf17

View File

@ -141,6 +141,12 @@ std::filesystem::path normilizedPath(const std::string &path)
return std::filesystem::path(std::filesystem::weakly_canonical(path).generic_string());
}
void printFilesystemError(const std::filesystem::filesystem_error &fserr, std::string_view errorMsg)
{
std::cerr << errorMsg << ": " << fserr.path1() << ".\n"
<< fserr.what() << "(" << fserr.code().value() << ")" << std::endl;
}
bool createDirectories(const std::string &path, std::string_view errorMsg, bool *exists = nullptr)
{
bool result = true;
@ -776,26 +782,31 @@ public:
return false;
if (outDirExists && !skipCleanup) {
for (const auto &entry :
std::filesystem::recursive_directory_iterator(outputDirectory)) {
if (m_producedHeaders.find(entry.path().filename().generic_string())
== m_producedHeaders.end()) {
// Check if header file came from another module as result of the cross-module
// deprecation before removing it.
std::string firstLine;
{
std::ifstream input(entry.path(), std::ifstream::in);
if (input.is_open()) {
std::getline(input, firstLine);
input.close();
try {
for (const auto &entry :
std::filesystem::recursive_directory_iterator(outputDirectory)) {
if (m_producedHeaders.find(entry.path().filename().generic_string())
== m_producedHeaders.end()) {
// Check if header file came from another module as result of the
// cross-module deprecation before removing it.
std::string firstLine;
{
std::ifstream input(entry.path(), std::ifstream::in);
if (input.is_open()) {
std::getline(input, firstLine);
input.close();
}
}
if (firstLine.find("#ifndef DEPRECATED_HEADER_"
+ m_commandLineArgs->moduleName())
== 0
|| firstLine.find("#ifndef DEPRECATED_HEADER_") != 0)
std::filesystem::remove(entry.path());
}
if (firstLine.find("#ifndef DEPRECATED_HEADER_"
+ m_commandLineArgs->moduleName())
== 0
|| firstLine.find("#ifndef DEPRECATED_HEADER_") != 0)
std::filesystem::remove(entry.path());
}
} catch (const std::filesystem::filesystem_error &fserr) {
utils::printFilesystemError(fserr, "Unable to clean the staging directory");
return false;
}
}