Commit a98c4893 authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

Be able to specify an ultimateowner of a file

parent 0aa38ef1
......@@ -27,6 +27,7 @@ CREATE TABLE IF NOT EXISTS `files` (
`package` INTEGER NOT NULL ,
`file` TEXT NOT NULL ,
`backup` TEXT NULL DEFAULT NULL ,
`ultimateowner` INTEGER NULL DEFAULT 0 ,
CONSTRAINT `fk_files_packages`
FOREIGN KEY (`package` )
REFERENCES `packages` (`id` ) );
......
......@@ -188,7 +188,6 @@ void SQLiteConnection::query(const QString &q, const QVariantMap &bindings)
for (int i = 0; i != count; i++) {
QVariantMap::const_iterator it = bindings.constBegin();
QVariantMap::const_iterator end = bindings.constEnd();
qDebug() << it.key() << it.value();
for ( ; it != end; it++) {
if (it.value().toList().first().type() == QVariant::Int) {
bind(it.key(), it.value().toList()[i].toInt());//Can we somehow compress the duplicated code?
......
......@@ -791,7 +791,8 @@ Package* Backend::loadPackageFromFile(const QString& path)
if (!md5.isEmpty()) {
retpackage->d_func()->addBackup(value, md5);
}
} else if (key == "ultimateowner") {
retpackage->d_func()->addUltimatelyOwnedFile(value);
} else if (key == "makepkgopt") {
// retpackage->d_func()->arch = value;
} else if (key == "screenshot") {
......
......@@ -253,6 +253,7 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
Q_PRIVATE_SLOT(d_func(), void __k__initializationFinished())
Q_PRIVATE_SLOT(d_func(), void __k__lockGranted(qint64))
Q_PRIVATE_SLOT(d_func(), void __k__lockGranted())
friend class DatabasePrivate;
friend class Config;
......
......@@ -93,7 +93,8 @@ class BackendPrivate : public QObject
const char * callbackSlot;
void __k__initializationFinished();
void __k__lockGranted(qint64 pid = QCoreApplication::applicationPid());
void __k__lockGranted(qint64 pid);
void __k__lockGranted() { __k__lockGranted(QCoreApplication::applicationPid()); }
void getLock();
QHash<QString, Database*> performInitialization();
......
......@@ -911,13 +911,14 @@ int QueryPerformer::insertFiles(Database *db, Package* p)
int QueryPerformer::insertFiles(PolKitSQLiteConnection &dbConnection, Package* p)
{
const QString null = "NULL";
QString sqlQuery = "INSERT INTO files ('package', 'file', 'backup') VALUES (:Package, :File, :Backup);";
QString sqlQuery = "INSERT INTO files ('package', 'file', 'backup', 'ultimateowner') VALUES (:Package, :File, :Backup, :UltimateOwner);";
try {
QVariantList packages;
QVariantList files;
QVariantList backup;
foreach (const QString &file, p->retrieveFiles()) {
QVariantList uoList;
foreach (const QString &file, p->retrieveFiles(Package::FilepathNoPrefix)) {
packages.append(QVariant::fromValue<int>(p->databaseId()));
files.append(QVariant::fromValue<QString>(file));
if (p->backupFiles().contains(file)) {
......@@ -925,12 +926,18 @@ int QueryPerformer::insertFiles(PolKitSQLiteConnection &dbConnection, Package* p
} else {
backup.append(QVariant::fromValue<QString>(null));
}
if (p->ultimatelyOwnedFiles().contains(file)) {
uoList.append(QVariant::fromValue<bool>(true));
} else {
uoList.append(QVariant::fromValue<bool>(false));
}
}
QVariantMap map;
map.insert(":Package", QVariant(packages));
map.insert(":File", QVariant(files));
map.insert(":Backup", QVariant(backup));
map.insert(":UltimateOwner", QVariant(uoList));
dbConnection.query(sqlQuery, map);
} catch (SQLiteException& e) {
return SQLITE_ABORT;
......@@ -973,7 +980,7 @@ int QueryPerformer::updateFiles(PolKitSQLiteConnection &dbConnection, Package* f
dbConnection.query(sqlQuery);
}
foreach (const QString &f, add) {
sqlQuery = "INSERT INTO files ('package', 'file', 'backup') VALUES (:Package, :File, :Backup);";
sqlQuery = "INSERT INTO files ('package', 'file', 'backup', 'ultimateowner') VALUES (:Package, :File, :Backup, :UltimateOwner);";
dbConnection.bind(":Package", to->databaseId());
dbConnection.bind(":File", f);
if (backups.contains(f)) {
......@@ -981,15 +988,21 @@ int QueryPerformer::updateFiles(PolKitSQLiteConnection &dbConnection, Package* f
} else {
dbConnection.bind(":Backup", null);
}
if (to->ultimatelyOwnedFiles().contains(f)) {
dbConnection.bind(":UltimateOwner", 1);
} else {
dbConnection.bind(":UltimateOwner", 0);
}
dbConnection.query(sqlQuery);
}
//This query will most likely be executed a lot of times, so let's make it a multiple one
sqlQuery = "UPDATE files SET file=:File, package=:ToPackage, backup=:Backup WHERE package=:FromPackage AND file=:File;";
sqlQuery = "UPDATE files SET file=:File, package=:ToPackage, backup=:Backup, ultimateowner=:UltimateOwner WHERE package=:FromPackage AND file=:File;";
QVariantList fromPackages;
QVariantList toPackages;
QVariantList files;
QVariantList backup;
QVariantList uoList;
foreach (const QString &file, update) {
fromPackages.append(QVariant::fromValue<int>(from->databaseId()));
toPackages.append(QVariant::fromValue<int>(to->databaseId()));
......@@ -998,6 +1011,11 @@ int QueryPerformer::updateFiles(PolKitSQLiteConnection &dbConnection, Package* f
backup.append(QVariant::fromValue<QString>(backups[file]));
} else {
backup.append(QVariant::fromValue<QString>(null));
}
if (to->ultimatelyOwnedFiles().contains(file)) {
uoList.append(QVariant::fromValue<bool>(true));
} else {
uoList.append(QVariant::fromValue<bool>(false));
}
}
......@@ -1006,6 +1024,7 @@ int QueryPerformer::updateFiles(PolKitSQLiteConnection &dbConnection, Package* f
map.insert(":ToPackage", QVariant(toPackages));
map.insert(":File", QVariant(files));
map.insert(":Backup", QVariant(backup));
map.insert(":UltimateOwner", QVariant(uoList));
dbConnection.query(sqlQuery, map);
} catch (SQLiteException& e) {
return SQLITE_ABORT;
......
......@@ -149,6 +149,12 @@ void PackagePrivate::addBackup(const QString &f, const QString &sum)
backup.insert(f, sum);
}
void PackagePrivate::addUltimatelyOwnedFile(const QString &f)
{
QWriteLocker locker(mutex);
ultimatelyOwnedFiles.append(f);
}
void PackagePrivate::setScriptlet(const QString &s)
{
QWriteLocker locker(mutex);
......@@ -656,10 +662,12 @@ QStringList Package::retrieveFiles(FilepathMode mode)
QStringList fileList;
QStringList prefixedFileList;
QMap<QString, QString> backups;
QStringList ultimatelyOwnedFiles;
for (int y = 0; y < table.getRowsCount(); ++y) {
QString file( table.getDataAt(y, "file").toString() );
QString backup( table.getDataAt(y, "backup").toString() );
bool ultimatelyOwned( table.getDataAt(y, "ultimateowner").toBool() );
if (file == ".INSTALL" || file == ".PKGINFO")
continue;
......@@ -670,10 +678,13 @@ QStringList Package::retrieveFiles(FilepathMode mode)
if (!backup.isEmpty() && backup != "NULL") {
backups.insert(file, backup);
}
if (ultimatelyOwned)
ultimatelyOwnedFiles << file;
}
d->files = fileList;
d->backup = backups;
d->systemPathFiles = prefixedFileList;
d->ultimatelyOwnedFiles = ultimatelyOwnedFiles;
}
} catch (SQLiteException& e) {
akabeiDebug() << "Error while querying database: " << e.what();
......@@ -936,6 +947,13 @@ QMap<QString, QString> Package::backupFiles() const
return d->backup;
}
QStringList Package::ultimatelyOwnedFiles() const
{
Q_D(const Package);
QReadLocker locker(d->mutex);
return d->ultimatelyOwnedFiles;
}
QStringList Package::licenses() const
{
Q_D(const Package);
......
......@@ -186,12 +186,6 @@ public:
* @returns the license of the package
*/
QStringList licenses() const;
/**
* @returns a map of files which is going to be backupped when there are newer versions available
* and the current version changed on disk
* The key represents the path on disk, the value is the md5sum of the backed up file.
*/
QMap<QString, QString> backupFiles() const;
/**
* @returns a list of package names which the current package replaces
*/
......@@ -214,6 +208,18 @@ public:
* first called it's expensive
*/
QStringList retrieveFiles(FilepathMode mode = FilepathIntelligent);
/**
* @returns a map of files which is going to be backupped when there are newer versions available
* and the current version changed on disk
* The key represents the path on disk, the value is the md5sum of the backed up file.
*/
QMap<QString, QString> backupFiles() const;
/**
* @returns a list of files which the package ultimately owns (it forces the ownership on itself)
*/
QStringList ultimatelyOwnedFiles() const;
/**
* @returns a list of hook-names the package needs to trigger on a transaction
*/
......
......@@ -75,6 +75,7 @@ public:
void addReplaces(const QString &r);
void addLicense(const QString &l);
void addBackup(const QString &f, const QString &sum);
void addUltimatelyOwnedFile(const QString &f);
void setScriptlet(const QString &s);
void setScreenshot(const QUrl &s);
void setInstallReason(const Package::InstallReason &r);
......@@ -112,6 +113,7 @@ private:
qint32 isize;
QStringList files;
QStringList systemPathFiles;
QStringList ultimatelyOwnedFiles;
QStringList deps;
QStringList makedeps;
QStringList conflicts;
......
......@@ -495,9 +495,10 @@ EntryHandlerFunctor::EntryHandlerFunctor(Akabei::Operation *caller, ArchiveHandl
, m_handle(handle)
{}
InstallFunctor::InstallFunctor(QMap< QString, QString >& backup, Akabei::Operation *caller, ArchiveHandler& handle)
InstallFunctor::InstallFunctor(QMap< QString, QString >& backup, const QStringList &uo, Akabei::Operation *caller, ArchiveHandler& handle)
: EntryHandlerFunctor(caller, handle)
, backupFiles(backup)
, ultimatelyOwned(uo)
, partialSize(0)
{}
......@@ -526,6 +527,19 @@ bool InstallFunctor::operator()(const ArchiveEntry& currentEntry)
m_caller->addMessage(QObject::tr("Akabei found an existing config, but had a problem to move it to %1. "
"Maybe an old config was still in place. Please fix it yourself!").arg(file + ".akabeisave"));
}
} else if (ultimatelyOwned.contains(entryName)) {
QString file = Akabei::Config::instance()->rootDir().absoluteFilePath(entryName);
bool done = QFile::rename(file, file + ".akabeisave");
if (done) {
m_caller->addMessage(
QObject::tr("As %1 is the ultimate owner of %2, akabei moved the old file to %3!").arg(m_caller->targetName())
.arg(file).arg(file + ".akabeisave"));
} else if (QFile::exists(file)) {
m_caller->addMessage(
QObject::tr("As %1 is the ultimate owner of %2, akabei tried to move the old file to %3 but failed!"
"Please fix it yourself!"
).arg(m_caller->targetName()).arg(file).arg(file + ".akabeisave"));
}
}
partialSize += currentEntry.getFileSize();
......@@ -548,9 +562,11 @@ bool InstallFunctor::operator()(const ArchiveEntry& currentEntry)
return true;
}
ReinstallUpgradeFunctor::ReinstallUpgradeFunctor(QMap< QString, QString >& backup, Akabei::Operation *caller, ArchiveHandler& handle)
ReinstallUpgradeFunctor::ReinstallUpgradeFunctor(QMap< QString, QString >& backup, const QStringList &uo,
Akabei::Operation *caller, ArchiveHandler& handle)
: EntryHandlerFunctor(caller, handle)
, backupFiles(backup)
, ultimatelyOwned(uo)
, partialSize(0)
{}
......@@ -595,6 +611,19 @@ bool ReinstallUpgradeFunctor::operator()(const ArchiveEntry& currentEntry)
} else {
overwrite = true;
}
} else if (ultimatelyOwned.contains(entryName)) {
QString file = Akabei::Config::instance()->rootDir().absoluteFilePath(entryName);
bool done = QFile::rename(file, file + ".akabeisave");
if (done) {
m_caller->addMessage(
QObject::tr("As %1 is the ultimate owner of %2, akabei moved the old file to %3!").arg(m_caller->targetName())
.arg(file).arg(file + ".akabeisave"));
} else if (QFile::exists(file)) {
m_caller->addMessage(
QObject::tr("As %1 is the ultimate owner of %2, akabei tried to move the old file to %3 but failed!"
"Please fix it yourself!"
).arg(m_caller->targetName()).arg(file).arg(file + ".akabeisave"));
}
}
partialSize += currentEntry.getFileSize();
......
......@@ -107,12 +107,13 @@ private:
class InstallFunctor : public EntryHandlerFunctor
{
public:
InstallFunctor(QMap<QString, QString> &, Akabei::Operation *, ArchiveHandler &);
InstallFunctor(QMap<QString, QString> &, const QStringList &, Akabei::Operation *, ArchiveHandler &);
bool operator() (const ArchiveEntry &);
private:
QMap<QString, QString> &backupFiles;
int partialSize;
const QStringList &ultimatelyOwned;
qint64 partialSize;
};
/**
......@@ -123,12 +124,13 @@ private:
class ReinstallUpgradeFunctor : public EntryHandlerFunctor
{
public:
ReinstallUpgradeFunctor(QMap<QString, QString> &, Akabei::Operation *, ArchiveHandler &);
ReinstallUpgradeFunctor(QMap<QString, QString> &, const QStringList &, Akabei::Operation *, ArchiveHandler &);
bool operator() (const ArchiveEntry &);
private:
QMap<QString, QString> &backupFiles;
int partialSize;
const QStringList &ultimatelyOwned;
qint64 partialSize;
};
/**
......
......@@ -73,13 +73,13 @@ void PlainInstallOperation::run()
// Run it.
QDir currentDir = QDir::current();
PolKitArchiveHandler handle(d->package->pathToArchive());
ArchiveHandler handle(d->package->pathToArchive());
try {
// libarchive requires this for extracting hard links.
chdir(Config::instance()->root().toUtf8().data());
QMap<QString, QString> backup = d->package->backupFiles();
/* Sets up the functor to do all the necessary job on the archive entries */
PolKitInstallFunctor extractor(backup, this, handle);
InstallFunctor extractor(backup, d->package->ultimatelyOwnedFiles(), this, handle);
handle.handleEntries(extractor);
// Restore the old cwd is we have it.
......@@ -197,6 +197,10 @@ void PlainInstallOperation::validate()
if (QFile::exists(Config::instance()->rootDir().absoluteFilePath(file)))
additions.removeAll(file);
}
foreach (const QString &file, d->package->ultimatelyOwnedFiles()) {
if (QFile::exists(Config::instance()->rootDir().absoluteFilePath(file)))
additions.removeAll(file);
}
setFileSystemAdditions(additions);
}
......
......@@ -99,13 +99,13 @@ void PlainReInstallOperation::run()
// Ok, now install
QDir currentDir = QDir::current();
PolKitArchiveHandler handle(d->package->pathToArchive());
ArchiveHandler handle(d->package->pathToArchive());
try {
/* libarchive requires this for extracting hard links */
chdir(Config::instance()->root().toUtf8().data());
/* Sets up the functor to do all the necessary job on the archive entries */
PolKitReinstallUpgradeFunctor extractor(backup, this, handle);
ReinstallUpgradeFunctor extractor(backup, d->package->ultimatelyOwnedFiles(), this, handle);
handle.handleEntries(extractor);
} catch (ArchiveException& e) {
......
......@@ -101,13 +101,13 @@ void PlainUpgradeOperation::run()
// Ok, now install
QDir currentDir = QDir::current();
PolKitArchiveHandler handle(d->to->pathToArchive());
ArchiveHandler handle(d->to->pathToArchive());
try {
/* libarchive requires this for extracting hard links */
chdir(Config::instance()->root().toUtf8().data());
/* Sets up the functor to do all the necessary job on the archive entries */
PolKitReinstallUpgradeFunctor extractor(backup, this, handle);
ReinstallUpgradeFunctor extractor(backup, d->to->ultimatelyOwnedFiles(), this, handle);
handle.handleEntries(extractor);
} catch (ArchiveException& e) {
setErrors(Error::List() << Error(Error::UnknownError, QObject::tr("Could not open package file."), this));
......@@ -273,6 +273,10 @@ void PlainUpgradeOperation::validate()
remove.removeAll(real);
}
}*/
foreach (const QString &file, d->to->ultimatelyOwnedFiles()) {
if (QFile::exists(Config::instance()->rootDir().absoluteFilePath(file)))
add.remove(file);
}
if (!(processingOptions().testFlag(Akabei::Force))) {
setFileSystemAdditions(add.toList());
}
......
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