Skip to content

Commit

Permalink
Bug fix for case where the output path was not empty, but resolved to…
Browse files Browse the repository at this point in the history
… be the current working directory. This would cause mkpath() to fail on an empty string.
  • Loading branch information
billvaglienti committed Nov 16, 2016
1 parent 1ea100d commit d3ebd2c
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions protocolparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <iostream>

// The version of the protocol generator is set here
const QString ProtocolParser::genVersion = "1.6.4.b";
const QString ProtocolParser::genVersion = "1.6.4.c";

/*!
* \brief ProtocolParser::ProtocolParser
Expand Down Expand Up @@ -96,22 +96,26 @@ bool ProtocolParser::parse(QString filename, QString path)
QDomElement docElem = doc.documentElement();

// Set our output directory
if(!path.isEmpty())
// Make the path as short as possible
path = ProtocolFile::sanitizePath(path);

// There is an interesting case here: the user's output path is not
// empty, but after sanitizing it is empty, which implies the output
// path is the same as the current working directory. If this happens
// then mkpath() will fail because the input string cannot be empty,
// so we must test path.isEmpty() again. Note that in this case the
// path definitely exists (since its our working directory)

// Make sure the path exists
if(path.isEmpty() || QDir::current().mkpath(path))
{
// Make the path as short as possible
path = ProtocolFile::sanitizePath(path);

// Make sure the path exists
if(QDir::current().mkpath(path))
{
// Remember the output path for all users
support.outputpath = path;
}
else
{
std::cerr << "error: Failed to create output path: " << QDir::toNativeSeparators(path).toStdString() << std::endl;
return false;
}
// Remember the output path for all users
support.outputpath = path;
}
else
{
std::cerr << "error: Failed to create output path: " << QDir::toNativeSeparators(path).toStdString() << std::endl;
return false;
}

// This element must have the "Protocol" tag
Expand Down

0 comments on commit d3ebd2c

Please sign in to comment.