Commit 7de9d3a4 authored by Lukas Appelhans's avatar Lukas Appelhans

Start work on repo-add and repo-remove

parent 7e4fdd96
......@@ -148,6 +148,49 @@ bool CreateDb::writeArchive(const QString& filename, const QHash< QString, QStri
archive_write_finish(a); // Note 5
return true;
}
QHash<QString, QString> extractArchive(const QString &path)
{
struct archive *a;
struct archive *ext;
struct archive_entry *entry;
int flags;
int r;
/* Select which attributes we want to restore. */
flags = ARCHIVE_EXTRACT_TIME;
flags |= ARCHIVE_EXTRACT_PERM;
flags |= ARCHIVE_EXTRACT_ACL;
flags |= ARCHIVE_EXTRACT_FFLAGS;
a = archive_read_new();
archive_read_support_format_all(a);
archive_read_support_compression_all(a);
ext = archive_write_disk_new();
archive_write_disk_set_options(ext, flags);
archive_write_disk_set_standard_lookup(ext);
QHash<QString, QString> result;
if ((r = archive_read_open_file(a, path.toStdString().c_str(), 10240)))
return result;
for (;;) {
r = archive_read_next_header(a, &entry);
if (r == ARCHIVE_EOF)
break;
QString name = archive_entry_pathname(entry);
QString fileName = "/tmp/" + name;
archive_entry_set_pathname(entry, fileName.toStdString().c_str());
r = archive_write_header(ext, entry);
if (archive_entry_size(entry) > 0) {
r = archive_read_extract2(a, entry, ext);
r = archive_write_finish_entry(ext);
}
result[name] = fileName;
}
archive_read_close(a);
archive_read_finish(a);
return result;
}
/*
bool CreateDb::writeArchive(const QString& filename, const QHash< QString, QString >& files)
{
......@@ -694,4 +737,34 @@ void CreateDb::start()
QCoreApplication::instance()->quit();
}
void CreateDb::add()
{
}
void CreateDb::remove()
{
QString dbName = m_db.split('/').last();
QString compressedDbPath;
if (m_db.endsWith(".db")) {
compressedDbPath = m_db;
dbName = dbName.remove(dbName.length() - 3, 3);
} else {
compressedDbPath = m_db + ".db";
}
compressedDbPath += ".tar.xz";
compressedDbPath = cleanPath(compressedDbPath);
if (!QFile::exists(compressedDbPath)) {
out << endl << "The file " << compressedDbPath << " does not exist." << endl;
out.flush();
return;
}
QHash<QString, QString> files = extractArchive("/tmp");
QString unc = files.value(dbName + ".db");
out.flush();
}
#include "createdb.moc"
......@@ -26,6 +26,8 @@ class CreateDb : public QObject
public slots:
void start();
void add();
void remove();
private:
QString cleanPath(const QString &path);
......
......@@ -22,19 +22,27 @@ int main(int argc, char **argv)
QStringList args = QCoreApplication::arguments();
if (args.count() < 4) {
qWarning() << "Usage: akabei-create-db <repo> <groupdefinitiondir> <target> ...";
if (args.count() < 3) {
qWarning() << "Usage: akabei-create-db <action> <repo> <target> ...";
qWarning() << "Action can either be generate, add or remove";
return 0;
}
QString newDbPath = args.at(1);
QString command = args.at(1);
QString newDbPath = args.at(2);
QStringList targets = args;
targets.removeAt(0);
targets.removeAt(0);
targets.removeAt(0);
CreateDb db(newDbPath, targets);
QTimer::singleShot(0, &db, SLOT(start()));
if (command == "generate")
QTimer::singleShot(0, &db, SLOT(start()));
else if (command == "add")
QTimer::singleShot(0, &db, SLOT(add()));
else if (command == "remove")
QTimer::singleShot(0, &db, SLOT(remove()));
app.exec();
}
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