Skip to content

Commit

Permalink
CommandLineInterface: Report an error immediately when writing to dis…
Browse files Browse the repository at this point in the history
…k fails
  • Loading branch information
cameel committed Nov 9, 2021
1 parent c8380c2 commit f50aec9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
19 changes: 3 additions & 16 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion solc/CommandLineInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class CommandLineInterface
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<std::string> m_standardJsonInput;
std::unique_ptr<frontend::CompilerStack> m_compiler;
Expand Down

0 comments on commit f50aec9

Please sign in to comment.