mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Fix, if db-file is readonly (#1082)
This commit is contained in:
parent
56f45a4930
commit
d28540a7fe
@ -263,7 +263,7 @@ int main(int argc, char** argv)
|
||||
QDir destDir(exportEfxOption.value(parser));
|
||||
if (directory.exists() && destDir.exists())
|
||||
{
|
||||
std::cout << "Extract to folder: " << std::endl;
|
||||
std::cout << "Extract to folder: " << destDir.absolutePath().toStdString() << std::endl;
|
||||
QStringList filenames = directory.entryList(QStringList() << "*", QDir::Files, QDir::Name | QDir::IgnoreCase);
|
||||
QString destFileName;
|
||||
for (const QString & filename : filenames)
|
||||
@ -294,40 +294,37 @@ int main(int argc, char** argv)
|
||||
int rc = 1;
|
||||
bool readonlyMode = false;
|
||||
|
||||
QString userDataPath(userDataOption.value(parser));
|
||||
|
||||
QDir userDataDirectory(userDataPath);
|
||||
QFileInfo dbFile(userDataDirectory.absolutePath() +"/db/hyperion.db");
|
||||
|
||||
try
|
||||
{
|
||||
// handle and create userDataPath for user data, default path is home directory + /.hyperion
|
||||
QString userDataPath(userDataOption.value(parser));
|
||||
QDir mDir(userDataPath);
|
||||
QFileInfo mFi(userDataPath);
|
||||
if(!mDir.mkpath(userDataPath) || !mFi.isWritable())
|
||||
{
|
||||
if ( !mDir.isReadable() )
|
||||
{
|
||||
throw std::runtime_error("The user data path '"+mDir.absolutePath().toStdString()+"' can't be created or isn't read/writeable. Please setup permissions correctly!");
|
||||
}
|
||||
else
|
||||
{
|
||||
QFileInfo mFiDB(userDataPath + "/db/hyperion.db");
|
||||
|
||||
if ( !mFiDB.exists() )
|
||||
|
||||
if (dbFile.exists())
|
||||
{
|
||||
throw std::runtime_error("Configuration database '"+mFiDB.absoluteFilePath().toStdString()+"' does not exist!");
|
||||
if (!dbFile.isReadable())
|
||||
{
|
||||
throw std::runtime_error("Configuration database '" + dbFile.absoluteFilePath().toStdString() + "' is not readable. Please setup permissions correctly!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !mFiDB.isReadable() )
|
||||
{
|
||||
throw std::runtime_error("Configuration database '"+mFiDB.absoluteFilePath().toStdString()+"' is not readable. Please setup permissions correctly!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !mFiDB.isWritable() )
|
||||
if (!dbFile.isWritable())
|
||||
{
|
||||
readonlyMode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!userDataDirectory.mkpath(dbFile.absolutePath()))
|
||||
{
|
||||
if (!userDataDirectory.isReadable() || !dbFile.isWritable())
|
||||
{
|
||||
throw std::runtime_error("The user data path '" + userDataDirectory.absolutePath().toStdString() + "' can't be created or isn't read/writeable. Please setup permissions correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,12 +333,12 @@ int main(int argc, char** argv)
|
||||
{
|
||||
if ( readonlyMode )
|
||||
{
|
||||
Error(log,"Password reset is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(mDir.absolutePath()));
|
||||
Error(log,"Password reset is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(userDataDirectory.absolutePath()));
|
||||
throw std::runtime_error("Password reset failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
AuthTable* table = new AuthTable(userDataPath);
|
||||
AuthTable* table = new AuthTable(userDataDirectory.absolutePath());
|
||||
if(table->resetHyperionUser()){
|
||||
Info(log,"Password reset successful");
|
||||
delete table;
|
||||
@ -359,15 +356,14 @@ int main(int argc, char** argv)
|
||||
{
|
||||
if ( readonlyMode )
|
||||
{
|
||||
Error(log,"Deleting the configuration database is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(mDir.absolutePath()));
|
||||
Error(log,"Deleting the configuration database is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(dbFile.absolutePath()));
|
||||
throw std::runtime_error("Deleting the configuration database failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString dbFile = mDir.absolutePath() + "/db/hyperion.db";
|
||||
if (QFile::exists(dbFile))
|
||||
if (QFile::exists(dbFile.absoluteFilePath()))
|
||||
{
|
||||
if (!QFile::remove(dbFile))
|
||||
if (!QFile::remove(dbFile.absoluteFilePath()))
|
||||
{
|
||||
Info(log,"Failed to delete Database!");
|
||||
exit(1);
|
||||
@ -379,7 +375,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning(log,"Configuration database [%s] does not exist!", QSTRING_CSTR(dbFile));
|
||||
Warning(log,"Configuration database [%s] does not exist!", QSTRING_CSTR(dbFile.absoluteFilePath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -389,17 +385,17 @@ int main(int argc, char** argv)
|
||||
|
||||
if ( !readonlyMode )
|
||||
{
|
||||
Info(log, "Set user data path to '%s'", QSTRING_CSTR(mDir.absolutePath()));
|
||||
Info(log, "Set user data path to '%s'", QSTRING_CSTR(userDataDirectory.absolutePath()));
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning(log,"The user data path '%s' is not writeable. Hyperion starts in read-only mode. Configuration updates will not be persisted!", QSTRING_CSTR(mDir.absolutePath()));
|
||||
Warning(log,"The user data path '%s' is not writeable. Hyperion starts in read-only mode. Configuration updates will not be persisted!", QSTRING_CSTR(userDataDirectory.absolutePath()));
|
||||
}
|
||||
|
||||
HyperionDaemon* hyperiond = nullptr;
|
||||
try
|
||||
{
|
||||
hyperiond = new HyperionDaemon(userDataPath, qApp, bool(logLevelCheck), readonlyMode);
|
||||
hyperiond = new HyperionDaemon(userDataDirectory.absolutePath(), qApp, bool(logLevelCheck), readonlyMode);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
@ -430,5 +426,13 @@ int main(int argc, char** argv)
|
||||
|
||||
// delete components
|
||||
Logger::deleteInstance();
|
||||
|
||||
#ifdef _WIN32
|
||||
if (parser.isSet(consoleOption))
|
||||
{
|
||||
system("pause");
|
||||
}
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user