Skip to content

Commit

Permalink
kill --reset-system
Browse files Browse the repository at this point in the history
Contributes-To: sailfishos-patches#204
  • Loading branch information
nephros committed Jan 16, 2023
1 parent 2bd327f commit 6698868
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 90 deletions.
88 changes: 0 additions & 88 deletions src/bin/patchmanager-daemon/patchmanagerobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,90 +828,6 @@ void PatchManagerObject::restartService(const QString &serviceName)
}
}

void PatchManagerObject::resetSystem()
{
qDebug() << Q_FUNC_INFO;

unapplyAllPatches();

QStringList patchedFiles;
QDir patchesDir(PATCHES_DIR);
for (const QString &patchFolder : patchesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
qDebug() << Q_FUNC_INFO << "Processing Patch" << patchFolder;
QFile patchFile(QStringLiteral("%1/%2/unified_diff.patch").arg(PATCHES_DIR, patchFolder));
if (!patchFile.exists() || !patchFile.open(QFile::ReadOnly)) {
continue;
}
while (!patchFile.atEnd()) {
QByteArray line = patchFile.readLine();
if (!line.startsWith(QByteArrayLiteral("+++ "))) {
continue;
}
QString toPatch = QString::fromLatin1(line.split(' ')[1].split('\t')[0].split('\n')[0]);
QString path = toPatch;
while (!QFileInfo::exists(path) && path.count('/') > 1) {
path = path.mid(path.indexOf('/', 1));
}
if (!QFileInfo::exists(path)) {
if (toPatch.startsWith(QChar('/'))) {
path = toPatch;
} else {
path = toPatch.mid(toPatch.indexOf('/', 1));
}
}
if (!patchedFiles.contains(path)) {
qDebug() << Q_FUNC_INFO << "Found patched file" << path;
patchedFiles.append(path);
}
}
}

QStringList packages;
for (const QString &file : patchedFiles) {
qDebug() << Q_FUNC_INFO << "Processing patched file" << file;

QProcess rpmProc;
rpmProc.start(BIN_RPM, { QStringLiteral("-qf"), QStringLiteral("--qf"), QStringLiteral("%{NAME}"), file });
if (!rpmProc.waitForFinished(5000) || rpmProc.exitCode() != 0) {
continue;
}
const QString package = QString::fromLatin1(rpmProc.readAllStandardOutput());
if (package.isEmpty()) {
continue;
} else if (!packages.contains(package)) {
qDebug() << Q_FUNC_INFO << "Found RPM package to reinstall:" << package;
packages.append(package);
}
}

if (packages.isEmpty()) {
qDebug() << Q_FUNC_INFO << "Empty RPM package, hence nothing to reinstall.";
QCoreApplication::exit(0);
return;
}

qDebug() << Q_FUNC_INFO << "Refreshing repositories.";
QProcess refreshProc;
refreshProc.start(BIN_PKCON, { QStringLiteral("refresh") });
refreshProc.waitForFinished(-1);

for (const QString &package : packages) {
qDebug() << Q_FUNC_INFO << "Reinstalling RPM package" << package;

QProcess pkconProc;
pkconProc.start(BIN_PKCON, { QStringLiteral("install"), QStringLiteral("-y"), package });
pkconProc.waitForFinished(-1);

if (pkconProc.exitCode() == 0) {
qDebug() << Q_FUNC_INFO << "Successfully reinstalled RPM package.";
} else {
qDebug() << Q_FUNC_INFO << "Failed to reinstall RPM package!";
}
}

QCoreApplication::exit(0);
}

void PatchManagerObject::clearFakeroot()
{
qDebug() << Q_FUNC_INFO;
Expand Down Expand Up @@ -940,10 +856,6 @@ void PatchManagerObject::process()

if (args.count() == 2 && args[1] == QStringLiteral("--daemon")) {
initialize();
} else if (args[1] == QStringLiteral("--reset-system")) {
resetSystem();
QCoreApplication::exit(2);
return;
} else if (args.count() > 1) {
QDBusConnection connection = QDBusConnection::systemBus();
qDebug() << Q_FUNC_INFO << "Has arguments, sending D-Bus message and quit.";
Expand Down
1 change: 0 additions & 1 deletion src/bin/patchmanager-daemon/patchmanagerobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ private slots:
private:
void restartService(const QString &serviceName);

void resetSystem();
void clearFakeroot();

void registerDBus();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/patchmanager-tool
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function usage() {
printf "* For writing to <filepath>, it must not already exist and must be in a writable directory.\n"
printf "* For reading from <filepath>, it must be a plain text file containing the (internal) names of Patches, separated by white-spaces, commas or both.\n"
printf "* The -a, -A, -d, -D options must be executed as root to be effective, otherwise they output a script with the commands to execute.\n"
printf "* In order to use this tool as a drop-in replacement for calling the patchmanager executable, its options -u (synonym to -d), --unapply-all (synonym to -D) and --reset-system are also supported.\n"
printf "* In order to use this tool as a drop-in replacement for calling the patchmanager executable, its options -u (synonym to -d), --unapply-all (synonym to -D) are also supported.\n"
printf "Exit codes:\n"
printf "\t0: All went fine.\n"
printf "\t1: Incorrect parameter(s) provided.\n"
Expand Down

0 comments on commit 6698868

Please sign in to comment.