From f50aec9334608a54c345801df1f2230284d12149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Wed, 13 Oct 2021 12:55:49 +0200 Subject: [PATCH] CommandLineInterface: Report an error immediately when writing to disk fails --- solc/CommandLineInterface.cpp | 19 +++---------------- solc/CommandLineInterface.h | 1 - 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 08b45c6ee..461074102 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -546,19 +546,12 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da string pathName = (m_options.output.dir / _fileName).string(); if (fs::exists(pathName) && !m_options.output.overwriteFiles) - { - serr() << "Refusing to overwrite existing file \"" << pathName << "\" (use --overwrite to force)." << endl; - m_outputFailed = true; - return; - } + solThrow(CommandLineOutputError, "Refusing to overwrite existing file \"" + pathName + "\" (use --overwrite to force)."); + ofstream outFile(pathName); outFile << _data; if (!outFile) - { - serr() << "Could not write to file \"" << pathName << "\"." << endl; - m_outputFailed = true; - return; - } + solThrow(CommandLineOutputError, "Could not write to file \"" + pathName + "\"."); } void CommandLineInterface::createJson(string const& _fileName, string const& _json) @@ -643,9 +636,6 @@ void CommandLineInterface::processInput() compile(); outputCompilationResults(); } - - if (m_outputFailed) - solThrow(CommandLineOutputError, "Failed to write all output files to disk."); } void CommandLineInterface::printVersion() @@ -969,10 +959,7 @@ void CommandLineInterface::writeLinkedFiles() ofstream outFile(src.first); outFile << src.second; if (!outFile) - { - m_outputFailed = true; solThrow(CommandLineOutputError, "Could not write to file " + src.first + ". Aborting."); - } } sout() << "Linking completed." << endl; } diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index fc584001f..9d1646e52 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -136,7 +136,6 @@ private: std::ostream& m_sout; std::ostream& m_serr; bool m_hasOutput = false; - bool m_outputFailed = false; ///< If true, creation or write to some of the output files failed. FileReader m_fileReader; std::optional m_standardJsonInput; std::unique_ptr m_compiler;