From 0d8b99f6fb0404497dc21f3746970740c6888135 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Tue, 23 May 2017 17:33:21 +0300 Subject: [PATCH] Cosmetic style changes --- declarative/declarativessudeviceinfo.h | 3 ++ libssu/sandbox.cpp | 2 +- libssu/ssu.cpp | 28 ++++++++++------ libssu/ssucoreconfig.cpp | 3 +- libssu/ssudeviceinfo.cpp | 12 +++---- libssu/ssudeviceinfo.h | 13 +++++++- libssu/ssufeaturemanager.cpp | 3 +- libssu/ssulog.cpp | 6 ++-- libssu/ssurepomanager.cpp | 45 ++++++++++++-------------- libssu/ssusettings.cpp | 27 ++++++++-------- libssu/ssuvariables.cpp | 12 +++---- ssucli/ssucli.cpp | 12 +++---- ssucli/ssucli.h | 8 ++--- ssuconfperm/ssuconfperm.c | 13 ++++---- ssud/ssud.cpp | 3 +- ssuks/ssukickstarter.cpp | 30 +++++++++-------- ssuurlresolver/ssuurlresolver.cpp | 13 +++++--- 17 files changed, 129 insertions(+), 104 deletions(-) diff --git a/declarative/declarativessudeviceinfo.h b/declarative/declarativessudeviceinfo.h index 631f5e4..a007db4 100644 --- a/declarative/declarativessudeviceinfo.h +++ b/declarative/declarativessudeviceinfo.h @@ -32,16 +32,19 @@ class DeclarativeSsuDeviceInfo : public QObject * multithreaded environment, unless you like funny results. */ Q_INVOKABLE QString deviceFamily(); + /** * Try to find the device variant for the system this is running on. * If the device is not a variant it will return an empty string. If * fallback is set to true it return the device model in this case. */ Q_INVOKABLE QString deviceVariant(bool fallback = false); + /** * Try to find out ond what kind of system this is running */ Q_INVOKABLE QString deviceModel(); + /** * Return a string suitable for display in dialogs, ... * diff --git a/libssu/sandbox.cpp b/libssu/sandbox.cpp index 75e86a1..fb8b72d 100644 --- a/libssu/sandbox.cpp +++ b/libssu/sandbox.cpp @@ -276,7 +276,7 @@ bool Sandbox::prepare() QString Sandbox::createTmpDir(const QString &nameTemplate) { - static const int REASONABLE_REPEAT_COUNT = 10; + const int REASONABLE_REPEAT_COUNT = 10; for (int i = 0; i < REASONABLE_REPEAT_COUNT; ++i) { QString path; diff --git a/libssu/ssu.cpp b/libssu/ssu.cpp index f8594a7..91977f6 100644 --- a/libssu/ssu.cpp +++ b/libssu/ssu.cpp @@ -37,7 +37,8 @@ static void restoreUid() } } -Ssu::Ssu(): QObject() +Ssu::Ssu() + : QObject() { errorFlag = false; pendingRequests = 0; @@ -223,8 +224,9 @@ bool Ssu::registerDevice(QDomDocument *response) settings->setValue("registered", false); setError("Certificate is invalid"); return false; - } else + } else { settings->setValue("certificate", certificate.toPem()); + } QString privateKeyString = response->elementsByTagName("privateKey").at(0).toElement().text(); QSslKey privateKey(privateKeyString.toLatin1(), QSsl::Rsa); @@ -233,8 +235,9 @@ bool Ssu::registerDevice(QDomDocument *response) settings->setValue("registered", false); setError("Private key is invalid"); return false; - } else + } else { settings->setValue("privateKey", privateKey.toPem()); + } // oldUser is just for reference purposes, in case we want to notify // about owner changes for the device @@ -357,7 +360,7 @@ void Ssu::sendRegistration(QString usernameDomain, QString password) { errorFlag = false; - QString ssuCaCertificate, ssuRegisterUrl; + QString ssuRegisterUrl; QString username, domainName; SsuLog *ssuLog = SsuLog::instance(); @@ -381,7 +384,7 @@ void Ssu::sendRegistration(QString usernameDomain, QString password) setDomain(settings->value("default-rnd-domain").toString()); } - ssuCaCertificate = SsuRepoManager::caCertificatePath(); + QString ssuCaCertificate = SsuRepoManager::caCertificatePath(); if (ssuCaCertificate.isEmpty()) { setError("CA certificate for ssu not set ('_ca-certificate in domain')"); return; @@ -393,8 +396,9 @@ void Ssu::sendRegistration(QString usernameDomain, QString password) setError("URL for ssu registration not set (config key 'register-url')"); return; } - } else + } else { ssuRegisterUrl = settings->value("register-url").toString(); + } QString IMEI = deviceInfo.deviceUid(); if (IMEI == "") { @@ -535,8 +539,9 @@ void Ssu::storeAuthorizedKeys(QByteArray data) ssuLog->print(LOG_DEBUG, QString("Dropping to %1/%2 for writing authorized keys") .arg(uid_min) .arg(pw->pw_gid)); - } else + } else { return; + } homePath = Sandbox::map(homePath); @@ -547,13 +552,14 @@ void Ssu::storeAuthorizedKeys(QByteArray data) return; } - if (!dir.exists(homePath + "/.ssh")) + if (!dir.exists(homePath + "/.ssh")) { if (!dir.mkdir(homePath + "/.ssh")) { ssuLog->print(LOG_DEBUG, QString("Unable to create .ssh in %1") .arg(homePath)); restoreUid(); return; } + } QFile::setPermissions(homePath + "/.ssh", QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner); @@ -595,8 +601,9 @@ void Ssu::updateCredentials(bool force) setError("URL for credentials update not set (config key 'credentials-url')"); return; } - } else + } else { ssuCredentialsUrl = settings->value("credentials-url").toString(); + } if (!isRegistered()) { setError("Device is not registered."); @@ -659,8 +666,9 @@ void Ssu::updateStoreCredentials() if (settings->value("ignore-credential-errors").toBool() == true) { ssuLog->print(LOG_WARNING, QString("Warning: ignore-credential-errors is set, passing auth errors down to libzypp")); ssuLog->print(LOG_WARNING, QString("Store credentials not received. %1").arg(reply.error().message())); - } else + } else { setError(QString("Store credentials not received. %1").arg(reply.error().message())); + } } else { SsuCoreConfig *settings = SsuCoreConfig::instance(); settings->beginGroup("credentials-store"); diff --git a/libssu/ssucoreconfig.cpp b/libssu/ssucoreconfig.cpp index 153af12..c4e308b 100644 --- a/libssu/ssucoreconfig.cpp +++ b/libssu/ssucoreconfig.cpp @@ -111,8 +111,9 @@ void SsuCoreConfig::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode oldMode |= mode; } else if ((editMode & Ssu::Remove) == Ssu::Remove) { oldMode &= ~mode; - } else + } else { oldMode = mode; + } setValue("deviceMode", oldMode); sync(); diff --git a/libssu/ssudeviceinfo.cpp b/libssu/ssudeviceinfo.cpp index 5278db6..62f796d 100644 --- a/libssu/ssudeviceinfo.cpp +++ b/libssu/ssudeviceinfo.cpp @@ -23,7 +23,8 @@ #include "../constants.h" -SsuDeviceInfo::SsuDeviceInfo(QString model): QObject() +SsuDeviceInfo::SsuDeviceInfo(const QString &model) + : QObject() { boardMappings = new SsuSettings(SSU_BOARD_MAPPING_CONFIGURATION, SSU_BOARD_MAPPING_CONFIGURATION_DIR); if (!model.isEmpty()) @@ -160,19 +161,16 @@ QString SsuDeviceInfo::deviceVariant(bool fallback) QString SsuDeviceInfo::deviceModel() { - QDir dir; - QFile procCpuinfo; - QStringList keys; - if (!cachedModel.isEmpty()) return cachedModel; boardMappings->beginGroup("file.exists"); - keys = boardMappings->allKeys(); + QStringList keys = boardMappings->allKeys(); // check if the device can be identified by testing for a file foreach (const QString &key, keys) { QString value = boardMappings->value(key).toString(); + QDir dir; if (dir.exists(Sandbox::map(value))) { cachedModel = key; break; @@ -182,6 +180,7 @@ QString SsuDeviceInfo::deviceModel() if (!cachedModel.isEmpty()) return cachedModel; // check if the device can be identified by a string in /proc/cpuinfo + QFile procCpuinfo; procCpuinfo.setFileName(Sandbox::map("/proc/cpuinfo")); procCpuinfo.open(QIODevice::ReadOnly | QIODevice::Text); if (procCpuinfo.isOpen()) { @@ -347,7 +346,6 @@ QString SsuDeviceInfo::displayName(const int type) QString variant = deviceVariant(false); QString value, key; - switch (type) { case Ssu::DeviceManufacturer: key = "/deviceManufacturer"; diff --git a/libssu/ssudeviceinfo.h b/libssu/ssudeviceinfo.h index 21ea161..e5c967e 100644 --- a/libssu/ssudeviceinfo.h +++ b/libssu/ssudeviceinfo.h @@ -30,43 +30,51 @@ class SsuDeviceInfo: public QObject * Return the list of adaptations used for the set model */ QStringList adaptationRepos(); + /** * Resolve adaptation-specific variables for adaptationName, and store them in storageHash * Returns "adaptation" if a valid adaptation was found, adaptationName otherwise */ QString adaptationVariables(const QString &adaptationName, QHash *storageHash); + /** * Check if a given model is available in the deviceinfo database, either directly, * or as variant. If no model is provided as argument the autodetected or previously * set model is used. */ bool contains(const QString &model = ""); + /** * Try to find the device family for the system this is running on. This function * temporarily changes the detected model, and therefore should not be used in a * multithreaded environment, unless you like funny results. */ Q_INVOKABLE QString deviceFamily(); + /** * Try to find the device variant for the system this is running on. * If the device is not a variant it will return an empty string. If * fallback is set to true it return the device model in this case. */ Q_INVOKABLE QString deviceVariant(bool fallback = false); + /** * Try to find out ond what kind of system this is running */ Q_INVOKABLE QString deviceModel(); + /** * Calculate the device ID used in ssu requests * @return The first imei from oFono ModemManager API, if available, or WLAN mac address, or device uid fallback code similar to QDeviceInfo::uniqueDeviceID() */ Q_INVOKABLE QString deviceUid(); + /** * Return the list of repositories explicitely disabled for this device * This does not include repositories only disabled in the user configuration. */ QStringList disabledRepos(); + /** * Return a string suitable for display in dialogs, ... * @@ -85,10 +93,12 @@ class SsuDeviceInfo: public QObject * Disabled repositories are excluded depending on filter settings. */ QStringList repos(bool rnd = false, int filter = Ssu::NoFilter); + /** * Override device model autodetection */ Q_INVOKABLE void setDeviceModel(QString model = ""); + /** * Return a variable from the given variable section. 'var'- is automatically * prepended to the section name if not specified already. Recursive search @@ -96,11 +106,13 @@ class SsuDeviceInfo: public QObject * returned will be the first occurence of the variable. */ QVariant variable(QString section, const QString &key); + /** * Return the requested variable section. 'var-' is automatically * prepended to the section name if not specified already. */ void variableSection(QString section, QHash *storageHash); + /** * Return a value from an adaptation section. Returns an empty string * or a given default value if key does not exist. @@ -111,7 +123,6 @@ class SsuDeviceInfo: public QObject */ QVariant value(const QString &key, const QVariant &value = QVariant()); - private: SsuSettings *boardMappings; QString cachedFamily, cachedModel, cachedVariant; diff --git a/libssu/ssufeaturemanager.cpp b/libssu/ssufeaturemanager.cpp index 42baee5..75aa942 100644 --- a/libssu/ssufeaturemanager.cpp +++ b/libssu/ssufeaturemanager.cpp @@ -18,7 +18,8 @@ #include "../constants.h" -SsuFeatureManager::SsuFeatureManager(): QObject() +SsuFeatureManager::SsuFeatureManager() + : QObject() { featureSettings = new SsuSettings(SSU_FEATURE_CONFIGURATION, SSU_FEATURE_CONFIGURATION_DIR); } diff --git a/libssu/ssulog.cpp b/libssu/ssulog.cpp index 64b395c..46e6542 100644 --- a/libssu/ssulog.cpp +++ b/libssu/ssulog.cpp @@ -26,9 +26,6 @@ SsuLog *SsuLog::instance() void SsuLog::print(int priority, QString message) { - QByteArray ba = message.toUtf8(); - const char *ca = ba.constData(); - // directly go through qsettings here to avoid recursive invocation // of coreconfig / ssulog if (ssuLogLevel == -1) { @@ -45,6 +42,9 @@ void SsuLog::print(int priority, QString message) if (priority > ssuLogLevel) return; + QByteArray ba = message.toUtf8(); + const char *ca = ba.constData(); + if (sd_journal_print(priority, "ssu: %s", ca) < 0 && fallbackLogPath != "") { QFile logfile; QTextStream logstream; diff --git a/libssu/ssurepomanager.cpp b/libssu/ssurepomanager.cpp index 4774d8b..2af7a8b 100644 --- a/libssu/ssurepomanager.cpp +++ b/libssu/ssurepomanager.cpp @@ -21,9 +21,9 @@ #include "../constants.h" -SsuRepoManager::SsuRepoManager(): QObject() +SsuRepoManager::SsuRepoManager() + : QObject() { - } int SsuRepoManager::add(QString repo, QString repoUrl) @@ -47,8 +47,9 @@ int SsuRepoManager::add(QString repo, QString repoUrl) enabledRepos.append(repo); enabledRepos.removeDuplicates(); ssuSettings->setValue("enabled-repos", enabledRepos); - } else + } else { ssuSettings->setValue("repository-urls/" + repo, repoUrl); + } ssuSettings->sync(); return 0; @@ -190,8 +191,7 @@ QStringList SsuRepoManager::repos(bool rnd, SsuDeviceInfo &deviceInfo, int filte appInstallMode = true; } - if (filter == Ssu::NoFilter || - filter == Ssu::UserFilter) { + if (filter == Ssu::NoFilter || filter == Ssu::UserFilter) { // user defined repositories, or ones overriding URLs for default ones // -> in update mode we need to check for each of those if it already // exists. If it exists, keep it, if it does not, disable it @@ -242,23 +242,19 @@ 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; - SsuCoreConfig *ssuSettings = SsuCoreConfig::instance(); int deviceMode = ssuSettings->deviceMode(); SsuLog *ssuLog = SsuLog::instance(); - // if device is misconfigured, always assume release mode - bool rndMode = false; - if ((deviceMode & Ssu::DisableRepoManager) == Ssu::DisableRepoManager) { ssuLog->print(LOG_INFO, "Repo management requested, but not enabled (option 'deviceMode')"); return; } + // if device is misconfigured, always assume release mode + bool rndMode = false; + if ((deviceMode & Ssu::RndMode) == Ssu::RndMode) rndMode = true; @@ -280,10 +276,11 @@ void SsuRepoManager::update() } // ... delete all ssu-managed repositories not valid for this device ... + QStringList ssuFilters; ssuFilters.append("ssu_*"); QDirIterator it(Sandbox::map(ZYPP_REPO_PATH), ssuFilters); while (it.hasNext()) { - QString f = it.next(); + it.next(); QStringList parts = it.fileName().split("_"); // repo file structure is ssu__.repo -> splits to 3 parts @@ -291,8 +288,9 @@ void SsuRepoManager::update() if (!repositoryList.contains(parts.at(1)) || parts.at(2) != (rndMode ? "rnd.repo" : "release.repo" )) QFile(it.filePath()).remove(); - } else + } else { QFile(it.filePath()).remove(); + } } // ... and create all repositories required for this device @@ -395,11 +393,6 @@ QString SsuRepoManager::url(QString repoName, bool rndRepo, QHash repoParameters, QHash parametersOverride) { - QString r; - QStringList configSections; - SsuVariables var; - SsuCoreConfig *settings = SsuCoreConfig::instance(); - SsuSettings repoSettings(SSU_REPO_CONFIGURATION, QSettings::IniFormat); SsuDeviceInfo deviceInfo; // set debugSplit for incorrectly configured debuginfo repositories (debugSplit @@ -408,8 +401,7 @@ QString SsuRepoManager::url(QString repoName, bool rndRepo, if (repoName.endsWith("-debuginfo") && !repoParameters.contains("debugSplit")) repoParameters.insert("debugSplit", "debug"); - configSections = repoVariables(&repoParameters, rndRepo); - + QStringList configSections = repoVariables(&repoParameters, rndRepo); // Override device model (and therefore all the family, ... stuff) if (parametersOverride.contains("model")) @@ -421,16 +413,20 @@ QString SsuRepoManager::url(QString repoName, bool rndRepo, repoName = deviceInfo.adaptationVariables(repoName, &repoParameters); + SsuCoreConfig *settings = SsuCoreConfig::instance(); QString domain; + if (parametersOverride.contains("domain")) { domain = parametersOverride.value("domain"); domain.replace("-", ":"); - } else + } else { domain = settings->domain(); + } // variableSection does autodetection for the domain default section - var.variableSection(&repoSettings, - domain + "-domain", &repoParameters); + SsuSettings repoSettings(SSU_REPO_CONFIGURATION, QSettings::IniFormat); + SsuVariables var; + var.variableSection(&repoSettings, domain + "-domain", &repoParameters); // override arbitrary variables, mostly useful for generating mic URLs QHash::const_iterator i = parametersOverride.constBegin(); @@ -445,6 +441,7 @@ QString SsuRepoManager::url(QString repoName, bool rndRepo, // 3. URLs from repos.ini SsuFeatureManager featureManager; + QString r; if (settings->contains("repository-urls/" + repoName)) r = settings->value("repository-urls/" + repoName).toString(); diff --git a/libssu/ssusettings.cpp b/libssu/ssusettings.cpp index 602fcf3..f9e8f2c 100644 --- a/libssu/ssusettings.cpp +++ b/libssu/ssusettings.cpp @@ -14,26 +14,25 @@ #include "ssusettings_p.h" #include "ssulog_p.h" -SsuSettings::SsuSettings(): QSettings() +SsuSettings::SsuSettings() + : QSettings() { - } -SsuSettings::SsuSettings(const QString &fileName, Format format, QObject *parent): - QSettings(Sandbox::map(fileName), format, parent) +SsuSettings::SsuSettings(const QString &fileName, Format format, QObject *parent) + : QSettings(Sandbox::map(fileName), format, parent) { - } -SsuSettings::SsuSettings(const QString &fileName, Format format, const QString &defaultFileName, QObject *parent): - QSettings(Sandbox::map(fileName), format, parent) +SsuSettings::SsuSettings(const QString &fileName, Format format, const QString &defaultFileName, QObject *parent) + : QSettings(Sandbox::map(fileName), format, parent) { defaultSettingsFile = Sandbox::map(defaultFileName); upgrade(); } -SsuSettings::SsuSettings(const QString &fileName, const QString &settingsDirectory, QObject *parent): - QSettings(Sandbox::map(fileName), QSettings::IniFormat, parent) +SsuSettings::SsuSettings(const QString &fileName, const QString &settingsDirectory, QObject *parent) + : QSettings(Sandbox::map(fileName), QSettings::IniFormat, parent) { settingsd = Sandbox::map(settingsDirectory); merge(); @@ -112,14 +111,14 @@ void SsuSettings::merge(QSettings *masterSettings, const QStringList &settingsFi */ void SsuSettings::upgrade() { + if (defaultSettingsFile.isEmpty()) + return; + int configVersion = 0; int defaultConfigVersion = 0; SsuLog *ssuLog = SsuLog::instance(); - if (defaultSettingsFile == "") - return; - QSettings defaultSettings(defaultSettingsFile, QSettings::IniFormat); if (contains("configVersion")) @@ -133,13 +132,13 @@ void SsuSettings::upgrade() .arg(defaultConfigVersion)); for (int i = configVersion + 1; i <= defaultConfigVersion; i++) { - QStringList defaultKeys; QString currentSection = QString("%1/").arg(i); ssuLog->print(LOG_DEBUG, QString("Processing configuration version %1").arg(i)); defaultSettings.beginGroup(currentSection); - defaultKeys = defaultSettings.allKeys(); + QStringList defaultKeys = defaultSettings.allKeys(); defaultSettings.endGroup(); + foreach (const QString &key, defaultKeys) { // Default keys support both commands and new keys if (key.compare("cmd-remove", Qt::CaseSensitive) == 0) { diff --git a/libssu/ssuvariables.cpp b/libssu/ssuvariables.cpp index 8a14666..b5af213 100644 --- a/libssu/ssuvariables.cpp +++ b/libssu/ssuvariables.cpp @@ -14,9 +14,9 @@ #include "../constants.h" -SsuVariables::SsuVariables(): QObject() +SsuVariables::SsuVariables() + : QObject() { - } QString SsuVariables::defaultSection(SsuSettings *settings, QString section) @@ -153,9 +153,7 @@ QVariant SsuVariables::variable(QString section, const QString &key) QVariant SsuVariables::variable(SsuSettings *settings, QString section, const QString &key) { - QVariant value; - - value = readVariable(settings, section, key, 0); + QVariant value = readVariable(settings, section, key, 0); // first check if the value is defined in the main section, and fall back // to default sections @@ -178,9 +176,9 @@ void SsuVariables::variableSection(SsuSettings *settings, QString section, QHash { QString dSection = defaultSection(settings, section); - if (dSection.isEmpty()) + if (dSection.isEmpty()) { readSection(settings, section, storageHash, 0); - else { + } else { readSection(settings, dSection, storageHash, 0); readSection(settings, section, storageHash, 0, false); } diff --git a/ssucli/ssucli.cpp b/ssucli/ssucli.cpp index 1bf5e97..23f02be 100644 --- a/ssucli/ssucli.cpp +++ b/ssucli/ssucli.cpp @@ -19,7 +19,8 @@ #include "ssucli.h" -SsuCli::SsuCli(): QObject() +SsuCli::SsuCli() + : QObject() { connect(this, SIGNAL(done()), QCoreApplication::instance(), SLOT(quit()), Qt::DirectConnection); @@ -171,7 +172,6 @@ void SsuCli::optMode(QStringList opt) void SsuCli::optModel(QStringList opt) { QTextStream qout(stdout); - QTextStream qerr(stderr); SsuDeviceInfo deviceInfo; if (opt.count() == 3 && opt.at(2) == "-s") { @@ -413,8 +413,9 @@ void SsuCli::optRepos(QStringList opt) if (repo.endsWith("-debuginfo")) { repoName = repo.left(repo.size() - 10); repoParameters.insert("debugSplit", "debug"); - } else if (repoParameters.value("debugSplit") == "debug") + } else if (repoParameters.value("debugSplit") == "debug") { repoParameters.remove("debugSplit"); + } QString repoUrl = ssu.repoUrl(repoName, rndRepo, repoParameters, repoOverride); qout << "repo --name=" << repo << "-" @@ -426,9 +427,9 @@ void SsuCli::optRepos(QStringList opt) return; } - if (device.isEmpty()) + if (device.isEmpty()) { repos = repoManager.repos(rndRepo, deviceInfo, Ssu::BoardFilterUserBlacklist); - else { + } else { qout << "Printing repository configuration for '" << device << "'" << endl << endl; repos = repoManager.repos(rndRepo, deviceInfo, Ssu::BoardFilter); } @@ -601,7 +602,6 @@ void SsuCli::optUpdateRepos(QStringList opt) void SsuCli::run() { - QTextStream qout(stdout); QTextStream qerr(stderr); QStringList arguments = QCoreApplication::arguments(); diff --git a/ssucli/ssucli.h b/ssucli/ssucli.h index 63a75cc..14149e8 100644 --- a/ssucli/ssucli.h +++ b/ssucli/ssucli.h @@ -47,10 +47,10 @@ public slots: void optUpdateRepos(QStringList opt); enum Actions { - Remove = 0, - Add = 1, - Disable = 2, - Enable = 3, + Remove, + Add, + Disable, + Enable }; void optModifyRepo(enum Actions action, QStringList opt); diff --git a/ssuconfperm/ssuconfperm.c b/ssuconfperm/ssuconfperm.c index 1442d36..c751e41 100644 --- a/ssuconfperm/ssuconfperm.c +++ b/ssuconfperm/ssuconfperm.c @@ -14,11 +14,12 @@ #include "../constants.h" -int main(int argc, char **argv){ - struct stat sb; +int main(int argc, char **argv) +{ + struct stat sb; - if (!stat(SSU_CONFIGURATION, &sb)){ - chown(SSU_CONFIGURATION, 0, SSU_GROUP_ID); - chmod(SSU_CONFIGURATION, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); - } + if (!stat(SSU_CONFIGURATION, &sb)){ + chown(SSU_CONFIGURATION, 0, SSU_GROUP_ID); + chmod(SSU_CONFIGURATION, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); + } } diff --git a/ssud/ssud.cpp b/ssud/ssud.cpp index fc9d8fa..1e410a6 100644 --- a/ssud/ssud.cpp +++ b/ssud/ssud.cpp @@ -16,7 +16,8 @@ const char *Ssud::SERVICE_NAME = "org.nemo.ssu"; const char *Ssud::OBJECT_PATH = "/org/nemo/ssu"; -Ssud::Ssud(QObject *parent): QObject(parent) +Ssud::Ssud(QObject *parent) + : QObject(parent) { QDBusConnection connection = QDBusConnection::systemBus(); if (!connection.registerObject(OBJECT_PATH, this)) { diff --git a/ssuks/ssukickstarter.cpp b/ssuks/ssukickstarter.cpp index 08b1f92..f13e172 100644 --- a/ssuks/ssukickstarter.cpp +++ b/ssuks/ssukickstarter.cpp @@ -64,13 +64,13 @@ QStringList SsuKickstarter::commandSection(const QString §ion, const QString .arg(SSU_DATA_DIR) .arg(section))); - if (dir.exists(replaceSpaces(deviceModel.toLower()))) + if (dir.exists(replaceSpaces(deviceModel.toLower()))) { commandFile = replaceSpaces(deviceModel.toLower()); - else if (dir.exists(replaceSpaces(deviceInfo.deviceVariant(true).toLower()))) + } else if (dir.exists(replaceSpaces(deviceInfo.deviceVariant(true).toLower()))) { commandFile = replaceSpaces(deviceInfo.deviceVariant(true).toLower()); - else if (dir.exists("default")) + } else if (dir.exists("default")) { commandFile = "default"; - else { + } else { if (description.isEmpty()) result.append("## No suitable configuration found in " + dir.path()); else @@ -129,7 +129,7 @@ QStringList SsuKickstarter::repos() : "")) .arg(repoUrl) ); - } else + } else { result.append(QString("repo --name=%1-%2%3 --baseurl=%4") .arg(repo) .arg((rndMode ? repoOverride.value("rndRelease") @@ -138,6 +138,7 @@ QStringList SsuKickstarter::repos() : "")) .arg(repoUrl) ); + } } return result; @@ -228,12 +229,7 @@ void SsuKickstarter::setRepoParameters(QHash parameters) bool SsuKickstarter::write(QString kickstart) { - QFile ks; - QTextStream kout; QTextStream qerr(stderr); - SsuDeviceInfo deviceInfo(deviceModel); - SsuRepoManager repoManager; - SsuVariables var; QStringList commandSections; // initialize with default 'part' for compatibility, as partitions @@ -252,9 +248,11 @@ bool SsuKickstarter::write(QString kickstart) QHash defaults; // get generic repo variables; domain and adaptation specific bits are not interesting // in the kickstart + SsuRepoManager repoManager; repoManager.repoVariables(&defaults, rndMode); // overwrite with kickstart defaults + SsuDeviceInfo deviceInfo(deviceModel); deviceInfo.variableSection("kickstart-defaults", &defaults); if (deviceInfo.variable("kickstart-defaults", "commandSections") .canConvert(QMetaType::QStringList)) { @@ -308,7 +306,11 @@ bool SsuKickstarter::write(QString kickstart) QString outputDir = repoOverride.value("outputdir"); if (!outputDir.isEmpty()) outputDir.append("/"); + QFile ks; + if (kickstart.isEmpty()) { + SsuVariables var; + if (repoOverride.contains("filename")) { QString fileName = QString("%1%2") .arg(outputDir) @@ -321,9 +323,9 @@ bool SsuKickstarter::write(QString kickstart) qerr << "No filename specified, and no default filename configured" << endl; return false; } - } else if (kickstart == "-") + } else if (kickstart == "-") { opened = ks.open(stdout, QIODevice::WriteOnly); - else { + } else { ks.setFileName(outputDir + kickstart); opened = ks.open(QIODevice::WriteOnly); } @@ -331,8 +333,9 @@ bool SsuKickstarter::write(QString kickstart) if (!opened) { qerr << "Unable to write output file " << ks.fileName() << ": " << ks.errorString() << endl; return false; - } else if (!ks.fileName().isEmpty()) + } else if (!ks.fileName().isEmpty()) { qerr << "Writing kickstart to " << ks.fileName() << endl; + } QString displayName = QString("# DisplayName: %1 %2/%3 (%4) %5") .arg(repoOverride.value("brand")) @@ -365,6 +368,7 @@ bool SsuKickstarter::write(QString kickstart) QString kickstartType = QString("# KickstartType: %1") .arg((rndMode ? "rnd" : "release")); + QTextStream kout; kout.setDevice(&ks); kout << displayName << endl; kout << kickstartType << endl; diff --git a/ssuurlresolver/ssuurlresolver.cpp b/ssuurlresolver/ssuurlresolver.cpp index 7b77283..7000d5f 100644 --- a/ssuurlresolver/ssuurlresolver.cpp +++ b/ssuurlresolver/ssuurlresolver.cpp @@ -16,7 +16,8 @@ #include "libssu/sandbox_p.h" #include "libssu/ssulog_p.h" -SsuUrlResolver::SsuUrlResolver(): QObject() +SsuUrlResolver::SsuUrlResolver() + : QObject() { QObject::connect(this, SIGNAL(done()), QCoreApplication::instance(), SLOT(quit()), @@ -74,7 +75,7 @@ bool SsuUrlResolver::writeZyppCredentialsIfNeeded(QString credentialsScope) void SsuUrlResolver::run() { QHash repoParameters; - QString resolvedUrl, repo; + QString repo; bool isRnd = false; SsuLog *ssuLog = SsuLog::instance(); @@ -130,11 +131,12 @@ void SsuUrlResolver::run() if (ssu.error()) { error(ssu.lastError()); } - } else + } else { ssuLog->print(LOG_DEBUG, "Device not registered -- skipping credential update"); + } // resolve base url - resolvedUrl = ssu.repoUrl(repo, isRnd, repoParameters); + QString resolvedUrl = ssu.repoUrl(repo, isRnd, repoParameters); QString credentialsScope = ssu.credentialsScope(repo, isRnd); // only do credentials magic on secure connections @@ -155,8 +157,9 @@ void SsuUrlResolver::run() } headerList.append(QString("credentials=%1").arg(credentialsScope)); writeZyppCredentialsIfNeeded(credentialsScope); - } else + } else { ssuLog->print(LOG_DEBUG, QString("Skipping credential for %1 with scope %2").arg(repo).arg(credentialsScope)); + } if (!headerList.isEmpty() && !resolvedUrl.isEmpty()) { QUrl url(resolvedUrl);