Commit 31bef4c3 authored by kende's avatar kende

Merge branch 'jb17593' into 'master'

[ssu] Use libzypp for repo removal. Fixes JB#17593

See merge request !34
parents 0faf6c1c 15fbaa03
...@@ -31,7 +31,7 @@ SOURCES = \ ...@@ -31,7 +31,7 @@ SOURCES = \
CONFIG += link_pkgconfig CONFIG += link_pkgconfig
QT += network xml dbus QT += network xml dbus
PKGCONFIG += libsystemd-journal libshadowutils PKGCONFIG += libsystemd-journal libshadowutils libzypp
install_headers.files = $${public_headers} install_headers.files = $${public_headers}
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include <QRegExp> #include <QRegExp>
#include <QDirIterator> #include <QDirIterator>
#include <zypp/RepoManager.h>
#include <zypp/RepoInfo.h>
#include "sandbox_p.h" #include "sandbox_p.h"
#include "ssudeviceinfo.h" #include "ssudeviceinfo.h"
#include "ssurepomanager.h" #include "ssurepomanager.h"
...@@ -259,35 +262,37 @@ void SsuRepoManager::update() ...@@ -259,35 +262,37 @@ void SsuRepoManager::update()
// get list of device-specific repositories... // get list of device-specific repositories...
QStringList repositoryList = repos(rndMode); QStringList repositoryList = repos(rndMode);
zypp::RepoManager zyppManager;
std::list<zypp::RepoInfo> zyppRepos = zyppManager.knownRepositories();
// strict mode enabled -> delete all repositories not prefixed by ssu // strict mode enabled -> delete all repositories not prefixed by ssu
// assume configuration error if there are no device repos, and don't delete // assume configuration error if there are no device repos, and don't delete
// anything, even in strict mode // anything, even in strict mode
if ((deviceMode & Ssu::LenientMode) != Ssu::LenientMode && !repositoryList.isEmpty()) { if ((deviceMode & Ssu::LenientMode) != Ssu::LenientMode && !repositoryList.isEmpty()) {
QDirIterator it(Sandbox::map(ZYPP_REPO_PATH), QDir::AllEntries | QDir::NoDot | QDir::NoDotDot); foreach (zypp::RepoInfo zyppRepo, zyppRepos) {
while (it.hasNext()) { if (zyppRepo.filepath().basename().substr(0, 4) != "ssu_") {
it.next(); ssuLog->print(LOG_INFO, "Strict mode enabled, removing unmanaged repository " + QString::fromStdString(zyppRepo.name()));
if (it.fileName().left(4) != "ssu_") { zyppManager.removeRepository(zyppRepo);
ssuLog->print(LOG_INFO, "Strict mode enabled, removing unmanaged repository " + it.fileName());
QFile(it.filePath()).remove();
} }
} }
} }
// ... delete all ssu-managed repositories not valid for this device ... // ... delete all ssu-managed repositories not valid for this device ...
QStringList ssuFilters; zyppRepos = zyppManager.knownRepositories();
ssuFilters.append("ssu_*"); foreach (zypp::RepoInfo zyppRepo, zyppRepos) {
QDirIterator it(Sandbox::map(ZYPP_REPO_PATH), ssuFilters); if (zyppRepo.filepath().basename().substr(0, 4) == "ssu_") {
while (it.hasNext()) { QStringList parts = QString::fromStdString(zyppRepo.filepath().basename()).split("_");
it.next(); // repo file structure is ssu_<reponame>_<rnd|release>.repo -> splits to 3 parts
if (parts.count() == 3) {
QStringList parts = it.fileName().split("_"); if (!repositoryList.contains(parts.at(1)) ||
// repo file structure is ssu_<reponame>_<rnd|release>.repo -> splits to 3 parts parts.at(2) != (rndMode ? "rnd.repo" : "release.repo" )) {
if (parts.count() == 3) { // This will also remove metadata and cached packages from this repo
if (!repositoryList.contains(parts.at(1)) || zyppManager.removeRepository(zyppRepo);
parts.at(2) != (rndMode ? "rnd.repo" : "release.repo" )) }
QFile(it.filePath()).remove(); } else {
} else { // This will also remove metadata and cached packages from this repo
QFile(it.filePath()).remove(); zyppManager.removeRepository(zyppRepo);
}
} }
} }
...@@ -302,6 +307,8 @@ void SsuRepoManager::update() ...@@ -302,6 +307,8 @@ void SsuRepoManager::update()
repoName = repo.left(repo.size() - 10); repoName = repo.left(repo.size() - 10);
} }
// Not using libzypp to create repo files because it does not support
// file name being different than the repo name/alias (ssu_ prefix)
QString repoFilePath = QString("%1/ssu_%2_%3.repo") QString repoFilePath = QString("%1/ssu_%2_%3.repo")
.arg(Sandbox::map(ZYPP_REPO_PATH)) .arg(Sandbox::map(ZYPP_REPO_PATH))
.arg(repo) .arg(repo)
......
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