Commit 85e448a7 authored by Lukas Appelhans's avatar Lukas Appelhans

Make it possible to clean all not-installed packages from cache and also fix...

Make it possible to clean all not-installed packages from cache and also fix compilation with newest gcc
parent ff7ad73b
......@@ -85,18 +85,18 @@ public:
* @param name the database filename
* @param readonly true if read-only access, false for read-write
*/
SQLiteConnection(QString const&, bool);
SQLiteConnection(QString const& name, bool readonly);
/**
* Constructs an object without establishing any connection
*/
SQLiteConnection();
~SQLiteConnection();
/**
* Establishes a new connection with a database
*
*
* @param name the database filename
* @param readonly true if read-only access, false for read-write
*/
......
......@@ -16,6 +16,7 @@
#include <akabeiconfig.h>
#include <utime.h>
#include <akabeicore/SQLiteConnection.h>
/*
* This is an utility class we use for sorting the cache entries according to some date/time.
......@@ -60,8 +61,8 @@ private:
class Cache::Private
{
public:
Private(const QDir &cd) : cachedir(cd), plainEntryList(cd.entryList()) {}
Private(const QDir &cd, const QStringList &kp) : cachedir(cd), plainEntryList(cd.entryList()), keepPackages(kp) {}
Private(const QDir &cd, const QDir &dd) : cachedir(cd), databasedir(dd), plainEntryList(cd.entryList()) {}
Private(const QDir &cd, const QDir &dd, const QStringList &kp) : cachedir(cd), databasedir(dd), plainEntryList(cd.entryList()), keepPackages(kp) {}
~Private() {}
enum RemoveCriteria {
......@@ -77,8 +78,10 @@ public:
bool cleanAll();
bool cleanConditional(RemoveCriteria criteria, bool half = false);
bool cleanNotInstalled();
QDir cachedir;
QDir databasedir;
QStringList cacheFiles;
QStringList plainEntryList;
QStringList keepPackages;
......@@ -91,7 +94,7 @@ public:
* All the options are read from the configuration file later.
*/
Cache::Cache()
: d(new Private(Config::instance()->cacheDir()))
: d(new Private(Config::instance()->cacheDir(), Config::instance()->databaseDir()))
{
d->init();
d->keepPackages.append(Config::instance()->keepPackages());
......@@ -101,8 +104,8 @@ Cache::Cache()
* This constructor is meant to be used by the akabei-clean-cache tool, where the options
* can be specified from the command line.
*/
Cache::Cache(const QString &cachedir, const QStringList &keepPackages)
: d(new Private(cachedir, keepPackages))
Cache::Cache(const QString &cachedir, const QString &databasedir, const QStringList &keepPackages)
: d(new Private(cachedir, databasedir, keepPackages))
{
d->init();
}
......@@ -195,9 +198,12 @@ bool Cache::writePackage(const QString &path, const QString &newName)
case CleanUnused:
return d->cleanConditional(d->LastReadDate, true);
case CleanOldAndUnused:
case CleanOldAndUnused: {
bool worked = d->cleanConditional(Cache::Private::CreationDate);
return worked && d->cleanConditional(Cache::Private::LastReadDate);
}
case CleanNotInstalled:
return d->cleanNotInstalled();
}
}
......@@ -224,9 +230,35 @@ void Cache::cleanCache(MaxSizePolicy policy)
case CleanUnused:
d->cleanConditional(Cache::Private::LastReadDate);
break;
case CleanNotInstalled:
d->cleanNotInstalled();
break;
};
}
bool Cache::Private::cleanNotInstalled()
{
try {
SQLiteConnection database(databasedir.absoluteFilePath("local.db"), true);
foreach (QString const& file, cacheFiles) {
database.bind(":Filename", file.split("/").last());
SQLiteResource res = database.query("SELECT * FROM packages WHERE filename=:Filename");
if (res.getRowsCount() == 0) {
QFile f(file);
if (!f.remove()) {
error = f.errorString();
return false;
}
}
}
} catch (SQLiteException &exc) {
qWarning() << "Caught an error with" << cachedir.absoluteFilePath("local.db") << ":" << exc.what();
return false;
}
return true;
}
/*
* The bool parameter is needed because to distinguish whether we're removing packages because of an explicit
* request from the user (in that case, it removes all the old/unused packages) or if we're removing because
......
......@@ -33,7 +33,8 @@ public:
CleanAll,
CleanOldAndUnused,
CleanOld,
CleanUnused
CleanUnused,
CleanNotInstalled
};
/**
......@@ -43,7 +44,7 @@ public:
* @param keepPackages A list of packages the cache must always maintain.
* @param operations A list of operations to perform.
*/
Cache(const QString &cachedir, const QStringList &keepPackages);
Cache(const QString &cachedir, const QString &databasedir, const QStringList &keepPackages);
/**
* Constructs a cache manager.
......
......@@ -20,6 +20,7 @@
#include <QtCore/QDir>
#include <QtCore/QDebug>
#include <qtemporaryfile.h>
#include <unistd.h>
namespace Akabei
{
......@@ -46,9 +47,9 @@ void ChrootedProcess::run(const QString &cmd, QFile * file)
void ChrootedProcess::setupChildProcess()
{
::chroot(m_chroot.toUtf8().data());
::chdir("/");
::umask(0022);
::chroot(m_chroot.toUtf8().data());
::chdir("/");
umask(0022);
}
void ChrootedProcess::slotFinished(int exitCode)
......
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