From b8fb4b778cb99c593fd35f567cd6501568e8ea1a Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Mon, 1 Jul 2024 01:24:45 +0400 Subject: [PATCH] cmMakefile::ConfigureFile: Convert 'else' block to early return and deindent --- Source/cmMakefile.cxx | 108 +++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5a1c45f101..4fc33402b1 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4084,68 +4084,70 @@ int cmMakefile::ConfigureFile(const std::string& infile, if (!cmSystemTools::SetPermissions(soutfile, permissions)) { this->IssueMessage(MessageType::FATAL_ERROR, cmSystemTools::GetLastSystemError()); - return 0; + res = 0; } + return res; + } + + std::string newLineCharacters; + std::ios::openmode omode = std::ios::out | std::ios::trunc; + if (newLine.IsValid()) { + newLineCharacters = newLine.GetCharacters(); + omode |= std::ios::binary; } else { - std::string newLineCharacters; - std::ios::openmode omode = std::ios::out | std::ios::trunc; - if (newLine.IsValid()) { - newLineCharacters = newLine.GetCharacters(); - omode |= std::ios::binary; - } else { - newLineCharacters = "\n"; - } - std::string tempOutputFile = cmStrCat(soutfile, ".tmp"); - cmsys::ofstream fout(tempOutputFile.c_str(), omode); - if (!fout) { - cmSystemTools::Error("Could not open file for write in copy operation " + - tempOutputFile); - cmSystemTools::ReportLastSystemError(""); - return 0; - } - cmsys::ifstream fin(sinfile.c_str()); - if (!fin) { - cmSystemTools::Error("Could not open file for read in copy operation " + - sinfile); - return 0; - } + newLineCharacters = "\n"; + } + std::string tempOutputFile = cmStrCat(soutfile, ".tmp"); + cmsys::ofstream fout(tempOutputFile.c_str(), omode); + if (!fout) { + cmSystemTools::Error("Could not open file for write in copy operation " + + tempOutputFile); + cmSystemTools::ReportLastSystemError(""); + return 0; + } + cmsys::ifstream fin(sinfile.c_str()); + if (!fin) { + cmSystemTools::Error("Could not open file for read in copy operation " + + sinfile); + return 0; + } - cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin); - if (bom != cmsys::FStream::BOM_None && bom != cmsys::FStream::BOM_UTF8) { - this->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("File starts with a Byte-Order-Mark that is not UTF-8:\n ", - sinfile)); - return 0; - } - // rewind to copy BOM to output file - fin.seekg(0); + cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin); + if (bom != cmsys::FStream::BOM_None && bom != cmsys::FStream::BOM_UTF8) { + this->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("File starts with a Byte-Order-Mark that is not UTF-8:\n ", + sinfile)); + return 0; + } + // rewind to copy BOM to output file + fin.seekg(0); - // now copy input to output and expand variables in the - // input file at the same time - std::string inLine; - std::string outLine; - while (cmSystemTools::GetLineFromStream(fin, inLine)) { - outLine.clear(); - this->ConfigureString(inLine, outLine, atOnly, escapeQuotes); - fout << outLine << newLineCharacters; - } - // close the files before attempting to copy - fin.close(); - fout.close(); - if (!cmSystemTools::CopyFileIfDifferent(tempOutputFile, soutfile)) { + // now copy input to output and expand variables in the + // input file at the same time + std::string inLine; + std::string outLine; + while (cmSystemTools::GetLineFromStream(fin, inLine)) { + outLine.clear(); + this->ConfigureString(inLine, outLine, atOnly, escapeQuotes); + fout << outLine << newLineCharacters; + } + // close the files before attempting to copy + fin.close(); + fout.close(); + if (!cmSystemTools::CopyFileIfDifferent(tempOutputFile, soutfile)) { + this->IssueMessage(MessageType::FATAL_ERROR, + cmSystemTools::GetLastSystemError()); + res = 0; + } else { + if (!cmSystemTools::SetPermissions(soutfile, permissions)) { this->IssueMessage(MessageType::FATAL_ERROR, cmSystemTools::GetLastSystemError()); res = 0; - } else { - if (!cmSystemTools::SetPermissions(soutfile, permissions)) { - this->IssueMessage(MessageType::FATAL_ERROR, - cmSystemTools::GetLastSystemError()); - res = 0; - } } - cmSystemTools::RemoveFile(tempOutputFile); } + cmSystemTools::RemoveFile(tempOutputFile); + return res; }