Commit abc614de authored by Lukas Appelhans's avatar Lukas Appelhans

Revert "whitespace; create-db syntax change for now; todo--;"

This reverts commit 8e6b481f.
parent fb951f2d
This diff is collapsed.
...@@ -11,15 +11,12 @@ ...@@ -11,15 +11,12 @@
#ifndef AKABEIBACKEND_H #ifndef AKABEIBACKEND_H
#define AKABEIBACKEND_H #define AKABEIBACKEND_H
#include <QObject> #include <QtCore/QObject>
#include "akabeicore_global.h" #include "akabeicore_global.h"
class QUuid; class QUuid;
namespace Akabei { namespace Akabei {
class Delta; class Delta;
class OperationRunner; class OperationRunner;
class Group; class Group;
...@@ -27,7 +24,6 @@ class Package; ...@@ -27,7 +24,6 @@ class Package;
class Database; class Database;
class BackendPrivate; class BackendPrivate;
class AKABEICORESHARED_EXPORT Backend : public QObject class AKABEICORESHARED_EXPORT Backend : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -42,13 +38,12 @@ class AKABEICORESHARED_EXPORT Backend : public QObject ...@@ -42,13 +38,12 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
StatusOnTransaction = 4, StatusOnTransaction = 4,
StatusBroken = 5 StatusBroken = 5
}; };
static Backend *instance();
static Backend* instance();
virtual ~Backend(); virtual ~Backend();
Status status() const; Status status() const;
Database* localDatabase(); Database *localDatabase();
QList<Database*> databases(); QList<Database*> databases();
QUuid packages(); QUuid packages();
...@@ -60,11 +55,11 @@ class AKABEICORESHARED_EXPORT Backend : public QObject ...@@ -60,11 +55,11 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
QUuid queryPackages(const QString &sql); QUuid queryPackages(const QString &sql);
QUuid queryGroups(const QString &sql); QUuid queryGroups(const QString &sql);
OperationRunner* operationRunner(); OperationRunner *operationRunner();
Package* loadPackageFromFile(const QString &path); Package *loadPackageFromFile(const QString &path);
Delta* loadDeltaFromFile(const QString &path); Delta *loadDeltaFromFile(const QString &path);
Group* loadGroupFromFile(const QString &path); Group *loadGroupFromFile(const QString &path);
public Q_SLOTS: public Q_SLOTS:
void initialize(); void initialize();
...@@ -77,9 +72,9 @@ class AKABEICORESHARED_EXPORT Backend : public QObject ...@@ -77,9 +72,9 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
private: private:
Backend(QObject* parent = 0); Backend(QObject* parent = 0);
BackendPrivate* const d_ptr; BackendPrivate * const d_ptr;
Q_PRIVATE_SLOT(d_func(), void _initializationFinished()) Q_PRIVATE_SLOT(d_func(), void __k__initializationFinished())
friend class DatabasePrivate; friend class DatabasePrivate;
friend class Config; friend class Config;
......
...@@ -11,15 +11,15 @@ ...@@ -11,15 +11,15 @@
#ifndef AKABEIBACKEND_P_H #ifndef AKABEIBACKEND_P_H
#define AKABEIBACKEND_P_H #define AKABEIBACKEND_P_H
#include <QFileSystemWatcher>
#include <QFutureWatcher>
#include <QUuid>
#include "akabeibackend.h" #include "akabeibackend.h"
#include "akabeioperationrunner.h"
#include <QtCore/QFileSystemWatcher>
#include <QtCore/QFutureWatcher>
#include <QtCore/QUuid>
#include "akabeioperationrunner.h"
namespace Akabei { namespace Akabei
{
class GroupPool class GroupPool
{ {
...@@ -41,7 +41,7 @@ class BackendPrivate : public QObject ...@@ -41,7 +41,7 @@ class BackendPrivate : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_DECLARE_PUBLIC(Backend) Q_DECLARE_PUBLIC(Backend)
Backend* const q_ptr; Backend * const q_ptr;
public: public:
BackendPrivate(Backend *p) BackendPrivate(Backend *p)
...@@ -57,7 +57,7 @@ class BackendPrivate : public QObject ...@@ -57,7 +57,7 @@ class BackendPrivate : public QObject
Backend::Status status; Backend::Status status;
Database* localDatabase; Database *localDatabase;
QList<Database*> databases; QList<Database*> databases;
QFileSystemWatcher *fsWatcher; QFileSystemWatcher *fsWatcher;
...@@ -69,7 +69,7 @@ class BackendPrivate : public QObject ...@@ -69,7 +69,7 @@ class BackendPrivate : public QObject
OperationRunner *runner; OperationRunner *runner;
void _initializationFinished(); void __k__initializationFinished();
QHash<QString, Database*> performInitialization(); QHash<QString, Database*> performInitialization();
void setStatus(Backend::Status status); void setStatus(Backend::Status status);
......
...@@ -8,16 +8,16 @@ ...@@ -8,16 +8,16 @@
version 2 of the License, or (at your option) any later version. version 2 of the License, or (at your option) any later version.
*/ */
#include <qglobal.h> #include "akabeiconfig.h"
#include <QDir>
#include "akabeibackend.h" #include "akabeibackend.h"
#include "akabeibackend_p.h" #include "akabeibackend_p.h"
#include "akabeiconfig.h" #include <qglobal.h>
#include <QtCore/QDir>
namespace Akabei { namespace Akabei
{
class Config::Private class Config::Private
{ {
...@@ -41,8 +41,9 @@ class ConfigHelper ...@@ -41,8 +41,9 @@ class ConfigHelper
{ {
public: public:
ConfigHelper() : q(0) {} ConfigHelper() : q(0) {}
~ConfigHelper() { delete q; } ~ConfigHelper() {
delete q;
}
Config *q; Config *q;
}; };
...@@ -50,7 +51,9 @@ Q_GLOBAL_STATIC(ConfigHelper, s_globalConfig) ...@@ -50,7 +51,9 @@ Q_GLOBAL_STATIC(ConfigHelper, s_globalConfig)
Config *Config::instance() Config *Config::instance()
{ {
if (!s_globalConfig()->q) { new Config; } if (!s_globalConfig()->q) {
new Config;
}
return s_globalConfig()->q; return s_globalConfig()->q;
} }
...@@ -61,8 +64,8 @@ Config::Config() ...@@ -61,8 +64,8 @@ Config::Config()
Q_ASSERT(!s_globalConfig()->q); Q_ASSERT(!s_globalConfig()->q);
s_globalConfig()->q = this; s_globalConfig()->q = this;
setRoot("/"); setRoot("/");
setCachePath("/var/cache/akabei"); setCachePath(Akabei::DEFAULT_CACHE_DIR.toString());
setDatabasePath("/var/akabei"); setDatabasePath(Akabei::DEFAULT_DATABASE_DIR.toString());
} }
Config::~Config() Config::~Config()
......
...@@ -13,17 +13,15 @@ ...@@ -13,17 +13,15 @@
#include <akabeicore_global.h> #include <akabeicore_global.h>
class QDir;
class QString; class QString;
class QStringList; class QStringList;
class QDir;
namespace Akabei { namespace Akabei {
class AKABEICORESHARED_EXPORT Config class AKABEICORESHARED_EXPORT Config
{ {
public: public:
static Config* instance(); static Config *instance();
~Config(); ~Config();
QString root() const; QString root() const;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#ifndef AKABEICORE_GLOBAL_H #ifndef AKABEICORE_GLOBAL_H
#define AKABEICORE_GLOBAL_H #define AKABEICORE_GLOBAL_H
#include <qglobal.h> #include <QtCore/qglobal.h>
#include <QUrl> #include <QUrl>
#if defined(AKABEICORE_LIBRARY) #if defined(AKABEICORE_LIBRARY)
...@@ -20,47 +20,51 @@ ...@@ -20,47 +20,51 @@
# define AKABEICORESHARED_EXPORT Q_DECL_IMPORT # define AKABEICORESHARED_EXPORT Q_DECL_IMPORT
#endif #endif
// Define column numbers
namespace Akabei { namespace Akabei {
namespace Tables { namespace Tables {
namespace Packages { namespace Packages {
const int ID = 0; const int ID = 0;
const int NAME = 1; const int NAME = 1;
const int VERSION = 2; const int VERSION = 2;
const int FILENAME = 3; const int FILENAME = 3;
const int DESCRIPTION = 4; const int DESCRIPTION = 4;
const int GROUPS = 5; const int GROUPS = 5;
const int SIZE = 6; const int SIZE = 6;
const int INSTALLEDSIZE = 7; const int INSTALLEDSIZE = 7;
const int MD5SUM = 8; const int MD5SUM = 8;
const int URL = 9; const int URL = 9;
const int BUILDDATE = 10; const int BUILDDATE = 10;
const int ARCH = 11; const int ARCH = 11;
const int PACKAGER = 12; const int PACKAGER = 12;
const int PROVIDES = 13; const int PROVIDES = 13;
const int CONFLICTS = 14; const int CONFLICTS = 14;
const int DEPENDS = 15; const int DEPENDS = 15;
const int OPTDEPENDS = 16; const int OPTDEPENDS = 16;
const int REPLACES = 17; const int REPLACES = 17;
const int BACKUP = 18; const int BACKUP = 18;
const int LICENSE = 19; const int LICENSE = 19;
const int PROVIDESMIMETYPE = 20; const int PROVIDESMIMETYPE = 20;
const int FLAGS = 21; const int FLAGS = 21;
const int SCREENSHOTURL = 22; const int SCREENSHOTURL = 22;
const int INSTALLREASON = 23; const int INSTALLREASON = 23;
const int INSTALLDATE = 24; const int INSTALLDATE = 24;
} }
namespace Groups {
const int ID = 0;
const int NAME = 1;
const int DESCRIPTION = 2;
const int ICONNAME = 3;
}
namespace Groups { }
const int ID = 0;
const int NAME = 1;
const int DESCRIPTION = 2;
const int ICONNAME = 3;
}
} const QUrl DEFAULT_DATABASE_DIR = QUrl("/var/local/akabei");
const QUrl DEFAULT_CACHE_DIR = QUrl("/var/cache/akabei");
} }
......
...@@ -8,15 +8,14 @@ ...@@ -8,15 +8,14 @@
version 2 of the License, or (at your option) any later version. version 2 of the License, or (at your option) any later version.
*/ */
#include <sqlite3.h> #include "akabeidatabase_p.h"
#include "akabeipackage_p.h" #include "akabeipackage_p.h"
#include "akabeigroup_p.h" #include "akabeigroup_p.h"
#include "akabeibackend_p.h" #include "akabeibackend_p.h"
#include "akabeihelpers_p.h" #include "akabeihelpers_p.h"
#include "akabeidatabase_p.h" #include <sqlite3.h>
namespace Akabei { namespace Akabei {
...@@ -37,16 +36,18 @@ void DatabasePrivate::init() ...@@ -37,16 +36,18 @@ void DatabasePrivate::init()
{ {
if (dbHandle) if (dbHandle)
sqlite3_close(dbHandle); sqlite3_close(dbHandle);
// Try opening the db read only
int result = sqlite3_open16(pathToDb.constData(), &dbHandle); int result = sqlite3_open16(pathToDb.constData(), &dbHandle);
switch (result) { switch (result) {
case SQLITE_OK: case SQLITE_OK:
break; // Everything went fine and the handle is ready
default: break;
dbHandle = 0; default:
break; // Errors. Set the handle to 0
dbHandle = 0;
break;
} }
// Populate group cache on startup
populateGroupCache(); populateGroupCache();
} }
...@@ -62,38 +63,42 @@ void DatabasePrivate::populateGroupCache() ...@@ -62,38 +63,42 @@ void DatabasePrivate::populateGroupCache()
QString sql = "SELECT * FROM groups"; QString sql = "SELECT * FROM groups";
sqlite3_stmt *statement = 0; sqlite3_stmt *statement = 0;
int result = sqlite3_prepare16_v2(dbHandle, sql.constData(), int result = sqlite3_prepare16_v2(dbHandle, sql.constData(), (sql.size() + 1) * sizeof(QChar),
(sql.size() + 1) * sizeof(QChar),
&statement, 0); &statement, 0);
switch (result) { switch (result) {
case SQLITE_OK: case SQLITE_OK:
break; // Everything went fine and the handle is ready
default: break;
return; default:
break; // Errors. Take action here
return;
break;
} }
while (sqlite3_step(statement) == SQLITE_ROW) { while (sqlite3_step(statement) == SQLITE_ROW) {
Group *group = groupFromRow(statement); Group * group = groupFromRow(statement);
groupCache[group->name()] = group; groupCache[group->name()] = group;
} }
result = sqlite3_finalize(statement); sqlite3_finalize(statement);
} }
Group* DatabasePrivate::groupFromRow(sqlite3_stmt* stmt) Group *DatabasePrivate::groupFromRow(sqlite3_stmt *stmt)
{ {
using namespace Tables::Groups; using namespace Tables::Groups;
QString name = QSTRING_FROM_DB(stmt, NAME); QString name = QSTRING_FROM_DB(stmt, NAME);
// Is our group still not into the pool?
if (!Backend::instance()->d_func()->groupPool->contains(name)) { if (!Backend::instance()->d_func()->groupPool->contains(name)) {
Group* group = Backend::instance()->d_func()->groupPool->group(name); // In this case, populate its fields
Group *group = Backend::instance()->d_func()->groupPool->group(name);
group->d_ptr->desc = QSTRING_FROM_DB(stmt, DESCRIPTION); group->d_ptr->desc = QSTRING_FROM_DB(stmt, DESCRIPTION);
group->d_ptr->icon = QSTRING_FROM_DB(stmt, ICONNAME); group->d_ptr->icon = QSTRING_FROM_DB(stmt, ICONNAME);
} }
// Return the group from the pool
return Backend::instance()->d_func()->groupPool->group(name); return Backend::instance()->d_func()->groupPool->group(name);
} }
...@@ -103,12 +108,16 @@ Package *DatabasePrivate::packageFromRow(sqlite3_stmt *stmt) ...@@ -103,12 +108,16 @@ Package *DatabasePrivate::packageFromRow(sqlite3_stmt *stmt)
int id = sqlite3_column_int(stmt, Tables::Packages::ID); int id = sqlite3_column_int(stmt, Tables::Packages::ID);
// Does the cache contain our package?
if (packageCache.contains(id)) { if (packageCache.contains(id)) {
// Simply return it
return packageCache[id]; return packageCache[id];
} }
using namespace Tables::Packages; // Otherwise go ahead, create the package, add it to the cache, and return it.
using namespace Tables::Packages;
// We suppose the statement is actually valid. So let's create our package.
Package *package = new Package(q, id, QSTRING_FROM_DB(stmt, NAME)); Package *package = new Package(q, id, QSTRING_FROM_DB(stmt, NAME));
package->d_func()->arch = QSTRING_FROM_DB(stmt, ARCH); package->d_func()->arch = QSTRING_FROM_DB(stmt, ARCH);
...@@ -119,7 +128,7 @@ Package *DatabasePrivate::packageFromRow(sqlite3_stmt *stmt) ...@@ -119,7 +128,7 @@ Package *DatabasePrivate::packageFromRow(sqlite3_stmt *stmt)
package->d_func()->md5sum = QSTRING_FROM_DB(stmt, MD5SUM).toUtf8(); package->d_func()->md5sum = QSTRING_FROM_DB(stmt, MD5SUM).toUtf8();
package->d_func()->mimetypes = Helpers::stringlistFromDb(stmt, PROVIDESMIMETYPE); package->d_func()->mimetypes = Helpers::stringlistFromDb(stmt, PROVIDESMIMETYPE);
package->d_func()->packager = QSTRING_FROM_DB(stmt, PACKAGER); package->d_func()->packager = QSTRING_FROM_DB(stmt, PACKAGER);
package->d_func()->provides = Helpers::stringlistFromDb(stmt, PROVIDES); package->d_func()->providers = Helpers::stringlistFromDb(stmt, PROVIDES);
package->d_func()->size = sqlite3_column_int64(stmt, SIZE); package->d_func()->size = sqlite3_column_int64(stmt, SIZE);
package->d_func()->isize = sqlite3_column_int64(stmt, INSTALLEDSIZE); package->d_func()->isize = sqlite3_column_int64(stmt, INSTALLEDSIZE);
package->d_func()->url = QUrl(QSTRING_FROM_DB(stmt, URL)); package->d_func()->url = QUrl(QSTRING_FROM_DB(stmt, URL));
...@@ -132,18 +141,23 @@ Package *DatabasePrivate::packageFromRow(sqlite3_stmt *stmt) ...@@ -132,18 +141,23 @@ Package *DatabasePrivate::packageFromRow(sqlite3_stmt *stmt)
package->d_func()->license = QSTRING_FROM_DB(stmt, LICENSE); package->d_func()->license = QSTRING_FROM_DB(stmt, LICENSE);
package->d_func()->replaces = Helpers::stringlistFromDb(stmt, REPLACES); package->d_func()->replaces = Helpers::stringlistFromDb(stmt, REPLACES);
// Install Reason (if any)
switch (sqlite3_column_int(stmt, INSTALLREASON)) { switch (sqlite3_column_int(stmt, INSTALLREASON)) {
case 1: case 1:
// Explicit
package->d_func()->reason = Package::ExplicitlyInstalledReason; package->d_func()->reason = Package::ExplicitlyInstalledReason;
break; break;
case 2: case 2:
// Dependency
package->d_func()->reason = Package::InstalledAsDependencyReason; package->d_func()->reason = Package::InstalledAsDependencyReason;
break; break;
default: default:
// No reason
package->d_func()->reason = Package::NoReason; package->d_func()->reason = Package::NoReason;
break; break;
} }
// Groups
foreach (const QString &group, QSTRING_FROM_DB(stmt, GROUPS).split(';')) { foreach (const QString &group, QSTRING_FROM_DB(stmt, GROUPS).split(';')) {
if (group.isEmpty()) if (group.isEmpty())
continue; continue;
...@@ -152,44 +166,52 @@ Package *DatabasePrivate::packageFromRow(sqlite3_stmt *stmt) ...@@ -152,44 +166,52 @@ Package *DatabasePrivate::packageFromRow(sqlite3_stmt *stmt)
} }
} }
// Check if it has a scriptlet
package->d_func()->hasScriptlet = false; package->d_func()->hasScriptlet = false;
QString sql = "SELECT * FROM scriptlets WHERE Package=" + QString::number(id); QString sql = "SELECT * FROM scriptlets WHERE Package=" + QString::number(id);
sqlite3_stmt *statement = 0; sqlite3_stmt *statement = 0;
int result = sqlite3_prepare16_v2(dbHandle, sql.constData(), int result = sqlite3_prepare16_v2(dbHandle, sql.constData(), (sql.size() + 1) * sizeof(QChar),
(sql.size() + 1) * sizeof(QChar),
&statement, 0); &statement, 0);
switch (result) { switch (result) {
case SQLITE_OK: case SQLITE_OK:
break; // Everything went fine and the handle is ready
default: break;
break; default:
break;
} }
if (sqlite3_step(statement) == SQLITE_ROW) { if (sqlite3_step(statement) == SQLITE_ROW) {
// There is one
package->d_func()->hasScriptlet = true; package->d_func()->hasScriptlet = true;
} }
sqlite3_finalize(statement); sqlite3_finalize(statement);
// Check if it has any hooks
package->d_func()->hasHooks = false; package->d_func()->hasHooks = false;
sql = "SELECT * FROM hooks WHERE Packages LIKE \"%;" + QString::number(id) + ";%\""; sql = "SELECT * FROM hooks WHERE Packages LIKE \"%;" + QString::number(id) + ";%\"";
statement = 0; statement = 0;
result = sqlite3_prepare16_v2(dbHandle, sql.constData(), result = sqlite3_prepare16_v2(dbHandle, sql.constData(), (sql.size() + 1) * sizeof(QChar),
(sql.size() + 1) * sizeof(QChar),
&statement, 0); &statement, 0);
switch (result) { switch (result) {
case SQLITE_OK: case SQLITE_OK:
break; // Everything went fine and the handle is ready
default: break;
break; default:
break;
} }
if (sqlite3_step(statement) == SQLITE_ROW) { if (sqlite3_step(statement) == SQLITE_ROW) {
// There is one
package->d_func()->hasHooks = true; package->d_func()->hasHooks = true;
} }
sqlite3_finalize(statement); sqlite3_finalize(statement);
// Attempt loading the archive from cache, if any
// package->d_func()->attemptLoadFromCache();
// Add the package to the cache
packageCache[id] = package; packageCache[id] = package;
return package; return package;
...@@ -237,20 +259,22 @@ QList<Package*> Database::queryPackages(const QString &sql) ...@@ -237,20 +259,22 @@ QList<Package*> Database::queryPackages(const QString &sql)
{ {
Q_D(Database); Q_D(Database);
// Shield us from multithreaded disaster
QMutexLocker locker(d->mutex); QMutexLocker locker(d->mutex);