[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Blibqapt=5D_src=3A_Add_Backend=3A=3AaddArchiveToCach?=
From: Jonathan Thomas <echidnaman () kubuntu ! org>
Date: 2011-01-30 2:08:02
Message-ID: 20110130020802.CE460A6094 () git ! kde ! org
[Download RAW message or body]
Git commit 8212cc76c0d51dfbac96a7c6ba4196d3f7f60ae3 by Jonathan Thomas.
Pushed by jmthomas into branch 'master'.
Add Backend::addArchiveToCache(), whichs adds .deb files for the candidate versions \
of existing packages to the apt .deb cache. This function can be used to add .debs \
from e.g. a USB stick so that computers without internet connections can update \
packages.
M +38 -0 src/backend.cpp
M +3 -0 src/backend.h
M +4 -0 src/worker/org.kubuntu.qaptworker.xml
M +15 -0 src/worker/worker.cpp
M +1 -0 src/worker/worker.h
http://commits.kde.org/d5234754/8212cc76c0d51dfbac96a7c6ba4196d3f7f60ae3
diff --git a/src/backend.cpp b/src/backend.cpp
index 39c8f1a..1a76f92 100644
--- a/src/backend.cpp
+++ b/src/backend.cpp
@@ -44,6 +44,7 @@
// QApt includes
#include "cache.h"
#include "config.h"
+#include "debfile.h"
#include "workerdbus.h" // OrgKubuntuQaptworkerInterface
namespace QApt {
@@ -1084,6 +1085,43 @@ void Backend::updateXapianIndex()
d->worker->updateXapianIndex();
}
+bool Backend::addArchiveToCache(const DebFile &archive)
+{
+ Q_D(Backend);
+
+ // Sanity checks
+ Package *pkg = package(archive.packageName());
+ if (!pkg) {
+ // The package is not in the cache, so we can't do anything
+ // with this .deb
+ return false;
+ }
+
+ QString arch = archive.architecture();
+
+ if (arch != QLatin1String("all") &&
+ arch != d->config->readEntry(QLatin1String("APT::Architecture"), QString())) \
{ + // Incompatible architecture
+ return false;
+ }
+
+ QLatin1String debVersion = archive.version();
+ QString candVersion = pkg->availableVersion();
+
+ if (debVersion != candVersion) {
+ // Incompatible version
+ return false;
+ }
+
+ if (archive.md5Sum() != pkg->md5Sum()) {
+ // Not the same as the candidate
+ return false;
+ }
+
+ // Add the package, but we'll need auth so the worker'll do it
+ return d->worker->copyArchiveToCache(archive.filePath());
+}
+
void Backend::workerStarted()
{
Q_D(Backend);
diff --git a/src/backend.h b/src/backend.h
index 4688634..3180271 100644
--- a/src/backend.h
+++ b/src/backend.h
@@ -31,6 +31,7 @@ class pkgSourceList;
namespace QApt {
class Cache;
class Config;
+ class DebFile;
}
/**
@@ -661,6 +662,8 @@ public Q_SLOTS:
*/
void updateXapianIndex();
+ bool addArchiveToCache(const DebFile &archive);
+
private Q_SLOTS:
void serviceOwnerChanged(const QString &name, const QString &oldOwner, const \
QString &newOwner); void workerStarted();
diff --git a/src/worker/org.kubuntu.qaptworker.xml \
b/src/worker/org.kubuntu.qaptworker.xml index f5dfc15..511d301 100644
--- a/src/worker/org.kubuntu.qaptworker.xml
+++ b/src/worker/org.kubuntu.qaptworker.xml
@@ -75,6 +75,10 @@
<arg name="contents" type="s" direction="in"/>
<arg name="path" type="s" direction="in"/>
</method>
+ <method name="copyArchiveToCache">
+ <arg type="b" direction="out"/>
+ <arg name="archive" type="s" direction="in"/>
+ </method>
</interface>
</node>
diff --git a/src/worker/worker.cpp b/src/worker/worker.cpp
index 05f39dd..d188087 100644
--- a/src/worker/worker.cpp
+++ b/src/worker/worker.cpp
@@ -513,3 +513,18 @@ bool QAptWorker::writeFileToDisk(const QString &contents, const \
QString &path)
return false;
}
+
+bool QAptWorker::copyArchiveToCache(const QString &archivePath)
+{
+ if (!QApt::Auth::authorize(QLatin1String("org.kubuntu.qaptworker.writeFileToDisk"), \
message().service())) { + emit errorOccurred(QApt::AuthError, QVariantMap());
+ return false;
+ }
+
+ initializeApt();
+ QString cachePath = \
QString::fromStdString(_config->FindDir("Dir::Cache::Archives")); + // Filename
+ cachePath += archivePath.right(archivePath.size() - \
archivePath.lastIndexOf('/')); +
+ return QFile::copy(archivePath, cachePath);
+}
diff --git a/src/worker/worker.h b/src/worker/worker.h
index d241072..bdbfa8e 100644
--- a/src/worker/worker.h
+++ b/src/worker/worker.h
@@ -69,6 +69,7 @@ public Q_SLOTS:
void answerWorkerQuestion(const QVariantMap &response);
void updateXapianIndex();
bool writeFileToDisk(const QString &contents, const QString &path);
+ bool copyArchiveToCache(const QString &archivePath);
private Q_SLOTS:
bool initializeApt();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic