mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
check config when writing (#405)
* check config when writing * integrate #403
This commit is contained in:
parent
26154befa4
commit
72e2f0bf18
@ -107,8 +107,8 @@ To generate make files on OS X:
|
|||||||
|
|
||||||
After which you can run cmake with the correct qt5 path:
|
After which you can run cmake with the correct qt5 path:
|
||||||
```
|
```
|
||||||
cmake -DCMAKE_PREFIX_PATH=/usr/local/Cellar/qt5/5.7.0 -DCMAKE_BUILD_TYPE=Release ..
|
export QVER=$(find /usr/local/Cellar/qt5 -type d -name "5.*" | sort -n | head -n1)
|
||||||
```
|
cmake -DCMAKE_PREFIX_PATH=$QVER -DCMAKE_BUILD_TYPE=Release ..```
|
||||||
|
|
||||||
### Run make to build Hyperion
|
### Run make to build Hyperion
|
||||||
The `-j $(nproc)` specifies the amount of CPU cores to use.
|
The `-j $(nproc)` specifies the amount of CPU cores to use.
|
||||||
|
@ -1028,7 +1028,7 @@ void JsonClientConnection::handleSchemaGetCommand(const QJsonObject& message, co
|
|||||||
|
|
||||||
// read the hyperion json schema from the resource
|
// read the hyperion json schema from the resource
|
||||||
QFile schemaData(":/hyperion-schema-"+QString::number(_hyperion->getConfigVersionId()));
|
QFile schemaData(":/hyperion-schema-"+QString::number(_hyperion->getConfigVersionId()));
|
||||||
|
|
||||||
if (!schemaData.open(QIODevice::ReadOnly))
|
if (!schemaData.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
std::stringstream error;
|
std::stringstream error;
|
||||||
@ -1039,7 +1039,7 @@ void JsonClientConnection::handleSchemaGetCommand(const QJsonObject& message, co
|
|||||||
QByteArray schema = schemaData.readAll();
|
QByteArray schema = schemaData.readAll();
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(schema, &error);
|
QJsonDocument doc = QJsonDocument::fromJson(schema, &error);
|
||||||
schemaData.close();
|
schemaData.close();
|
||||||
|
|
||||||
if (error.error != QJsonParseError::NoError)
|
if (error.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
// report to the user the failure and their locations in the document.
|
// report to the user the failure and their locations in the document.
|
||||||
|
@ -101,7 +101,32 @@ void CgiHandler::cmd_cfg_set()
|
|||||||
if (error.error == QJsonParseError::NoError)
|
if (error.error == QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
QJsonObject hyperionConfigJsonObj = hyperionConfig.object();
|
QJsonObject hyperionConfigJsonObj = hyperionConfig.object();
|
||||||
QJsonFactory::writeJson(QString::fromStdString(_hyperion->getConfigFileName()), hyperionConfigJsonObj);
|
try
|
||||||
|
{
|
||||||
|
// make sure the resources are loaded (they may be left out after static linking)
|
||||||
|
Q_INIT_RESOURCE(resource);
|
||||||
|
QJsonObject schemaJson = QJsonFactory::readSchema(":/hyperion-schema-"+QString::number(_hyperion->getConfigVersionId()));
|
||||||
|
QJsonSchemaChecker schemaChecker;
|
||||||
|
schemaChecker.setSchema(schemaJson);
|
||||||
|
if ( schemaChecker.validate(hyperionConfigJsonObj) )
|
||||||
|
{
|
||||||
|
QJsonFactory::writeJson(QString::fromStdString(_hyperion->getConfigFileName()), hyperionConfigJsonObj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string errorMsg = "ERROR: Json validation failed: \n";
|
||||||
|
for (std::list<std::string>::const_iterator i = schemaChecker.getMessages().begin(); i != schemaChecker.getMessages().end(); ++i)
|
||||||
|
{
|
||||||
|
Error(_log, "config write validation: %s", (*i).c_str());
|
||||||
|
errorMsg += *i + "\n";
|
||||||
|
}
|
||||||
|
throw std::runtime_error(errorMsg.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const std::runtime_error& validate_error)
|
||||||
|
{
|
||||||
|
_reply->appendRawData (QString(validate_error.what()).toUtf8());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user