Commit 74e81bec authored by Olivier Langella's avatar Olivier Langella
Browse files

test added to check if output file path exists and create if needed

parent ae79fafb
......@@ -1166,6 +1166,13 @@ MasschroqmlParser::startElement_quantification_result(const QXmlAttributes &attr
_errorStr = QObject::tr("the quantification_result tag must have an output_file attribute.");
return false;
}
if (!ensureFilePathExists(output_file)) {
QDir file_dir(output_file);
_errorStr = QObject::tr("problem writing output to directory %1\n Please check output file path and permissions").arg(file_dir.absolutePath());
return false;
}
QString format = attributes.value("format");
if (format.isEmpty())
{
......@@ -1201,6 +1208,7 @@ MasschroqmlParser::startElement_quantification_result(const QXmlAttributes &attr
}
else if (format == "tsv")
{
MonitorSpeedInterface * p_monitor_speed = new MonitorTsvOutput(output_file);
_p_current_monitor_speed_list->addMonitor(p_monitor_speed);
return true;
......@@ -1217,6 +1225,28 @@ MasschroqmlParser::startElement_quantification_result(const QXmlAttributes &attr
return false;
}
bool MasschroqmlParser::ensureFilePathExists(QString output_file) {
QFileInfo complete_path(output_file);
// qDebug()<< "MasschroqmlParser::ensureFilePathExists complete_path.dir()" << complete_path.dir().absolutePath() ;
// qDebug() << QFileInfo("~/examples/191697/main.cpp").dir().absolutePath();
// qDebug() << QFileInfo("~/examples/191697/main").dir().absolutePath();
QDir only_dir(complete_path.dir().absolutePath());
if (only_dir.exists()) {
return true;
}
else {
//try to create it
if (only_dir.mkpath(only_dir.absolutePath()) == false ) {
return false;
qDebug()<< "MasschroqmlParser::ensureFilePathExists FALSE " << only_dir.absolutePath() ;
}
else {
return true;
}
}
}
bool
MasschroqmlParser::startElement_compar_result(const QXmlAttributes &attributes)
{
......@@ -1226,6 +1256,12 @@ MasschroqmlParser::startElement_compar_result(const QXmlAttributes &attributes)
_errorStr = QObject::tr("the compar_result tag must have an output_file attribute.");
return false;
}
if (!ensureFilePathExists(output_file)) {
QDir file_dir(output_file);
_errorStr = QObject::tr("problem writing output to directory %1\n Please check output file path and permissions").arg(file_dir.absolutePath());
return false;
}
QString format = attributes.value("format");
if (format.isEmpty())
{
......
......@@ -268,6 +268,14 @@ private:
bool _read_time_values;
QString _time_directory;
double _current_mh;
/** \brief ensure that the given file path already exists and has correct permissions
*
* if the file path does not exists, this will try to create it.
*
* \return true if path is ok, false otherwise
*/
bool ensureFilePathExists(QString output_file);
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment