Commit d8017f7b authored by Leszek Lesner's avatar Leszek Lesner Committed by Albert Astals Cid

Check if plymouth file is known to update-alternatives before setting

If the plymouth theme is not known to update-alternatives trying to
execute update-alternatives --set will always fail.
As plymouth kcm shows all plymouth themes in themes directory but not
all are necessarily known to update-alternatives we need to check if
they are known and if not use the update-alternatives --install instead
of --set.

Differential Revision: https://phabricator.kde.org/D5942
parent d36f310f
......@@ -65,31 +65,85 @@ ActionReply PlymouthHelper::save(const QVariantMap &args)
return reply;
}
int ret = 0;
QProcess process;
process.start("update-alternatives", QStringList() << "--set" << "default.plymouth" << dir.path() + QChar('/') + themeFile.first());
if (!process.waitForStarted()) {
QProcess checkProcess;
QByteArray data;
qDebug() << "Running update-alternatives --list default.plymouth now";
checkProcess.start("update-alternatives --list default.plymouth");
if (!checkProcess.waitForStarted()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("Cannot start update-alternatives."));
return reply;
}
if (!process.waitForFinished()) {
if (!checkProcess.waitForFinished()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("update-alternatives failed to run."));
return reply;
}
ret = process.exitCode();
else {
data = checkProcess.readAllStandardOutput();
}
ret = checkProcess.exitCode();
if (ret != 0) {
reply = ActionReply(ActionReply::HelperErrorReply());
reply.setErrorCode(static_cast<ActionReply::Error>(ret));
reply.setErrorDescription(i18n("update-alternatives returned with error condition %1.", ret));
return reply;
}
QString installFile = dir.path() + QChar('/') + themeFile.first();
if (!data.contains(installFile.toUtf8())) {
qDebug() << "Plymouth file not found in update-alternatives. So install it";
QProcess installProcess;
installProcess.start("update-alternatives", QStringList() << "--install" << "/usr/share/plymouth/themes/default.plymouth" << "default.plymouth" << installFile << "100");
if (!installProcess.waitForStarted()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("Cannot start update-alternatives."));
return reply;
}
if (!installProcess.waitForFinished()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("update-alternatives failed to run."));
return reply;
}
ret = installProcess.exitCode();
if (ret != 0) {
reply = ActionReply(ActionReply::HelperErrorReply());
reply.setErrorCode(static_cast<ActionReply::Error>(ret));
reply.setErrorDescription(i18n("update-alternatives returned with error condition %1.", ret));
return reply;
}
}
else {
qDebug() << "Running update-alternatives --set now";
QProcess process;
process.start("update-alternatives", QStringList() << "--set" << "default.plymouth" << installFile);
if (!process.waitForStarted()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("Cannot start update-alternatives."));
return reply;
}
if (!process.waitForFinished()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("update-alternatives failed to run."));
return reply;
}
ret = process.exitCode();
if (ret != 0) {
reply = ActionReply(ActionReply::HelperErrorReply());
reply.setErrorCode(static_cast<ActionReply::Error>(ret));
reply.setErrorDescription(i18n("update-alternatives returned with error condition %1.", ret));
return reply;
}
}
}
int ret = 0;
QProcess process;
qDebug() << "Running update-initramfs -u now";
process.start("/usr/sbin/update-initramfs", QStringList() << "-u");
if (!process.waitForStarted()) {
reply = ActionReply::BackendError;
......
Markdown is supported
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