syncqt: Catch fs exceptions that happen when clearing staging directory

Pick-to: 6.5
Change-Id: I1617f0940e1b1d892d321fc6f5df11262ee1f288
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit 9f3e7aaf17ba69a7cff81a584054978e6c283165)
This commit is contained in:
Alexey Edelev 2023-09-05 15:11:31 +02:00
parent 606839a1f9
commit 880da41adb

View File

@ -140,6 +140,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;
@ -740,12 +746,13 @@ public:
return false;
if (outDirExists && !skipCleanup) {
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.
// 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);
@ -761,6 +768,10 @@ public:
std::filesystem::remove(entry.path());
}
}
} catch (const std::filesystem::filesystem_error &fserr) {
utils::printFilesystemError(fserr, "Unable to clean the staging directory");
return false;
}
}
for (const auto &header : m_producedHeaders) {