...
  View open merge request
Commits (18)
cmake_minimum_required(VERSION 3.4.0 FATAL_ERROR)
project(akabeicore)
cmake_minimum_required(VERSION 3.0.0)
set(MAJOR_AKABEI_VERSION 0 CACHE INT "Akabei’s major version number" FORCE)
set(MINOR_AKABEI_VERSION 0 CACHE INT "Akabei’s minor version number" FORCE)
set(PATCH_AKABEI_VERSION 1 CACHE INT "Akabei’s patch version number" FORCE)
set(FIX_AKABEI_VERSION 0 CACHE INT "Akabei’s fix version number" FORCE)
set(AKABEI_VERSION_STRING "${MAJOR_AKABEI_VERSION}.${MINOR_AKABEI_VERSION}.${PATCH_AKABEI_VERSION}.${FIX_AKABEI_VERSION}")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
if(CMAKE_COMPILER_IS_GNUCXX AND BUILD_COVERAGE)
include(CodeCoverage)
setup_target_for_coverage(${PROJECT_NAME}_coverage ctest coverage)
SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
endif()
enable_testing() # make this conditional?
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-W -Wall)
add_definitions(-Werror)
# set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Compiles with debugging symbols (Debug mode)
if (CMAKE_COMPILER_IS_GNUCC)
......@@ -23,34 +46,12 @@ add_definitions(#-DQT_NO_CAST_TO_ASCII
-DQT_USE_QSTRINGBUILDER
)
set(MAJOR_AKABEI_VERSION 0 CACHE INT "Akabei’s major version number" FORCE)
set(MINOR_AKABEI_VERSION 0 CACHE INT "Akabei’s minor version number" FORCE)
set(PATCH_AKABEI_VERSION 1 CACHE INT "Akabei’s patch version number" FORCE)
set(FIX_AKABEI_VERSION 0 CACHE INT "Akabei’s fix version number" FORCE)
set(AKABEI_VERSION_STRING "${MAJOR_AKABEI_VERSION}.${MINOR_AKABEI_VERSION}.${PATCH_AKABEI_VERSION}.${FIX_AKABEI_VERSION}")
find_package(Qt5 5.2.0 REQUIRED CONFIG COMPONENTS Core Test Network Concurrent DBus Widgets)
find_package(LibArchive REQUIRED)
find_package(Sqlite REQUIRED)
find_package(PolkitQt5-1 REQUIRED)
add_definitions(${QT_DEFINITIONS} -W -Wall)
add_definitions(-Werror)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories(
BEFORE SYSTEM
${QT_INCLUDES}
${LIBARCHIVE_INCLUDE_DIR}
${POLKITQT-1_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/lib
${CMAKE_CURRENT_BINARY_DIR}/tools/polkit-helper
${CMAKE_SOURCE_DIR}/lib
${CMAKE_SOURCE_DIR}/tools/polkit-helper
)
# Define install directories
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/akabei" CACHE "Akabei data installation directory" STRING)
set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE "Akabei binary installation directory" STRING)
......
# Copyright (c) 2012 - 2015, Lars Bilke
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
#
# 2012-01-31, Lars Bilke
# - Enable Code Coverage
#
# 2013-09-17, Joakim Söderberg
# - Added support for Clang.
# - Some additional usage instructions.
#
# USAGE:
# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here:
# http://stackoverflow.com/a/22404544/80480
#
# 1. Copy this file into your cmake modules path.
#
# 2. Add the following line to your CMakeLists.txt:
# INCLUDE(CodeCoverage)
#
# 3. Set compiler flags to turn off optimization and enable coverage:
# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
#
# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
# which runs your test executable and produces a lcov code coverage report:
# Example:
# SETUP_TARGET_FOR_COVERAGE(
# my_coverage_target # Name for custom target.
# test_driver # Name of the test driver executable that runs the tests.
# # NOTE! This should always have a ZERO as exit code
# # otherwise the coverage generation will not complete.
# coverage # Name of output directory.
# )
#
# 4. Build a Debug build:
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# make
# make my_coverage_target
#
#
# Check prereqs
FIND_PROGRAM( GCOV_PATH gcov )
FIND_PROGRAM( LCOV_PATH lcov )
FIND_PROGRAM( GENHTML_PATH genhtml )
FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
IF(NOT GCOV_PATH)
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
ENDIF() # NOT GCOV_PATH
IF(NOT CMAKE_COMPILER_IS_GNUCXX)
# Clang version 3.0.0 and greater now supports gcov as well.
MESSAGE(WARNING "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.")
IF(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
ENDIF()
ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX
SET(CMAKE_CXX_FLAGS_COVERAGE
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C++ compiler during coverage builds."
FORCE )
SET(CMAKE_C_FLAGS_COVERAGE
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C compiler during coverage builds."
FORCE )
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used for linking binaries during coverage builds."
FORCE )
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
FORCE )
MARK_AS_ADVANCED(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage"))
MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" )
ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
# Param _targetname The name of new the custom make target
# Param _testrunner The name of the target which runs the tests.
# MUST return ZERO always, even on errors.
# If not, no coverage report will be created!
# Param _outputname lcov output is generated as _outputname.info
# HTML report is generated in _outputname/index.html
# Optional fourth parameter is passed as arguments to _testrunner
# Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF() # NOT LCOV_PATH
IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF() # NOT GENHTML_PATH
# Setup target
ADD_CUSTOM_TARGET(${_targetname}
# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters
# Run tests
COMMAND ${_testrunner} ${ARGV3}
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info
COMMAND ${LCOV_PATH} --remove ${_outputname}.info 'tests/*' '/usr/*' --output-file ${_outputname}.info.cleaned
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned
COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
)
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
# Param _targetname The name of new the custom make target
# Param _testrunner The name of the target which runs the tests
# Param _outputname cobertura output is generated as _outputname.xml
# Optional fourth parameter is passed as arguments to _testrunner
# Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname)
IF(NOT PYTHON_EXECUTABLE)
MESSAGE(FATAL_ERROR "Python not found! Aborting...")
ENDIF() # NOT PYTHON_EXECUTABLE
IF(NOT GCOVR_PATH)
MESSAGE(FATAL_ERROR "gcovr not found! Aborting...")
ENDIF() # NOT GCOVR_PATH
ADD_CUSTOM_TARGET(${_targetname}
# Run tests
${_testrunner} ${ARGV3}
# Running gcovr
COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running gcovr to produce Cobertura code coverage report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Cobertura code coverage report saved in ${_outputname}.xml."
)
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA
......@@ -86,7 +86,7 @@ QVariant SQLiteResource::getDataAt(int rowNumber, const QString& columnName)
{
QMutexLocker locker(&d->mutex);
if (d->table.isEmpty() || rowNumber >= d->table.size() || d->table[rowNumber].count(columnName) == 0) {
std::string error = QString("Access to non-existent data. Trying to access %1.").arg(columnName).toStdString();
std::string error = QStringLiteral("Access to non-existent data. Trying to access %1.").arg(columnName).toStdString();
throw SQLiteException(error.c_str());
}
......
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
PARENT_SCOPE
${CMAKE_CURRENT_BINARY_DIR}
)
set(AKABEI_CORE_SRCS
akabeibackend.cpp
akabeiconfig.cpp
......@@ -94,6 +88,13 @@ operations/akabeioperationutils.h
add_library(akabeicore SHARED ${AKABEI_CORE_SRCS} ${AKABEI_OPERATION_SRCS} ${AKABEI_MISSING_MOCS})
target_include_directories(akabeicore PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/lib
${CMAKE_CURRENT_BINARY_DIR}/tools/polkit-helper
${CMAKE_SOURCE_DIR}/lib
${CMAKE_SOURCE_DIR}/tools/polkit-helper
)
set_target_properties(akabeicore PROPERTIES AUTOMOC TRUE)
set_target_properties(akabeicore PROPERTIES VERSION ${MAJOR_AKABEI_VERSION}.${MINOR_AKABEI_VERSION}.${PATCH_AKABEI_VERSION}
......
......@@ -79,15 +79,15 @@ void PolKitSQLiteConnection::connectToDB(QString const& name, bool readonly)
SQLiteResource PolKitSQLiteConnection::query(const QString &q)
{
if ((d->access.testFlag(Akabei::Helpers::ReadWritePermission)) || ((d->access.testFlag(Akabei::Helpers::ReadPermission)) && q.startsWith("SELECT"))) {
if ((d->access.testFlag(Akabei::Helpers::ReadWritePermission)) || ((d->access.testFlag(Akabei::Helpers::ReadPermission)) && q.startsWith(QLatin1String("SELECT")))) {
d->lastQueryDBus = false;
return d->connection->query(q);
}
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.sqlite.query")) {
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.sqlite.query"))) {
QDBusInterface iface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/sqlite"), QStringLiteral("org.chakraproject.akabeicorehelper.sqlite"), QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
QDBusMessage mes = iface.call("query", q);
QDBusMessage mes = iface.call(QStringLiteral("query"), q);
d->lastQueryDBus = true;
if (!mes.arguments().isEmpty()) {
const QDBusArgument arg = mes.arguments().first().value<QDBusArgument>();
......@@ -106,15 +106,15 @@ SQLiteResource PolKitSQLiteConnection::query(const QString &q)
void PolKitSQLiteConnection::query(const QString &q, const QVariantMap &bindings)
{
if ((d->access.testFlag(Akabei::Helpers::ReadWritePermission)) || ((d->access.testFlag(Akabei::Helpers::ReadPermission)) && q.startsWith("SELECT"))) {
if ((d->access.testFlag(Akabei::Helpers::ReadWritePermission)) || ((d->access.testFlag(Akabei::Helpers::ReadPermission)) && q.startsWith(QLatin1String("SELECT")))) {
d->connection->query(q, bindings);
d->lastQueryDBus = false;
return;
}
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.sqlite.query")) {
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.sqlite.query"))) {
QDBusInterface iface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/sqlite"), QStringLiteral("org.chakraproject.akabeicorehelper.sqlite"), QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
QDBusMessage mes = iface.call("query", q, bindings);
QDBusMessage mes = iface.call(QStringLiteral("query"), q, bindings);
d->lastQueryDBus = true;
} else {
Akabei::ErrorQueue::instance()->appendError(
......@@ -127,11 +127,11 @@ qint64 PolKitSQLiteConnection::getLastRowId()
if (!d->lastQueryDBus)
return d->connection->getLastRowId();
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusInterface iface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/sqlite"), QStringLiteral("org.chakraproject.akabeicorehelper.sqlite"), QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
QDBusMessage mes = iface.call("lastRowId");
QDBusMessage mes = iface.call(QStringLiteral("lastRowId"));
if (!mes.arguments().isEmpty())
return mes.arguments().first().toInt();
return -1;
......@@ -147,11 +147,11 @@ void PolKitSQLiteConnection::bind(QString const& key, int value)
//We bind to both databases, as we have no information yet if we have a read or write query
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusInterface iface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/sqlite"), QStringLiteral("org.chakraproject.akabeicorehelper.sqlite"), QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
QDBusMessage mes = iface.call("bind", key, value);
QDBusMessage mes = iface.call(QStringLiteral("bind"), key, value);
}
void PolKitSQLiteConnection::bind(QString const& key, QString const& value)
......@@ -164,11 +164,11 @@ void PolKitSQLiteConnection::bind(QString const& key, QString const& value)
//We bind to both databases, as we have no information yet if we have a read or write query
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusInterface iface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/sqlite"), QStringLiteral("org.chakraproject.akabeicorehelper.sqlite"), QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
QDBusMessage mes = iface.call("bind", key, value);
QDBusMessage mes = iface.call(QStringLiteral("bind"), key, value);
}
void PolKitSQLiteConnection::bind(QString const& key, QByteArray const& value)
......@@ -181,9 +181,9 @@ void PolKitSQLiteConnection::bind(QString const& key, QByteArray const& value)
//We bind to both databases, as we have no information yet if we have a read or write query
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusInterface iface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/sqlite"), QStringLiteral("org.chakraproject.akabeicorehelper.sqlite"), QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
QDBusMessage mes = iface.call("bind", key, value);
QDBusMessage mes = iface.call(QStringLiteral("bind"), key, value);
}
This diff is collapsed.
......@@ -17,7 +17,7 @@
#include <akabeicore_global.h>
#include "akabeierror.h"
struct QUuid;
class QUuid;
namespace Akabei {
class Delta;
class OperationRunner;
......
......@@ -124,7 +124,7 @@ void Cache::Private::init()
* Create a new list of cache entries with their full path.
*/
foreach (QString const& cacheFile, plainEntryList) {
if (!cacheFile.startsWith(".")) {
if (!cacheFile.startsWith(QLatin1String("."))) {
cacheFiles.append(cachedir.absoluteFilePath(cacheFile));
}
}
......@@ -155,8 +155,8 @@ QString Cache::getPathInCache(const QString &filename) const
* were requested a longer time ago (see the RemoveCriteria enumeration).
*/
struct utimbuf time;
time.modtime = QDateTime::currentDateTime().toTime_t();
time.actime = QDateTime::currentDateTime().toTime_t();
time.modtime = QDateTime::currentDateTimeUtc().toTime_t();
time.actime = QDateTime::currentDateTimeUtc().toTime_t();
std::string tmp = filename.toStdString();
utime(tmp.c_str(), &time);
......@@ -242,10 +242,10 @@ void Cache::cleanCache(MaxSizePolicy policy)
bool Cache::Private::cleanNotInstalled()
{
try {
SQLiteConnection database(databasedir.absoluteFilePath("local.db"), true);
SQLiteConnection database(databasedir.absoluteFilePath(QStringLiteral("local.db")), true);
foreach (QString const& file, cacheFiles) {
database.bind(":Filename", file.split("/").last());
SQLiteResource res = database.query( Queries::selectPackages("filename", "=", ":Filename") );
database.bind(QStringLiteral(":Filename"), file.split(QStringLiteral("/")).last());
SQLiteResource res = database.query( Queries::selectPackages(QStringLiteral("filename"), QStringLiteral("="), QStringLiteral(":Filename")) );
if (res.getRowsCount() == 0) {
if (!Helpers::removeFile(file)) {
error = QObject::tr("Failed to remove file!");
......@@ -254,7 +254,7 @@ bool Cache::Private::cleanNotInstalled()
}
}
} catch (SQLiteException &exc) {
qWarning() << "Caught an error with" << cachedir.absoluteFilePath("local.db") << ":" << exc.what();
qWarning() << "Caught an error with" << cachedir.absoluteFilePath(QStringLiteral("local.db")) << ":" << exc.what();
return false;
}
return true;
......@@ -297,7 +297,7 @@ bool Cache::Private::cleanAll()
foreach (QString const& file, plainEntryList) {
QString packageName = getPackageName(file);
if (file.startsWith(".") || keepPackages.contains(packageName)) {
if (file.startsWith(QLatin1String(".")) || keepPackages.contains(packageName)) {
continue;
}
......@@ -324,7 +324,7 @@ QString Cache::Private::getPackageName(const QString& filename)
}
pkgname += token;
pkgname += "-";
pkgname += QLatin1String("-");
}
pkgname.resize(pkgname.size() - 1);
......@@ -341,7 +341,7 @@ QString Cache::Private::getPackageVersion(const QString& filename)
}
pkgver += token;
pkgver += "-";
pkgver += QLatin1String("-");
}
pkgver.resize(pkgver.size() - 1);
......
......@@ -84,7 +84,7 @@ Config::Config()
{
Q_ASSERT(!s_globalConfig()->q);
s_globalConfig()->q = this;
setRoot("/");
setRoot(QStringLiteral("/"));
setCachePath(Akabei::DEFAULT_CACHE_DIR.toString());
setDatabasePath(Akabei::DEFAULT_DATABASE_DIR.toString());
}
......
This diff is collapsed.
......@@ -105,17 +105,17 @@ QString Delta::xdeltaApplyCommand(const QString& pathToDest) const
}
QString retstring;
if (d->pathToDelta.endsWith(".gz")) {
retstring = QString("xdelta3 -d -q -R -c -s %1 %2 | gzip -n > %3").arg(
if (d->pathToDelta.endsWith(QLatin1String(".gz"))) {
retstring = QStringLiteral("xdelta3 -d -q -R -c -s %1 %2 | gzip -n > %3").arg(
d->pathToOldFile,
d->pathToDelta,
pathToDest);
} else {
ArchiveHandler handle(d->pathToDelta);
QString deltaPath = Akabei::Config::instance()->rootDir().absoluteFilePath("tmp/" + d->pathToDelta.split('/').last().remove(".tar.xz"));
handle.extract(d->pathToDelta.split('/').last().remove(".tar.xz"), deltaPath, true);
QString deltaPath = Akabei::Config::instance()->rootDir().absoluteFilePath("tmp/" + d->pathToDelta.split('/').last().remove(QStringLiteral(".tar.xz")));
handle.extract(d->pathToDelta.split('/').last().remove(QStringLiteral(".tar.xz")), deltaPath, true);
retstring = QString("xdelta3 -d -q -s %1 %2 %3").arg(
retstring = QStringLiteral("xdelta3 -d -q -s %1 %2 %3").arg(
d->pathToOldFile,
deltaPath,
pathToDest);
......
......@@ -118,9 +118,11 @@ void ErrorQueue::appendError(const Error& error)
QWriteLocker locker(d->mutex);
d->errorQueue.enqueue(error);
foreach (ErrorHandler* registeredHandler, d->errorSlots.values( error.type() )) {
for (auto it = d->errorSlots.constFind( error.type() ), end = d->errorSlots.constEnd(); it != end && it.key() == error.type(); ++it ) {
ErrorHandler* registeredHandler = it.value();
QMetaObject::invokeMethod(registeredHandler->receiver(), registeredHandler->slot(), Qt::QueuedConnection);
}
}
void ErrorQueue::appendErrors(const Error::List& errors)
......@@ -245,4 +247,4 @@ Error::Type Error::type() const
return d->type;
}
}
\ No newline at end of file
}
......@@ -53,8 +53,8 @@ QList< Akabei::Package* > Group::packages() const
Q_D(const Group);
QReadLocker locker(d->mutex);
Helpers::PackageEventLoop e;
e.connect(Backend::instance(), SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)),
&e, SLOT(requestQuit(QUuid,QList<Akabei::Package*>)));
e.connect(Backend::instance(), &Backend::queryPackagesCompleted,
&e, &Helpers::PackageEventLoop::requestQuit);
e.setUuid( Backend::instance()->queryPackages( Queries::allPackagesInGroup(d->name) ) );
e.exec();
return e.result();
......@@ -65,8 +65,8 @@ QList< Package* > Group::search(const QString& token) const
Q_D(const Group);
QReadLocker locker(d->mutex);
Helpers::PackageEventLoop e;
e.connect(Backend::instance(), SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)),
&e, SLOT(requestQuit(QUuid,QList<Akabei::Package*>)));
e.connect(Backend::instance(), &Backend::queryPackagesCompleted,
&e, &Helpers::PackageEventLoop::requestQuit);
e.setUuid(Backend::instance()->queryPackages( Queries::packagesInGroup(d->name, token) ));
e.exec();
return e.result();
......
......@@ -8,6 +8,8 @@
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef AKABEIGROUP_P_H
#define AKABEIGROUP_P_H
#include <akabeigroup.h>
#include <QReadWriteLock>
......@@ -39,4 +41,5 @@ class GroupPrivate
friend class Group;
};
}
\ No newline at end of file
}
#endif
This diff is collapsed.
......@@ -53,7 +53,7 @@ QString Akabei::Hook::path()
if (d->file)
return d->file->fileName();
d->file = new QTemporaryFile(Config::instance()->rootDir().absoluteFilePath("tmp/akabei_XXXXXX"));
d->file = new QTemporaryFile(Config::instance()->rootDir().absoluteFilePath(QStringLiteral("tmp/akabei_XXXXXX")));
d->file->open();
QTextStream out(d->file);
out << d->content;
......
......@@ -18,24 +18,27 @@
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDebug>
#include <QGlobalStatic>
#include <syslog.h>
#include <iostream>
#include <fstream>
const void* Akabei::endlog = ( void* )-1;
/*
* Holds important configuration through different calls.
*/
namespace {
/* Necessary when polkit isn't involved */
static std::ofstream logStream;
Q_GLOBAL_STATIC(std::ofstream, logStream);
static bool isSyslog( false );
static QString pathToFile;
Q_GLOBAL_STATIC(QString, pathToFile);
/* Whether the init occurred correctly */
static bool systemInitialized( false );
static QString __msg_prefix[] = { "", "Warning: ", "Critical: " };
static QLatin1String __msg_prefix[] = { QLatin1String(""), QLatin1String("Warning: "), QLatin1String("Critical: ") };
static int __msg_priority[] = { LOG_INFO, LOG_WARNING, LOG_CRIT };
/*
......@@ -46,7 +49,7 @@ namespace {
*/
static bool permissionsNeeded()
{
Akabei::Helpers::Permissions access = Akabei::Helpers::permissionsOfPath(pathToFile);
Akabei::Helpers::Permissions access = Akabei::Helpers::permissionsOfPath(*pathToFile);
return (!isSyslog && !access.testFlag(Akabei::Helpers::WritePermission));
}
}
......@@ -87,10 +90,10 @@ public:
#pragma clang diagnostic pop
#endif
} else {
logStream << data.toStdString() << std::endl;
logStream.flush();
*logStream << data.toStdString() << std::endl;
logStream->flush();
if (logStream.bad()) {
if (logStream->bad()) {
qDebug() << "Log error: I/O error while writing";
}
}
......@@ -98,9 +101,9 @@ public:
} else {
/* Log through polkit */
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.logging.log")) {
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/logging", "org.chakraproject.akabeicorehelper.logging", QDBusConnection::systemBus());
QDBusMessage mes = iface.call("log", data);
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.logging.log"))) {
QDBusInterface iface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/logging"), QStringLiteral("org.chakraproject.akabeicorehelper.logging"), QDBusConnection::systemBus());
QDBusMessage mes = iface.call(QStringLiteral("log"), data);
if ( !mes.errorMessage().isEmpty() ) {
std::cerr << "Log error: an error occurred while logging via polkit" << std::endl;
......@@ -114,7 +117,7 @@ public:
QString getCurrentDateTime() const
{
return QDateTime::currentDateTime().toString("[dd/MM/yy hh:mm:ss] ");
return QDateTime::currentDateTime().toString(QStringLiteral("[dd/MM/yy hh:mm:ss] "));
}
QString data;
......@@ -123,7 +126,7 @@ public:
void AkabeiLogLine::initialize(bool syslog, const QString& filename)
{
pathToFile = filename;
*pathToFile = filename;
isSyslog = syslog;
if ( !permissionsNeeded() ) {
......@@ -132,10 +135,10 @@ void AkabeiLogLine::initialize(bool syslog, const QString& filename)
openlog("akabei", LOG_PID | LOG_CONS, LOG_USER); /* open connection for a generic user service */
systemInitialized = true;
} else {
pathToFile = filename;
logStream.open(filename.toUtf8().constData(), std::ios::app);
*pathToFile = filename;
logStream->open(filename.toUtf8().constData(), std::ios::app);
if (!logStream.is_open()) {
if (!logStream->is_open()) {
std::cerr << "Log error: couldn't open log file \"" << filename.toUtf8().constData() << "\" for writing." << std::endl;
} else {
systemInitialized = true;
......@@ -144,9 +147,9 @@ void AkabeiLogLine::initialize(bool syslog, const QString& filename)
} else {
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.logging.init")) {
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/logging", "org.chakraproject.akabeicorehelper.logging", QDBusConnection::systemBus());
QDBusMessage mes = iface.call("init", filename);
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.logging.init"))) {
QDBusInterface iface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/logging"), QStringLiteral("org.chakraproject.akabeicorehelper.logging"), QDBusConnection::systemBus());
QDBusMessage mes = iface.call(QStringLiteral("init"), filename);
if (mes.errorMessage().isEmpty()) {
systemInitialized = true;
......@@ -318,14 +321,14 @@ QString readLoggedActions(const QString &filter)
if (isSyslog)
return QString();
if (pathToFile.isEmpty()) {
if (pathToFile->isEmpty()) {
std::cerr << "Log error: logging system not initialized correctly. Cannot read from log." << std::endl;
return QString();
}
QString result;
QFile file(pathToFile);
QFile file(*pathToFile);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return QString();
......
......@@ -23,7 +23,7 @@
*/
namespace Akabei
{
static const void* endlog = ( void* )-1;
extern const void* endlog;
}
typedef enum __e_AkabeiLogLevel {
......@@ -93,4 +93,4 @@ AkabeiLogLine log();
QString readLoggedActions(const QString &filter);
#endif
\ No newline at end of file
#endif
......@@ -17,7 +17,7 @@
#include <akabeicore_global.h>
#include <akabeierror.h>
struct QUuid;
class QUuid;
class QStringList;
//FIXME: Do we need to make this thread-safe? Can it ever get access from 2 threads at the same time?
......
......@@ -275,14 +275,14 @@ void OperationRunnerPrivate::__k__connectToRunnerStatus()
q, SLOT(__k__errorsOccurred(Akabei::Error::List)), Qt::DirectConnection);
q->connect(runThread.data()->worker(), SIGNAL(runFinished(bool)),
q, SLOT(__k__finished(bool)), Qt::DirectConnection);
q->connect(runThread.data()->worker(), SIGNAL(phaseStarted(Akabei::Operation::Phase)),
q, SIGNAL(phaseStarted(Akabei::Operation::Phase)), Qt::DirectConnection);
q->connect(runThread.data()->worker(), SIGNAL(phaseFinished(Akabei::Operation::Phase)),
q, SIGNAL(phaseFinished(Akabei::Operation::Phase)), Qt::DirectConnection);
q->connect(runThread.data()->worker(), SIGNAL(operationStarted(Akabei::Operation *)),
q, SIGNAL(operationStarted(Akabei::Operation *)), Qt::DirectConnection);
q->connect(runThread.data()->worker(), SIGNAL(operationFinished(Akabei::Operation *)),
q, SIGNAL(operationFinished(Akabei::Operation *)), Qt::DirectConnection);
q->connect(runThread.data()->worker(), &RunnerWorker::phaseStarted,
q, &OperationRunner::phaseStarted, Qt::DirectConnection);
q->connect(runThread.data()->worker(), &RunnerWorker::phaseFinished,
q, &OperationRunner::phaseFinished, Qt::DirectConnection);
q->connect(runThread.data()->worker(), &RunnerWorker::operationStarted,
q, &OperationRunner::operationStarted, Qt::DirectConnection);
q->connect(runThread.data()->worker(), &RunnerWorker::operationFinished,
q, &OperationRunner::operationFinished, Qt::DirectConnection);
}
void OperationRunner::cancel()
......
This diff is collapsed.
......@@ -17,112 +17,112 @@ namespace Queries
QString selectGroups(const QString& property, const QString& comparison, const QString& value)
{
return QString("SELECT * FROM groups WHERE %1 %2 \"%3\";").arg(property, comparison, value);
return QStringLiteral("SELECT * FROM groups WHERE %1 %2 \"%3\";").arg(property, comparison, value);
}
QString selectGroupsNameOrDescription(const QString& token, const QString& comparison)
{
return QString("SELECT * FROM groups WHERE name %1 \"%2\" OR description %2 \"%3\";").arg(token, comparison, token);
return QStringLiteral("SELECT * FROM groups WHERE name %1 \"%2\" OR description %2 \"%3\";").arg(token, comparison, token);
}
QString selectPackages(const QString& property, const QString& comparison, const QString& value)
{
return QString("SELECT * FROM packages WHERE %1 %2 \"%3\";").arg(property, comparison, value);
return QStringLiteral("SELECT * FROM packages WHERE %1 %2 \"%3\";").arg(property, comparison, value);
}
QString selectPackagesNameOrDescription(const QString& token, const QString& comparison)
{
return QString("SELECT * FROM packages WHERE name %1 \"%2\" OR description %1 \"%2\";").arg(comparison, token);
return QStringLiteral("SELECT * FROM packages WHERE name %1 \"%2\" OR description %1 \"%2\";").arg(comparison, token);
}
QString selectHooks(const QString& property, const QString& comparison, const QString& value)
{
return QString("SELECT * FROM hooks WHERE %1 %2 \"%3\":").arg(property, comparison, value);
return QStringLiteral("SELECT * FROM hooks WHERE %1 %2 \"%3\":").arg(property, comparison, value);
}
QString selectDeltas(const QString& property, const QString& comparison, const QString& value)
{
return QString("SELECT * FROM deltas WHERE %1 %2 \"%3\";").arg(property, comparison, value);
return QStringLiteral("SELECT * FROM deltas WHERE %1 %2 \"%3\";").arg(property, comparison, value);
}
QString allPackages()
{
return QString("SELECT * FROM packages;");
return QStringLiteral("SELECT * FROM packages;");
}
QString allGroups()
{
return QString("SELECT * FROM groups;");
return QStringLiteral("SELECT * FROM groups;");
}
QString packageProperty(const QString& property, const QString& table, int packageId)
{
QString id = QString::number(packageId);
return QString("SELECT %1 FROM %2 WHERE package=\"%3\";").arg(property, table, id);
return QStringLiteral("SELECT %1 FROM %2 WHERE package=\"%3\";").arg(property, table, id);
}
QString packageHooks(int packageId)
{
QString id = QString::number(packageId);
return QString("SELECT * FROM belongshook JOIN hooks ON package=\"%1\" AND belongshook.hookname=hooks.name;").arg(id);
return QStringLiteral("SELECT * FROM belongshook JOIN hooks ON package=\"%1\" AND belongshook.hookname=hooks.name;").arg(id);
}
QString packagesFromHook(const QString& hook)
{
return QString("SELECT * FROM belongshook JOIN packages ON hookname=\"%1\" AND belongshook.package=packages.id;").arg(hook);
return QStringLiteral("SELECT * FROM belongshook JOIN packages ON hookname=\"%1\" AND belongshook.package=packages.id;").arg(hook);
}
QString packagesInGroup(const QString& group, const QString& token)
{
return QString("SELECT * FROM packages JOIN belongsgroup ON packages.id=belongsgroup.package WHERE belongsgroup.groupname=\"%1\" \
return QStringLiteral("SELECT * FROM packages JOIN belongsgroup ON packages.id=belongsgroup.package WHERE belongsgroup.groupname=\"%1\" \
AND (name LIKE \"%2\" OR description LIKE \"%2\");").arg(group, token);
}
QString belongsGroup(const QString& group, const QString& package)
{
return QString("SELECT * FROM belongsgroup JOIN groups ON groups.name=\"%1\" AND package=\"%2\";").arg(group, package);
return QStringLiteral("SELECT * FROM belongsgroup JOIN groups ON groups.name=\"%1\" AND package=\"%2\";").arg(group, package);
}
QString allPackagesInGroup(const QString& group)
{
return QString("SELECT * FROM packages JOIN belongsgroup ON packages.id=belongsgroup.package \
return QStringLiteral("SELECT * FROM packages JOIN belongsgroup ON packages.id=belongsgroup.package \
WHERE belongsgroup.groupname=\"%1\";").arg(group);
}
QString requiredByPackages(const QString& dependency)
{
return QString("SELECT packages.* FROM depends JOIN packages ON packages.id = depends.package \
return QStringLiteral("SELECT packages.* FROM depends JOIN packages ON packages.id = depends.package \
WHERE depends.dependency REGEXP \"%1\";").arg(dependency);
}
QString packageDependencies(const QString& dependency, const QString& comparison)
{
return QString("SELECT * FROM packages JOIN depends ON packages.id=depends.package WHERE depends.dependency %0 \"%1\";").arg(comparison, dependency);
return QStringLiteral("SELECT * FROM packages JOIN depends ON packages.id=depends.package WHERE depends.dependency %0 \"%1\";").arg(comparison, dependency);
}
QString globalReplaces()
{
return QString("SELECT * FROM replaces JOIN packages ON replaces.package = packages.id");
return QStringLiteral("SELECT * FROM replaces JOIN packages ON replaces.package = packages.id");
}
QString begin()
{
return QString("BEGIN;");
return QStringLiteral("BEGIN;");
}
QString commit()
{
return QString("COMMIT;");
return QStringLiteral("COMMIT;");
}
QString vacuum()
{
return QString("VACUUM;");
return QStringLiteral("VACUUM;");
}
QString rollback()
{
return QString("ROLLBACK;");
return QStringLiteral("ROLLBACK;");
}
}
......
......@@ -122,9 +122,12 @@ void RunnerWorker::processNextPhase()
break;
case Operation::Phase5:
//Now we need to move all ops back to the main app thread
foreach (QList<Operation*> ops, m_operations.values()) {
foreach (Operation * op, ops)
for (auto it = m_operations.constBegin(), end = m_operations.constEnd(); it != end; ++it) {
const auto ops = it.value();
for ( auto it2 = ops.constBegin(), end2 = ops.constEnd(); it2 != end2; ++it2 ) {
Operation* op = *it2;
op->moveToThread(QCoreApplication::instance()->thread());
}
}
// If we're here, we're successfully over.
emit runFinished(true);
......@@ -151,7 +154,7 @@ Akabei::Error::List RunnerWorker::runConcurrent(const QList< Operation* >& ops)
emit operationStarted(op);
QEventLoop e;
s_runFutureWatcher = new QFutureWatcher<void>;
connect(s_runFutureWatcher.data(), SIGNAL(finished()), &e, SLOT(quit()));
connect(s_runFutureWatcher.data(), &QFutureWatcherBase::finished, &e, &QEventLoop::quit);
QFuture< void > future = QtConcurrent::map(ops, RunnerWorker::runSingle);
s_runFutureWatcher.data()->setFuture(future);
e.exec();
......@@ -234,12 +237,17 @@ void RunnerRunnable::run()
//Don't parent, otherwise we break thread-affinity!!!
m_worker = new RunnerWorker(m_operations);
m_worker->moveToThread(m_thread);
foreach (QList<Operation*> ops, m_operations.values()) {
foreach (Operation * op, ops)
for (auto it = m_operations.constBegin(), end = m_operations.constEnd(); it != end; ++it) {
const auto ops = it.value();
for ( auto it2 = ops.constBegin(), end2 = ops.constEnd(); it2 != end2; ++it2 ) {
Operation* op = *it2;
op->moveToThread(m_thread);
}
}
emit ready();
QTimer::singleShot(0, m_worker, SLOT(run()));
QTimer::singleShot(0, m_worker, &RunnerWorker::run);
m_thread->start();
}
......
......@@ -142,10 +142,12 @@ void ValidatorWorker::processNextPhase()
break;
case Operation::Phase5:
//Now we need to move all ops back to the main app thread
foreach (QList<Operation*> ops, m_operations.values()) {
for (auto it = m_operations.constBegin(), end = m_operations.constEnd(); it != end; ++it ) {
const auto ops = it.value();
foreach (Operation * op, ops)
op->moveToThread(QCoreApplication::instance()->thread());
}
// If we're here, we're successfully over.
emit validationFinished(true, m_operations);
return;
......@@ -164,8 +166,8 @@ void ValidatorWorker::processNextPhase()
// Start the concurrent validation
QEventLoop e;
s_validateFutureWatcher = new QFutureWatcher<void>();
connect(s_validateFutureWatcher.data(), SIGNAL(finished()), &e, SLOT(quit()));
connect(s_validateFutureWatcher.data(), SIGNAL(progressValueChanged(int)), this, SLOT(streamValidationProgress(int)));
connect(s_validateFutureWatcher.data(), &QFutureWatcherBase::finished, &e, &QEventLoop::quit);
connect(s_validateFutureWatcher.data(), &QFutureWatcherBase::progressValueChanged, this, &ValidatorWorker::streamValidationProgress);
QFuture< void > future = QtConcurrent::map(processOps, concurrentValidate);
s_validateFutureWatcher.data()->setFuture(future);
e.exec();
......@@ -257,8 +259,8 @@ void ValidatorWorker::processNextPhase()
// The dependency is hereby missing. Is it resolvable? Let's see.
Helpers::PackageEventLoop loop;
connect(Backend::instance(), SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)),
&loop, SLOT(requestQuit(QUuid,QList<Akabei::Package*>)));
connect(Backend::instance(), &Backend::queryPackagesCompleted,
&loop, &Helpers::PackageEventLoop::requestQuit);
loop.setUuid(Backend::instance()->queryPackages(queryFromName(dependency.first)));
loop.exec();
Package *package = nullptr;
......@@ -337,7 +339,7 @@ void ValidatorWorker::processNextPhase()
foreach (const QString &target, op->conflictingTargets()) {
// if is a pkg to remove or replace skip the checks
bool skip = false;
foreach (const QString targetRemove, targetRemovals){
foreach (const QString& targetRemove, targetRemovals){
if(targetRemove.contains(target)) skip = true;
}
if (skip) continue;
......@@ -400,7 +402,7 @@ void ValidatorWorker::processNextPhase()
// Check if we are breaking dependencies somehow
foreach (const QString &target, targetRemovals) {
QString rT = Helpers::versionedTarget(target).first;
QString sql = Queries::packageDependencies(rT, "LIKE");
QString sql = Queries::packageDependencies(rT, QStringLiteral("LIKE"));
QList<Package*> ret = Backend::instance()->localDatabase()->queryPackages(sql);
// Iterate: we might have found targets that are not the ones we're looking for (due to version handling)
foreach (Package *p, ret) {
......@@ -467,13 +469,14 @@ void ValidatorRunnable::run()
//Don't use a parent here, otherwise we break thread affinity!!!
m_worker = new ValidatorWorker(m_operations);
m_worker->moveToThread(m_thread);
foreach (QList<Operation*> ops, m_operations.values()) {
for (auto it = m_operations.constBegin(), end = m_operations.constEnd(); it != end; ++it ) {
const auto ops = it.value();
foreach (Operation * op, ops)
op->moveToThread(m_thread);
}
emit ready();
// m_worker->run();
QTimer::singleShot(0, m_worker, SLOT(run()));
QTimer::singleShot(0, m_worker, &ValidatorWorker::run);
m_thread->start();
}
......
......@@ -17,18 +17,19 @@ int main(int argc, char *argv[])
#include <akabeiconfig.h>
#include <akabeibackend.h>
#include <akabeihelpers.h>
#include <akabeigroup.h>
void DatabaseBenchmark::benchmark_start()
{
Akabei::Config::instance()->setDatabasePath("/home/lukas/Development/buildroot/databases/");
Akabei::Config::instance()->setRoot("/home/lukas/Development/buildroot/_chroots/master-x32/");
Akabei::Config::instance()->setCachePath("/home/lukas/Development/buildroot/_cache-x32/");
Akabei::Config::instance()->setDatabasePath(QStringLiteral("/home/lukas/Development/buildroot/databases/"));
Akabei::Config::instance()->setRoot(QStringLiteral("/home/lukas/Development/buildroot/_chroots/master-x32/"));
Akabei::Config::instance()->setCachePath(QStringLiteral("/home/lukas/Development/buildroot/_cache-x32/"));
//Akabei::Config::instance()->setDatabases(QStringList() << "test1" << "test2");
QBENCHMARK_ONCE {
QEventLoop e;
connect(Akabei::Backend::instance(), SIGNAL(statusChanged(Akabei::Backend::Status)), &e, SLOT(quit()));
connect(Akabei::Backend::instance(), &Akabei::Backend::statusChanged, &e, &QEventLoop::quit);
Akabei::Backend::instance()->initialize();
e.exec();
}
......@@ -40,8 +41,8 @@ void DatabaseBenchmark::benchmark_start()
void DatabaseBenchmark::benchmark_QueryGroups()
{
GroupEventLoop e;
connect(Akabei::Backend::instance(), SIGNAL(queryGroupsCompleted(QUuid,QList<Akabei::Group*>)),
&e, SLOT(requestQuit(QUuid,QList<Akabei::Group*>)));
connect(Akabei::Backend::instance(), &Akabei::Backend::queryGroupsCompleted,
&e, &GroupEventLoop::requestQuit);
QBENCHMARK_ONCE {
e.setUuid(Akabei::Backend::instance()->groups());
......@@ -56,8 +57,8 @@ void DatabaseBenchmark::benchmark_QueryGroups()
void DatabaseBenchmark::benchmark_QueryPackages()
{
Akabei::Helpers::PackageEventLoop e;
connect(Akabei::Backend::instance(), SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)),
&e, SLOT(requestQuit(QUuid,QList<Akabei::Package*>)));
connect(Akabei::Backend::instance(), &Akabei::Backend::queryPackagesCompleted,
&e, &Akabei::Helpers::PackageEventLoop::requestQuit);
QBENCHMARK_ONCE {
e.setUuid(Akabei::Backend::instance()->packages());
......
......@@ -193,17 +193,16 @@ size_t ArchiveHandler::getEntrySize(QString const& fileName) const
size_t ArchiveHandler::totalEntrySize() const
{
size_t total = 0;
foreach (const QString& file, entries.keys()) {
for (auto it = entries.constBegin(), end = entries.constEnd(); it != end; ++it) {
const auto& file = it.key();
total += entries[file]->getFileSize();
}
return total;
}
bool ArchiveHandler::checkPackageValidity()
{
return (entries.find(".PKGINFO") != entries.end());
return (entries.find(QStringLiteral(".PKGINFO")) != entries.end());
}
void ArchiveHandler::handleEntries(Akabei::EntryHandlerFunctor& handler)
......@@ -230,7 +229,7 @@ void ArchiveHandler::handleEntries(Akabei::EntryHandlerFunctor& handler)
QString ArchiveHandler::readTextFile(const QString& textFile)
{
if (!entries.contains(textFile)) {
QString message = "ERROR: no such file in archive: %1";
QString message = QStringLiteral("ERROR: no such file in archive: %1");
throw ArchiveException(message.arg(textFile).toUtf8().data());
}
......@@ -506,7 +505,7 @@ bool InstallFunctor::operator()(const ArchiveEntry& currentEntry)
{
QString entryName = currentEntry.getFileName();
if (entryName == ".INSTALL" || entryName == ".PKGINFO" || entryName == ".MTREE" || entryName == ".Changelog")
if (entryName == QLatin1String(".INSTALL") || entryName == QLatin1String(".PKGINFO") || entryName == QLatin1String(".MTREE") || entryName == QLatin1String(".Changelog"))
return true;
OperationUtils utils;
......@@ -575,7 +574,7 @@ bool ReinstallUpgradeFunctor::operator()(const ArchiveEntry& currentEntry)
{
QString entryName = currentEntry.getFileName();
if (entryName == ".INSTALL" || entryName == ".PKGINFO")
if (entryName == QLatin1String(".INSTALL") || entryName == QLatin1String(".PKGINFO"))
return true;
OperationUtils utils;
......@@ -654,7 +653,7 @@ ExtractAllFunctor::ExtractAllFunctor(QString p, bool ow, Akabei::Operation *call
, pathPrefix(p)
, overwrite(ow)
{
if (!pathPrefix.endsWith("/")) {
if (!pathPrefix.endsWith(QLatin1String("/"))) {
pathPrefix.append("/");
}
}
......
......@@ -32,7 +32,7 @@ public:
handler = new ArchiveHandler(file);
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/archive", "org.chakraproject.akabeicorehelper.archive", QDBusConnection::systemBus());
iface = new QDBusInterface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/archive"), QStringLiteral("org.chakraproject.akabeicorehelper.archive"), QDBusConnection::systemBus());
}
~Private() {
delete handler;
......@@ -79,16 +79,18 @@ bool PolKitArchiveHandler::write(const QString& filename, const QHash<QString, Q
return ArchiveHandler::write(filename, files);
}
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.write")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.write"))) {
qDebug() << "Authorization granted";
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/archive", "org.chakraproject.akabeicorehelper.archive", QDBusConnection::systemBus());
QDBusInterface iface(QStringLiteral("org.chakraproject.akabeicorehelper"), QStringLiteral("/archive"), QStringLiteral("org.chakraproject.akabeicorehelper.archive"), QDBusConnection::systemBus());
iface.setProperty("filename", filename);
QVariantMap map;
foreach (const QString &k, files.keys())
for (auto it = files.constBegin(), end = files.constEnd(); it != end; ++it) {
const auto& k = it.key();
map.insert(k, files[k]);
QDBusMessage mes = iface.call("write", map);
}
QDBusMessage mes = iface.call(QStringLiteral("write"), map);
return !mes.arguments().isEmpty() && mes.arguments().first().toBool();
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();//TODO:Error handling
......@@ -103,11 +105,11 @@ QStringList PolKitArchiveHandler::getEntries() const
if (!Akabei::Config::instance()->needsPrivileges() || d->readLocally)
return d->handler->getEntries();
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call("entries");
QDBusMessage mes = d->iface->call(QStringLiteral("entries"));
if (!mes.arguments().isEmpty())
return mes.arguments().first().toStringList();
} else {
......@@ -122,11 +124,11 @@ size_t PolKitArchiveHandler::getEntrySize(QString const& fileName) const
if (!Akabei::Config::instance()->needsPrivileges() || d->readLocally)
return d->handler->getEntrySize(fileName);
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call("entrySize", fileName);
QDBusMessage mes = d->iface->call(QStringLiteral("entrySize"), fileName);
if (!mes.arguments().isEmpty())
return mes.arguments().first().toInt();
} else {
......@@ -142,11 +144,11 @@ size_t PolKitArchiveHandler::totalEntrySize() const
if (!Akabei::Config::instance()->needsPrivileges() || d->readLocally)
return d->handler->totalEntrySize();
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call("totalEntrySize");
QDBusMessage mes = d->iface->call(QStringLiteral("totalEntrySize"));
if (!mes.arguments().isEmpty())
return mes.arguments().first().toInt();
} else {
......@@ -162,11 +164,11 @@ QString PolKitArchiveHandler::readTextFile(const QString &file)
if (!Akabei::Config::instance()->needsPrivileges() || d->readLocally)
return d->handler->readTextFile(file);
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call("readTextFile", file);
QDBusMessage mes = d->iface->call(QStringLiteral("readTextFile"), file);
if (!mes.arguments().isEmpty())
return mes.arguments().first().toString();
} else {
......@@ -182,11 +184,11 @@ void PolKitArchiveHandler::extract(const QString& source, const QString& destNam
if (!Akabei::Config::instance()->needsPrivileges())
return d->handler->extract(source, destName, overwrite);
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.extract")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.extract"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call("extract", source, destName, overwrite);
QDBusMessage mes = d->iface->call(QStringLiteral("extract"), source, destName, overwrite);
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();
Akabei::ErrorQueue::instance()->appendError(Akabei::Error(Akabei::Error::PermissionError, PolkitQt1::Authority::instance()->errorDetails()));
......@@ -198,11 +200,11 @@ void PolKitArchiveHandler::extract(const ArchiveEntry &entry, const QString& des
if (!Akabei::Config::instance()->needsPrivileges())
return d->handler->extract(entry, destName, overwrite);
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.extract")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.extract"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call("extract", entry.getFileName(), destName, overwrite);
QDBusMessage mes = d->iface->call(QStringLiteral("extract"), entry.getFileName(), destName, overwrite);
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();
Akabei::ErrorQueue::instance()->appendError(Akabei::Error(Akabei::Error::PermissionError, PolkitQt1::Authority::instance()->errorDetails()));
......@@ -214,11 +216,11 @@ void PolKitArchiveHandler::extractAll(const QString& pathPrefix, bool overwrite)
if (!Akabei::Config::instance()->needsPrivileges())
return d->handler->extractAll(pathPrefix, overwrite);
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.extract")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.extract"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call("extractAll", pathPrefix, overwrite);
QDBusMessage mes = d->iface->call(QStringLiteral("extractAll"), pathPrefix, overwrite);
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();
Akabei::ErrorQueue::instance()->appendError(Akabei::Error(Akabei::Error::PermissionError, PolkitQt1::Authority::instance()->errorDetails()));
......@@ -230,11 +232,11 @@ QList<QByteArray> PolKitArchiveHandler::md5(const QStringList& files)
if (!Akabei::Config::instance()->needsPrivileges() || d->readLocally)
return d->handler->md5(files);
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call("md5", files);
QDBusMessage mes = d->iface->call(QStringLiteral("md5"), files);
if (!mes.arguments().isEmpty())
return mes.arguments().first().value< QList<QByteArray> >();
} else {
......@@ -250,11 +252,11 @@ QByteArray PolKitArchiveHandler::md5(const QString &file)
return d->handler->md5(file);
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read")) {
if (Akabei::Helpers::checkAuthorizationSync(QStringLiteral("org.chakraproject.akabeicorehelper.archive.read"))) {
qDebug() << "Authorization granted";
d->iface->setProperty("filename", d->filename);
QDBusMessage mes = d->iface->call("md5", file);
QDBusMessage mes = d->iface->call(QStringLiteral("md5"), file);
if (!mes.arguments().isEmpty())
return mes.arguments().first().toByteArray();
} else {
......@@ -269,7 +271,7 @@ bool PolKitArchiveHandler::checkPackageValidity()
if (!Akabei::Config::instance()->needsPrivileges() || d->readLocally)
return d->handler->checkPackageValidity();
return !readTextFile(".PKGINFO").isEmpty();
return !readTextFile(QStringLiteral(".PKGINFO")).isEmpty();
}
Akabei::Error::List PolKitArchiveHandler::errors()
......
......@@ -29,19 +29,19 @@ bool OperationUtils::validatePackage(Akabei::Package *package)
// First, let's check if the archive actually exists and it’s valid.
if (!QFile::exists(package->pathToArchive())) {
// Utter fail.
m_errorMessage = "Archive was not found on disk!";
m_errorMessage = QStringLiteral("Archive was not found on disk!");
return false;
}
// Now let’s check the file integrity (md5 and stuff).
if (!package->checkMD5Sum()) {
m_errorMessage = "MD5Sum of archive not correct!";
m_errorMessage = QStringLiteral("MD5Sum of archive not correct!");
return false;
}
// Ok, now let’s check that we are actually able to load the archive.
if (!package->checkArchiveValidity()) {
m_errorMessage = "Archive is not valid.";
m_errorMessage = QStringLiteral("Archive is not valid.");
return false;
}
......
......@@ -59,7 +59,7 @@ PlainHookOperation *PlainHookOperation::instance()
}
PlainHookOperation::PlainHookOperation()
: Operation("Hooks"),
: