Commit cda1a0c5 authored by Dario Freddi's avatar Dario Freddi

Start delta implementation

Signed-off-by: default avatarDario Freddi <drf@kde.org>
parent e062ada0
...@@ -23,7 +23,8 @@ CREATE TABLE packages ( ...@@ -23,7 +23,8 @@ CREATE TABLE packages (
"Flags" TEXT, "Flags" TEXT,
"ScreenShotURL" TEXT, "ScreenShotURL" TEXT,
"InstallReason" TEXT, "InstallReason" TEXT,
"InstallDate" INTEGER); "InstallDate" INTEGER
);
CREATE INDEX "id" on packages (ID ASC); CREATE INDEX "id" on packages (ID ASC);
CREATE INDEX "name" on packages (Name ASC); CREATE INDEX "name" on packages (Name ASC);
CREATE TABLE "files" ( CREATE TABLE "files" (
...@@ -46,3 +47,10 @@ CREATE TABLE "groups" ( ...@@ -46,3 +47,10 @@ CREATE TABLE "groups" (
"Description" TEXT, "Description" TEXT,
"IconName" TEXT "IconName" TEXT
); );
CREATE TABLE "deltas" (
"ID" INTEGER PRIMARY KEY AUTOINCREMENT,
"Package" INTEGER,
"VersionFrom" TEXT,
"VersionTo" TEXT,
"MD5SUM" TEXT
);
...@@ -7,6 +7,7 @@ include_directories( ...@@ -7,6 +7,7 @@ include_directories(
set(AKABEI_CORE_SRCS set(AKABEI_CORE_SRCS
akabeibackend.cpp akabeibackend.cpp
akabeiconfig.cpp akabeiconfig.cpp
akabeidelta.cpp
akabeidatabase.cpp akabeidatabase.cpp
akabeierror.cpp akabeierror.cpp
akabeigroup.cpp akabeigroup.cpp
......
/*
This file is part of the Chakra project
Copyright (C) 2010 Dario Freddi <drf@chakra-project.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include "akabeidelta_p.h"
#include "akabeihelpers_p.h"
namespace Akabei
{
Delta::Delta(const QString& targetName, const QString& versionFrom, const QString& versionTo)
: d_ptr(new DeltaPrivate(targetName, versionFrom, versionTo))
{
}
Delta::~Delta()
{
delete d_ptr;
}
bool Delta::checkMD5Sum()
{
Q_D(Delta);
if (d->_p_md5checked) {
return true;
}
// Check integrity
if (Helpers::md5sumOfFile(d->pathToDelta) != d->md5sum) {
d->_p_md5checked = false;
} else {
d->_p_md5checked = true;
}
return d->_p_md5checked;
}
QString Delta::filename() const
{
Q_D(const Delta);
return d->filename;
}
QString Delta::filenameFrom() const
{
Q_D(const Delta);
return d->filenameFrom;
}
QByteArray Delta::md5sum() const
{
Q_D(const Delta);
return d->md5sum;
}
QString Delta::pathToDelta() const
{
Q_D(const Delta);
return d->pathToDelta;
}
QString Delta::pathToSource() const
{
Q_D(const Delta);
return d->pathToOldFile;
}
void Delta::setPathToDelta(const QString& path)
{
Q_D(Delta);
d->pathToDelta = path;
}
void Delta::setPathToSource(const QString& path)
{
Q_D(Delta);
d->pathToOldFile = path;
}
QString Delta::targetName() const
{
Q_D(const Delta);
return d->name;
}
QString Delta::versionFrom() const
{
Q_D(const Delta);
return d->vFrom;
}
QString Delta::versionTo() const
{
Q_D(const Delta);
return d->vTo;
}
QString Delta::xdeltaApplyCommand(const QString& pathToDest) const
{
Q_D(const Delta);
if (pathToDest.isEmpty() || d->pathToDelta.isEmpty() || d->pathToOldFile.isEmpty()) {
return QString();
}
QString retstring;
if (d->pathToDelta.endsWith(".gz")) {
retstring = QString("xdelta3 -d -q -R -c -s %1 %2 | gzip -n > %3")
.arg(d->pathToOldFile).arg(d->pathToDelta).arg(pathToDest);
} else {
retstring = QString("xdelta3 -d -q -s %1 %2 %3").arg(d->pathToOldFile).arg(d->pathToDelta).arg(pathToDest);
}
return retstring;
}
}
/*
This file is part of the Chakra project
Copyright (C) 2010 Dario Freddi <drf@chakra-project.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef AKABEI_AKABEIDELTA_H
#define AKABEI_AKABEIDELTA_H
#include <QtCore/QObject>
namespace Akabei {
class DeltaPrivate;
class Delta {
Q_DISABLE_COPY(Delta)
Q_DECLARE_PRIVATE(Delta)
public:
virtual ~Delta();
QByteArray md5sum() const;
QString targetName() const;
QString versionFrom() const;
QString versionTo() const;
QString filename() const;
QString filenameFrom() const;
bool checkMD5Sum();
QString xdeltaApplyCommand(const QString &pathToDestination) const;
QString pathToDelta() const;
void setPathToDelta(const QString &path);
QString pathToSource() const;
void setPathToSource(const QString &path);
private:
Delta(const QString &targetName, const QString &versionFrom, const QString &versionTo);
DeltaPrivate * const d_ptr;
friend class Database;
friend class DatabasePrivate;
};
}
#endif // AKABEI_AKABEIDELTA_H
/*
This file is part of the Chakra project
Copyright (C) 2010 Dario Freddi <drf@chakra-project.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef AKABEI_AKABEIDELTA_P_H
#define AKABEI_AKABEIDELTA_P_H
#include "akabeidelta.h"
namespace Akabei {
class DeltaPrivate {
public:
DeltaPrivate(const QString &n, const QString &v1, const QString &v2)
: name(n)
, vFrom(v1)
, vTo(v2)
{}
~DeltaPrivate() {}
QString name;
QByteArray md5sum;
QString vFrom;
QString vTo;
QString filename;
QString filenameFrom;
QString pathToDelta;
QString pathToOldFile;
QString xdeltaApply;
bool _p_md5checked;
};
}
#endif
...@@ -42,10 +42,17 @@ void PackagePrivate::attemptLoadFromCache() ...@@ -42,10 +42,17 @@ void PackagePrivate::attemptLoadFromCache()
} }
} }
Package::Version::Version()
: d(new Private)
{
d->ref = 1;
}
Package::Version::Version(const QString& version) Package::Version::Version(const QString& version)
: d(new Private) : d(new Private)
{ {
d->ref = 1; d->ref = 1;
d->repr = version;
} }
Package::Version::~Version() Package::Version::~Version()
...@@ -55,6 +62,11 @@ Package::Version::~Version() ...@@ -55,6 +62,11 @@ Package::Version::~Version()
} }
} }
bool Package::Version::isValid() const
{
return !d->repr.isEmpty();
}
QString Package::Version::toString() const QString Package::Version::toString() const
{ {
d->ref.ref(); d->ref.ref();
...@@ -421,6 +433,16 @@ QString Package::retrieveScriptlet() ...@@ -421,6 +433,16 @@ QString Package::retrieveScriptlet()
return d->scriptlet; return d->scriptlet;
} }
QList< Delta* > Package::retrieveDeltas()
{
}
QList< Delta* > Package::retrieveDeltaTo(const Akabei::Package::Version& version)
{
}
QDateTime Package::installDate() const QDateTime Package::installDate() const
{ {
Q_D(const Package); Q_D(const Package);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
class QUrl; class QUrl;
namespace Akabei { namespace Akabei {
class Delta;
class Group; class Group;
class Database; class Database;
...@@ -36,9 +37,12 @@ public: ...@@ -36,9 +37,12 @@ public:
class Version { class Version {
public: public:
Version();
explicit Version(const QString &version); explicit Version(const QString &version);
~Version(); ~Version();
bool isValid() const;
QString toString() const; QString toString() const;
bool respectsConstraint(const QString &constraintedVersion) const; bool respectsConstraint(const QString &constraintedVersion) const;
static bool respectsConstraint(const QString &version, const QString &constraintedVersion); static bool respectsConstraint(const QString &version, const QString &constraintedVersion);
...@@ -121,6 +125,9 @@ public: ...@@ -121,6 +125,9 @@ public:
bool checkMD5Sum(); bool checkMD5Sum();
bool checkArchiveValidity(); bool checkArchiveValidity();
QList< Delta* > retrieveDeltaTo(const Version &version = Version());
QList< Delta* > retrieveDeltas();
Package *generateInstalledPackage(InstallReason reason, const QDateTime &installDate); Package *generateInstalledPackage(InstallReason reason, const QDateTime &installDate);
private: private:
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QUrl> #include <QtCore/QUrl>
#include <QtCore/QHash>
namespace Akabei { namespace Akabei {
...@@ -65,6 +66,7 @@ public: ...@@ -65,6 +66,7 @@ public:
bool hasHooks; bool hasHooks;
QList<Group*> groups; QList<Group*> groups;
QHash< QString, QHash< QString, Delta* > > deltaCache;
QString pathToArchive; QString pathToArchive;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment