From 2db4945150a1a94aeaab6add1b5b371ba6fbdc59 Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Tue, 15 May 2018 21:36:36 +0300 Subject: file(WRITE): Report errors during write operation We already report an error if the file cannot be opened for writing. Add another check to report an error if a write operation itself fails. --- Source/cmFileCommand.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 6c1a869..1e47687 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -232,6 +232,14 @@ bool cmFileCommand::HandleWriteCommand(std::vector const& args, } std::string message = cmJoin(cmMakeRange(i, args.end()), std::string()); file << message; + if (!file) { + std::string error = "write failed ("; + error += cmSystemTools::GetLastSystemError(); + error += "):\n "; + error += fileName; + this->SetError(error); + return false; + } file.close(); if (mode) { cmSystemTools::SetPermissions(fileName.c_str(), mode); -- cgit v0.12