Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add basic repository manager
  • Loading branch information
Bernd Wachter committed Mar 28, 2013
1 parent 0a221d6 commit 8fa3ad8
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
2 changes: 2 additions & 0 deletions constants.h
Expand Up @@ -24,4 +24,6 @@
#define SSU_PROTOCOL_VERSION "1"
/// Maximum recursion level for resolving variables
#define SSU_MAX_RECURSION 1024
/// Path to zypper repo configuration
#define ZYPP_REPO_PATH "/etc/zypp/repos.d"
#endif
2 changes: 2 additions & 0 deletions libssu/libssu.pro
Expand Up @@ -4,11 +4,13 @@ HEADERS = ssu.h \
ssulog.h \
ssuvariables.h \
ssusettings.h \
ssurepomanager.h \
../constants.h
SOURCES = ssu.cpp \
ssudeviceinfo.cpp \
ssulog.cpp \
ssuvariables.cpp \
ssurepomanager.cpp \
ssusettings.cpp
TEMPLATE = lib
TARGET = ssu
Expand Down
103 changes: 103 additions & 0 deletions libssu/ssurepomanager.cpp
@@ -0,0 +1,103 @@
/**
* @file ssurepomanager.cpp
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/

#include <QStringList>
#include <QRegExp>
#include <QDirIterator>

#include "ssudeviceinfo.h"
#include "ssurepomanager.h"
#include "ssulog.h"
#include "ssu.h"

#include "../constants.h"

SsuRepoManager::SsuRepoManager(): QObject() {

}

void SsuRepoManager::update(){
// - delete all non-ssu managed repositories (missing ssu_ prefix)
// - create list of ssu-repositories for current adaptation
// - go through ssu_* repositories, delete all which are not in the list; write others

SsuDeviceInfo deviceInfo;
QStringList ssuFilters;

QSettings ssuSettings(SSU_CONFIGURATION, QSettings::IniFormat);
int deviceMode = ssuSettings.value("deviceMode").toInt();

SsuLog *ssuLog = SsuLog::instance();

// if device is misconfigured, always assume release mode
bool rndMode = false;

if ((deviceMode & Ssu::RepoManager) != Ssu::RepoManager){
ssuLog->print(LOG_INFO, "Repo management requested, but not enabled (option 'deviceMode')");
return;
}

if ((deviceMode & Ssu::RndMode) == Ssu::RndMode)
rndMode = true;

// strict mode enabled -> delete all repositories not prefixed by ssu_
if ((deviceMode & Ssu::StrictMode) == Ssu::StrictMode){
QDirIterator it(ZYPP_REPO_PATH, QDir::AllEntries|QDir::NoDot|QDir::NoDotDot);
while (it.hasNext()){
it.next();
if (it.fileName().left(4) != "ssu_"){
ssuLog->print(LOG_INFO, "Strict mode enabled, removing unmanaged repository " + it.fileName());
QFile(it.filePath()).remove();
}
}
}

// get list of device-specific repositories...
QStringList repos = deviceInfo.repos();

// ... delete all ssu-managed repositories not valid for this device ...
ssuFilters.append("ssu_*");
QDirIterator it(ZYPP_REPO_PATH, ssuFilters);
while (it.hasNext()){
QString f = it.next();

QStringList parts = it.fileName().split("_");
// repo file structure is ssu_<reponame>_<rnd|release>.repo -> splits to 3 parts
if (parts.count() == 3){
if (!repos.contains(parts.at(1)))
QFile(it.filePath()).remove();
} else
QFile(it.filePath()).remove();
}

// ... and create all repositories required for this device
foreach (const QString &repo, repos){
QFile repoFile(QString("%1/ssu_%2_%3.repo")
.arg(ZYPP_REPO_PATH)
.arg(repo)
.arg(rndMode ? "rnd" : "release"));

if (repoFile.open(QIODevice::WriteOnly | QIODevice::Text)){
QTextStream out(&repoFile);
// TODO, add -rnd or -release if we want to support having rnd and
// release enabled at the same time
out << "[" << repo << "]" << endl
<< "name=" << repo << endl
<< "failovermethod=priority" << endl
<< "type=rpm-md" << endl
<< "gpgcheck=0" << endl
<< "enabled=1" << endl;

if (rndMode)
out << "baseurl=plugin:ssu?rnd&repo=" << repo << endl;
else
out << "baseurl=plugin:ssu?repo=" << repo << endl;

out.flush();
}
}
}
28 changes: 28 additions & 0 deletions libssu/ssurepomanager.h
@@ -0,0 +1,28 @@
/**
* @file ssurepomanager.h
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/

#ifndef _SSUREPOMANAGER_H
#define _SSUREPOMANAGER_H

#include <QObject>
#include <QSettings>
#include <QHash>

class SsuRepoManager: public QObject {
Q_OBJECT

public:
SsuRepoManager();
/**
* Look up all variables in the specified configuration file section,
* run them through the variable expander, and add them to the supplied
* QHash
*/
void update();
};

#endif

0 comments on commit 8fa3ad8

Please sign in to comment.