summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-03-07 12:12:31 (GMT)
committerKitware Robot <kwrobot@kitware.com>2018-03-07 12:12:50 (GMT)
commita6f1eabee0f6c7572f1fd3cfa8ec973deb21897e (patch)
treeb04bc09db5a7d2ead6011988109ff40c5a7d155e /Source
parent4f29bf56724aa8a71ce85b540f6b620454692ade (diff)
parent50b7be6d1f2022483cb75a5347a1e1a70a2994e0 (diff)
downloadCMake-a6f1eabee0f6c7572f1fd3cfa8ec973deb21897e.zip
CMake-a6f1eabee0f6c7572f1fd3cfa8ec973deb21897e.tar.gz
CMake-a6f1eabee0f6c7572f1fd3cfa8ec973deb21897e.tar.bz2
Merge topic 'autogen-empty-source-file-fix'
50b7be6d1f Autogen: Check if a file is empty before reading it Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1825
Diffstat (limited to 'Source')
-rw-r--r--Source/cmQtAutoGenerator.cxx29
1 files changed, 18 insertions, 11 deletions
diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx
index 5b2b6d0..1939bd4 100644
--- a/Source/cmQtAutoGenerator.cxx
+++ b/Source/cmQtAutoGenerator.cxx
@@ -190,25 +190,32 @@ bool cmQtAutoGenerator::FileSystem::FileRead(std::string& content,
bool success = false;
{
std::lock_guard<std::mutex> lock(Mutex_);
- if (cmSystemTools::FileExists(filename)) {
+ if (cmSystemTools::FileExists(filename, true)) {
std::size_t const length = cmSystemTools::FileLength(filename);
cmsys::ifstream ifs(filename.c_str(), (std::ios::in | std::ios::binary));
if (ifs) {
- content.resize(length);
- ifs.read(&content.front(), content.size());
- if (ifs) {
- success = true;
+ if (length > 0) {
+ content.resize(length);
+ ifs.read(&content.front(), content.size());
+ if (ifs) {
+ success = true;
+ } else {
+ content.clear();
+ if (error != nullptr) {
+ error->append("Reading from the file failed.");
+ }
+ }
} else {
+ // Readable but empty file
content.clear();
- if (error != nullptr) {
- error->append("Reading from the file failed.");
- }
+ success = true;
}
} else if (error != nullptr) {
error->append("Opening the file for reading failed.");
}
} else if (error != nullptr) {
- error->append("The file does not exist.");
+ error->append(
+ "The file does not exist, is not readable or is a directory.");
}
}
return success;
@@ -539,8 +546,8 @@ void cmQtAutoGenerator::ReadOnlyProcessT::UVExit(uv_process_t* handle,
void cmQtAutoGenerator::ReadOnlyProcessT::UVTryFinish()
{
// There still might be data in the pipes after the process has finished.
- // Therefore check if the process is finished AND all pipes are closed before
- // signaling the worker thread to continue.
+ // Therefore check if the process is finished AND all pipes are closed
+ // before signaling the worker thread to continue.
if (UVProcess_.get() == nullptr) {
if (UVPipeOut_.uv_pipe() == nullptr) {
if (UVPipeErr_.uv_pipe() == nullptr) {