Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 44 additions & 27 deletions src/bin/patchmanager-daemon/patchmanagerobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1951,21 +1951,10 @@ void PatchManagerObject::doRefreshPatchList()
{
qDebug() << Q_FUNC_INFO;

// create mangling replacement tokens
QStringList toManglePaths{}, mangledPaths{};
if(getSettings(QStringLiteral("bitnessMangle"), false).toBool()) {
toManglePaths = getMangleCandidates();
mangledPaths = getMangleCandidates().replaceInStrings("/usr/lib/", "/usr/lib64/");
if (Q_PROCESSOR_WORDSIZE == 4) { // 32 bit
std::swap(toManglePaths, mangledPaths);
}
}
qDebug() << Q_FUNC_INFO << "toManglePaths" << toManglePaths;
qDebug() << Q_FUNC_INFO << "mangledPaths" << mangledPaths;

// load applied patches

m_appliedPatches = getAppliedPatches();
if (m_mangleCandidates.empty()) getMangleCandidates();

// scan all patches
// collect conflicts per file
Expand All @@ -1985,28 +1974,27 @@ void PatchManagerObject::doRefreshPatchList()
const QByteArray line = patchFile.readLine();
if (line.startsWith(QByteArrayLiteral("+++ "))) {
const QString toPatch = QString::fromLatin1(line.split(' ')[1].split('\t')[0].split('\n')[0]);
QString path = toPatch;

for (int i = 0; i < toManglePaths.size(); i++) {
// we need to deal with either absolute, or "git-style" beginnings, see #426:
QString checkpath = path.mid(path.indexOf('/', 0));
if (checkpath.startsWith(toManglePaths[i])) {
qDebug() << Q_FUNC_INFO << "Mangle: Editing path: " << path;
path.replace(toManglePaths[i], mangledPaths[i]);
qDebug() << Q_FUNC_INFO << "Mangle: Edited path: " << path;
}
}

QString path = pathToMangledPath(toPatch, m_mangleCandidates);

// remove anything left of the slash until we find something that exists.
// deals with
// +++ patched/usr/foo/bar/...
// +++ a/usr/share/...
// FIXME: what if we find something that exists, but has nothing to do with our patch?
while (!QFileInfo::exists(path) && path.count('/') > 1) {
path = path.mid(path.indexOf('/', 1));
}
// if the loop finishes with no path/file found, it's likely a new file.
// so just accept whatever's in the patch, but do remove things left of the slash:
if (!QFileInfo::exists(path)) {
if (toPatch.startsWith(QChar('/'))) {
path = toPatch;
} else {
path = toPatch.mid(toPatch.indexOf('/', 1));
path = pathToMangledPath(toPatch, m_mangleCandidates);
if (!toPatch.startsWith(QChar('/'))) {
path = path.mid(path.indexOf('/', 1));
}
}

// record a list of possible conflicting paths
if (!filesConflicts[path].contains(patchFolder)) {
qDebug() << Q_FUNC_INFO << "Possible conflict in: " << path;
filesConflicts[path].append(patchFolder);
Expand Down Expand Up @@ -2929,3 +2917,32 @@ bool PatchManagerObject::tryToUnlinkFakeParent(const QString &path)
}
return false;
}

QString PatchManagerObject::pathToMangledPath(const QString &path, const QStringList &candidates) const
{
if(!getSettings(QStringLiteral("bitnessMangle"), false).toBool())
return path;
// Create mangling replacement tokens.
QStringList toManglePaths = candidates;
QStringList mangledPaths = candidates;
mangledPaths.replaceInStrings("/usr/lib/", "/usr/lib64/");
if (Q_PROCESSOR_WORDSIZE == 4) { // 32 bit
std::swap(toManglePaths, mangledPaths);
}
qDebug() << Q_FUNC_INFO << "toManglePaths" << toManglePaths;
qDebug() << Q_FUNC_INFO << "mangledPaths" << mangledPaths;

QString newpath = path;

for (int i = 0; i < toManglePaths.size(); i++) {
// we need to deal with either absolute, or "git-style" beginnings, see #426:
QString checkpath = path.mid(path.indexOf('/', 0));
if (checkpath.startsWith(toManglePaths[i])) {
qDebug() << Q_FUNC_INFO << "Mangle: Editing path: " << path;
newpath.replace(toManglePaths[i], mangledPaths[i]);
qDebug() << Q_FUNC_INFO << "Mangle: Edited path: " << path;
}
}
qDebug() << Q_FUNC_INFO << "Path after mangle" << newpath;
return newpath;
}
2 changes: 2 additions & 0 deletions src/bin/patchmanager-daemon/patchmanagerobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ private slots:

QStringList m_mangleCandidates;

QString pathToMangledPath(const QString &path, const QStringList &candidates) const;

PatchManagerAdaptor *m_adaptor = nullptr;
QNetworkAccessManager *m_nam = nullptr;

Expand Down