From 84dbb356ef36e60e78494be6acfeaf0728786e26 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Fri, 1 Sep 2023 17:19:10 +0200 Subject: [PATCH] syncqt: Close ifstream before attempt to remove file ifstream may block the file descriptor in some operating systems. Wrap the reading of files in staging directory with extra scope, to make sure that ifstream closed the descriptor before the removal attempt. Also make sure that we closed the ifstream explicitly. Change-Id: I56ef5e9925501912d5cd61e8545f664e0a0d90b8 Reviewed-by: Alexandru Croitor (cherry picked from commit 3115610cfa37b1341392039537299aea4a0b5d93) Reviewed-by: Qt Cherry-pick Bot --- src/tools/syncqt/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tools/syncqt/main.cpp b/src/tools/syncqt/main.cpp index 3f5fe500256..8d6709f9816 100644 --- a/src/tools/syncqt/main.cpp +++ b/src/tools/syncqt/main.cpp @@ -740,9 +740,14 @@ public: == m_producedHeaders.end()) { // Check if header file came from another module as result of the cross-module // deprecation before removing it. - std::ifstream input(entry.path(), std::ifstream::in); std::string firstLine; - std::getline(input, 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