Merge pull request #10293 from ethereum/fix-output-dir-creation-with-trailing-slash

[CLI] Fix --output-dir failure for paths with a trailing slash
This commit is contained in:
chriseth 2020-11-17 00:49:16 +01:00 committed by GitHub
commit a97521bff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -28,6 +28,7 @@ Bugfixes:
* SMTChecker: Fix false negative in modifier applied multiple times.
* SMTChecker: Fix internal error in the BMC engine when inherited contract from a different source unit has private state variables.
* SMTChecker: Fix internal error when ``array.push()`` is used as the LHS of an assignment.
* Command Line Interface: Fix write error when the directory passed to ``--output-dir`` ends with a slash.
* SMTChecker: Fix CHC false positives when branches are used inside modifiers.
* Code generator: Fix missing creation dependency tracking for abstract contracts.

View File

@ -737,12 +737,15 @@ map<string, Json::Value> CommandLineInterface::parseAstFromInput()
void CommandLineInterface::createFile(string const& _fileName, string const& _data)
{
namespace fs = boost::filesystem;
// create directory if not existent
fs::path p(m_args.at(g_argOutputDir).as<string>());
// Do not try creating the directory if the first item is . or ..
if (p.filename() != "." && p.filename() != "..")
fs::create_directories(p);
string pathName = (p / _fileName).string();
fs::path outputDir(m_args.at(g_argOutputDir).as<string>());
// NOTE: create_directories() raises an exception if the path consists solely of '.' or '..'
// (or equivalent such as './././.'). Paths like 'a/b/.' and 'a/b/..' are fine though.
// The simplest workaround is to use an absolute path.
fs::create_directories(fs::absolute(outputDir));
string pathName = (outputDir / _fileName).string();
if (fs::exists(pathName) && !m_args.count(g_strOverwrite))
{
serr() << "Refusing to overwrite existing file \"" << pathName << "\" (use --" << g_strOverwrite << " to force)." << endl;