From 4d9e6ffad97f632139a75acce899d6a6b0594576 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Tue, 13 Oct 2015 00:09:40 +0200 Subject: [PATCH] Make contentslist generation optional using --gencontentslist backend-sqlite: only output data for local repository to work also when executed with other arguments --- src/backend-sqlite3.c | 482 ++++++++++++++++++++++-------------------- src/distromatic.c | 16 +- src/include/reports.h | 1 + src/reports.c | 39 ++-- 4 files changed, 291 insertions(+), 247 deletions(-) diff --git a/src/backend-sqlite3.c b/src/backend-sqlite3.c index a729adb..a0f3ad8 100644 --- a/src/backend-sqlite3.c +++ b/src/backend-sqlite3.c @@ -1,7 +1,7 @@ /* * distromatic - tool for RPM based repositories * - * Copyright (C) 2013 by Silvan Calarco + * Copyright (C) 2013-2015 by Silvan Calarco * * This program is free software; you can redistribute it and/or modify it under * the terms of version 2 of the GNU General Public License as published by the @@ -68,29 +68,41 @@ int SQLite_print_contents_subtree(sqlite3 *db, struct configTag* ct, int arch) { + int thisrep, i; + while (ft) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO files VALUES(%ld,?,%ld,%ld,%ld,%d);", - ft->id, - (ft->firstchild?ft->firstchild->id:-1), - (ft->next?ft->next->id:-1), - (ft->parent?ft->parent->id:-1), - ft->numproviders); - sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL); - sqlite3_bind_text(stmt, 1, ft->name, -1, SQLITE_STATIC); - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query); - return 1; + i = 0; + thisrep = 0; + for (i = 0; i < ft->numproviders; i++) { + if (ft->provider[i]->altrepository == ct->repository_level) { + thisrep = 1; + break; + } } - sqlite3_finalize(stmt); + if (thisrep) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO files VALUES(%ld,?,%ld,%ld,%ld,%d);", + ft->id, + (ft->firstchild?ft->firstchild->id:-1), + (ft->next?ft->next->id:-1), + (ft->parent?ft->parent->id:-1), + ft->numproviders); + sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL); + sqlite3_bind_text(stmt, 1, ft->name, -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query); + return 1; + } + sqlite3_finalize(stmt); - sqlite3_transaction_size += strlen(sqlite3_query); - if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) { - SQLite_commit_transaction(db); - SQLite_begin_transaction(db); - } + sqlite3_transaction_size += strlen(sqlite3_query); + if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) { + SQLite_commit_transaction(db); + SQLite_begin_transaction(db); + } - if (ft->firstchild) { - if (SQLite_print_contents_subtree(db, ft->firstchild, ct, arch)) return 1; + if (ft->firstchild) { + if (SQLite_print_contents_subtree(db, ft->firstchild, ct, arch)) return 1; + } } ft=ft->next; } @@ -163,36 +175,37 @@ int generateSQLite_files(struct configTag* ct, sqlite3 *db, int arch) { currpackage = ct->headerlist[arch]; while (currpackage) { - /* packages <-> files relations */ - for (i = 0; i < currpackage->filenamecount; i++) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages_files_rel VALUES(NULL,%ld,%ld,%ld,%ld,%d,?,?,?);", - currpackage->id, - currpackage->file[i]->id, - currpackage->fileuser[i]->id, - currpackage->filegroup[i]->id, - currpackage->fileflags[i]); - if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query); - return 1; - } - sqlite3_bind_text(stmt, 1, currpackage->name, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC); - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_query, sqlite3_errmsg(db)); - return 3; - } - sqlite3_finalize(stmt); - sqlite3_transaction_size += strlen(sqlite3_query); - if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) { - SQLite_commit_transaction(db); - SQLite_begin_transaction(db); - } - } - currpackage = currpackage->next; + if (currpackage->altrepository == ct->repository_level) { + /* packages <-> files relations */ + for (i = 0; i < currpackage->filenamecount; i++) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages_files_rel VALUES(NULL,%ld,%ld,%ld,%ld,%d,?,?,?);", + currpackage->id, + currpackage->file[i]->id, + currpackage->fileuser[i]->id, + currpackage->filegroup[i]->id, + currpackage->fileflags[i]); + if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { + fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query); + return 1; + } + sqlite3_bind_text(stmt, 1, currpackage->name, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_query, sqlite3_errmsg(db)); + return 3; + } + sqlite3_finalize(stmt); + sqlite3_transaction_size += strlen(sqlite3_query); + if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) { + SQLite_commit_transaction(db); + SQLite_begin_transaction(db); + } + } + } + currpackage = currpackage->next; } SQLite_commit_transaction(db); - return 0; } @@ -202,6 +215,7 @@ int generateSQLite_files(struct configTag* ct, sqlite3 *db, int arch) { int generateSQLite_provided(struct configTag* ct, sqlite3 *db, int arch) { struct providedList* provided; + int i, thisrep; snprintf(sqlite3_query, PATH_MAX, "provided"); SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_provided); @@ -209,22 +223,30 @@ int generateSQLite_provided(struct configTag* ct, sqlite3 *db, int arch) { provided = ct->providedlist_idx[arch][0]; while (provided) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provided VALUES(%ld,?,%ld,%d);", - provided->id, - provided->flags, - provided->numproviders); - sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL); - sqlite3_bind_text(stmt, 1, provided->name, -1, SQLITE_STATIC); - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 1; + i = 0; + thisrep = 0; + for (i = 0; i < provided->numproviders; i++) { + if (provided->provider[i]->altrepository == ct->repository_level) { + thisrep = 1; + break; + } + } + if (thisrep) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provided VALUES(%ld,?,%ld,%d);", + provided->id, + provided->flags, + provided->numproviders); + sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL); + sqlite3_bind_text(stmt, 1, provided->name, -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 1; + } + sqlite3_finalize(stmt); } - sqlite3_finalize(stmt); provided = provided->next; } - SQLite_commit_transaction(db); - return 0; } @@ -238,7 +260,7 @@ int generateSQLite_packagers(sqlite3 *db) { SQLite_init_table(db, "packagers", SQLITE_TABLE_packagers); SQLite_begin_transaction(db); - + while (packager) { snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packagers VALUES(NULL,?,%d,%d,%d);", packager->role, @@ -316,92 +338,93 @@ generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) { currpackage = ct->headerlist[arch]; while (currpackage) { - - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages VALUES(NULL,?,%d,%ld,?,?,?,?,?,%ld,%ld);", - currpackage->altrepository, - currpackage->epoch, - currpackage->size, - currpackage->sourceheader->id); - if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 1; - } - - sqlite3_bind_text(stmt, 1, currpackage->name, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 4, currpackage->summary, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 5, currpackage->group, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 6, currpackage->description, -1, SQLITE_STATIC); - - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 3; - } - currpackage->id = sqlite3_last_insert_rowid(db); - sqlite3_finalize(stmt); - - /* obsoletes */ - for (i = 0; i < currpackage->obsoletecount; i++) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO obsoletes VALUES(NULL,%ld,?,%d,?);", - currpackage->id, - currpackage->obsoleteflags[i]); - - if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - } - sqlite3_bind_text(stmt, 1, currpackage->obsoletename[i], -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, currpackage->obsoleteversion[i], -1, SQLITE_STATIC); - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 3; - } - sqlite3_finalize(stmt); - } - - /* provides */ - for (i = 0; i < currpackage->providecount; i++) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provides VALUES(NULL,%ld,%ld,%d,?);", - currpackage->id, - currpackage->provided[i]->id, - currpackage->provideflags[i]); - - if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - } - sqlite3_bind_text(stmt, 1, currpackage->provideversion[i], -1, SQLITE_STATIC); - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 3; - } - sqlite3_finalize(stmt); - } - - /* requires */ - for (i = 0; i < currpackage->requirecount; i++) { - if (currpackage->require[i]->resolved) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO requires VALUES(NULL,%ld,%ld,%ld,?);", - currpackage->id, - currpackage->require[i]->resolved->id, - currpackage->require[i]->flags); - - if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - } - sqlite3_bind_text(stmt, 1, currpackage->require[i]->version, -1, SQLITE_STATIC); - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 3; - } - sqlite3_finalize(stmt); - } else if (strstr(currpackage->require[i]->name,"rpmlib(") != currpackage->require[i]->name) { - fprintf(stderr, "WARNING: package %s require %s not in provided list\n", currpackage->name, currpackage->require[i]->name); + if (currpackage->altrepository == ct->repository_level) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages VALUES(NULL,?,%d,%ld,?,?,?,?,?,%ld,%ld);", + currpackage->altrepository, + currpackage->epoch, + currpackage->size, + currpackage->sourceheader->id); + if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 1; } - } - currpackage = currpackage->next; - } - SQLite_commit_transaction(db); - return 0; + + sqlite3_bind_text(stmt, 1, currpackage->name, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 4, currpackage->summary, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 5, currpackage->group, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 6, currpackage->description, -1, SQLITE_STATIC); + + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 3; + } + currpackage->id = sqlite3_last_insert_rowid(db); + sqlite3_finalize(stmt); + + /* obsoletes */ + for (i = 0; i < currpackage->obsoletecount; i++) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO obsoletes VALUES(NULL,%ld,?,%d,?);", + currpackage->id, + currpackage->obsoleteflags[i]); + + if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + } + sqlite3_bind_text(stmt, 1, currpackage->obsoletename[i], -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 2, currpackage->obsoleteversion[i], -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 3; + } + sqlite3_finalize(stmt); + } + + /* provides */ + for (i = 0; i < currpackage->providecount; i++) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provides VALUES(NULL,%ld,%ld,%d,?);", + currpackage->id, + currpackage->provided[i]->id, + currpackage->provideflags[i]); + + if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + } + sqlite3_bind_text(stmt, 1, currpackage->provideversion[i], -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 3; + } + sqlite3_finalize(stmt); + } + + /* requires */ + for (i = 0; i < currpackage->requirecount; i++) { + if (currpackage->require[i]->resolved) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO requires VALUES(NULL,%ld,%ld,%ld,?);", + currpackage->id, + currpackage->require[i]->resolved->id, + currpackage->require[i]->flags); + + if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + } + sqlite3_bind_text(stmt, 1, currpackage->require[i]->version, -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 3; + } + sqlite3_finalize(stmt); + } else if (strstr(currpackage->require[i]->name,"rpmlib(") != currpackage->require[i]->name) { + fprintf(stderr, "WARNING: package %s require %s not in provided list\n", currpackage->name, currpackage->require[i]->name); + } + } + } + currpackage = currpackage->next; + } + SQLite_commit_transaction(db); + return 0; } #define SQLITE_TABLE_sources_source "id INTEGER PRIMARY KEY, id_source INTEGER, source STRING" @@ -435,95 +458,95 @@ generateSQLite_sources(struct configTag *ct, sqlite3 *db) { currsource = ct->headersourcelist; while (currsource != NULL) { - - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources VALUES(%ld,?,%d,%ld,?,?,?,%ld,?,?,?,?,?,?,?,%ld,%ld,%ld);", - currsource->id, - currsource->altrepository, - currsource->epoch, - currsource->packager->id, - currsource->buildtime, - currsource->size, - (currsource->changelog?nextchangelogid:0)); - if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - } - - sqlite3_bind_text(stmt, 1, currsource->name, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, currsource->version, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 3, currsource->release, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 4, currsource->summary, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 5, currsource->group, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 6, currsource->description, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 7, currsource->url, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 8, currsource->license, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 9, currsource->arch, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 10, currsource->buildarchs, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 11, currsource->excludearch, -1, SQLITE_STATIC); - - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 3; - } - currsource->id = sqlite3_last_insert_rowid(db); - sqlite3_finalize(stmt); - - /* source */ - if (currsource->source) { - i=0; - while (currsource->source[i]) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_source VALUES(NULL,%ld,?);", - currsource->id); - - if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - } - sqlite3_bind_text(stmt, 1, currsource->source[i], -1, SQLITE_STATIC); - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 3; - } - sqlite3_finalize(stmt); - i++; - } - } - - /* patch */ - if (currsource->patch) { - i=0; - while (currsource->patch[i]) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_patch VALUES(NULL,%ld,?);", - currsource->id); - - if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - } - sqlite3_bind_text(stmt, 1, currsource->patch[i], -1, SQLITE_STATIC); - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 3; - } - sqlite3_finalize(stmt); - i++; - } - } - - /* buildrequires */ - for (i = 0; i < currsource->requirecount; i++) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO buildrequires VALUES(NULL,%ld,?,%ld,?);", + if (currsource->altrepository == ct->repository_level) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources VALUES(%ld,?,%d,%ld,?,?,?,%ld,?,?,?,?,?,?,?,%ld,%ld,%ld);", currsource->id, - currsource->require[i]->flags); - + currsource->altrepository, + currsource->epoch, + currsource->packager->id, + currsource->buildtime, + currsource->size, + (currsource->changelog?nextchangelogid:0)); if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); } - sqlite3_bind_text(stmt, 1, currsource->require[i]->name, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, currsource->require[i]->version, -1, SQLITE_STATIC); + + sqlite3_bind_text(stmt, 1, currsource->name, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 2, currsource->version, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 3, currsource->release, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 4, currsource->summary, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 5, currsource->group, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 6, currsource->description, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 7, currsource->url, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 8, currsource->license, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 9, currsource->arch, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 10, currsource->buildarchs, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 11, currsource->excludearch, -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); return 3; } + currsource->id = sqlite3_last_insert_rowid(db); sqlite3_finalize(stmt); - } + + /* source */ + if (currsource->source) { + i=0; + while (currsource->source[i]) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_source VALUES(NULL,%ld,?);", + currsource->id); + + if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + } + sqlite3_bind_text(stmt, 1, currsource->source[i], -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 3; + } + sqlite3_finalize(stmt); + i++; + } + } + + /* patch */ + if (currsource->patch) { + i=0; + while (currsource->patch[i]) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_patch VALUES(NULL,%ld,?);", + currsource->id); + + if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + } + sqlite3_bind_text(stmt, 1, currsource->patch[i], -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 3; + } + sqlite3_finalize(stmt); + i++; + } + } + + /* buildrequires */ + for (i = 0; i < currsource->requirecount; i++) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO buildrequires VALUES(NULL,%ld,?,%ld,?);", + currsource->id, + currsource->require[i]->flags); + + if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + } + sqlite3_bind_text(stmt, 1, currsource->require[i]->name, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 2, currsource->require[i]->version, -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 3; + } + sqlite3_finalize(stmt); + } /* sources <-> provided relations (buildrequirements) */ /* for (i=0; iprovidecount; i++) { @@ -541,8 +564,9 @@ generateSQLite_sources(struct configTag *ct, sqlite3 *db) { sqlite3_finalize(stmt); }*/ - if (currsource->changelog) { - nextchangelogid = generateSQLite_add_changelog(db, currsource->changelog, currsource->id) + 1; + if (currsource->changelog) { + nextchangelogid = generateSQLite_add_changelog(db, currsource->changelog, currsource->id) + 1; + } } currsource = currsource->next; } diff --git a/src/distromatic.c b/src/distromatic.c index 3ec6305..d565f67 100644 --- a/src/distromatic.c +++ b/src/distromatic.c @@ -92,6 +92,7 @@ #define MODE_GENPKGLIST 64 #define MODE_SQLITE3 128 #define MODE_SQLITE3_FILES 256 +#define MODE_GENCONTENTSLIST 512 static void program_usage(int exit_code); static void program_version(void); @@ -147,6 +148,7 @@ static const char *helpmsg[] = { " --gensrcpkglist generate a source packages list with version", " --gensqlite3 dump data to SQLite3 databases", " --gensqlite3files dump files to SQLite3 databases", +" --gencontentslist generate files listing all files in packages", " --find-deps find dependencies for given package name", " --changelog print changelog for given package name", " --changelogsince print changelog for all packages since given date", @@ -895,8 +897,14 @@ void *threadArchScan(void* arg) { } if (mode & MODE_DATA_TABLES) { - if (!quietmode) fprintf(stdout,"%s: writing dependencies table...\n",configtag->arch[arch]); - print_datatables(configtag,arch); + if (!quietmode) fprintf(stdout,"%s: writing dependencies tables...\n",configtag->arch[arch]); + print_datatables(configtag,arch); + } + + + if (mode & MODE_GENCONTENTSLIST) { + if (!quietmode) fprintf(stdout,"%s: writing contentslist files...\n",configtag->arch[arch]); + print_contentslist(configtag,arch); } if (genheader_mode & GENHEADER_STATS) { @@ -956,6 +964,7 @@ main(int argc, char *argv[]) { "gensrcpkglist", no_argument, 0, 0 }, { "gensqlite3", no_argument, 0, 0 }, { "gensqlite3files", no_argument, 0, 0 }, + { "gencontentslist", no_argument, 0, 0 }, { "arch", required_argument, 0, 'a' }, { "conf", required_argument, 0, 'c' }, { "help", no_argument, 0, 'h' }, @@ -1020,6 +1029,9 @@ main(int argc, char *argv[]) mode |= MODE_GENBUILDINFO; genheader_mode |= GENHEADER_BASE; name = NULL; + } else if (!strcmp(longopts[longindex].name, "gencontentslist")) { + mode |= MODE_GENCONTENTSLIST; + name = NULL; } break; case 'a': diff --git a/src/include/reports.h b/src/include/reports.h index 47c575e..3d9afb7 100644 --- a/src/include/reports.h +++ b/src/include/reports.h @@ -28,6 +28,7 @@ int generateHTML_SRPMSFiles(struct configTag *configtag); int generateHTMLMainIndex(struct configTag *configtag); char *groupdirname(char *group,char *dest,unsigned int max); int write_RPM_HTML(struct configTag *ct,FILE *fout, struct headerList *currheaderlist); +int print_contentslist(struct configTag *ct, int arch); int print_datatables(struct configTag *ct, int arch); char *ftname(struct fileTree* ft, char* buf, unsigned int bufsize); void print_contents_subtree(FILE *f, diff --git a/src/reports.c b/src/reports.c index b36105b..268f339 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1764,13 +1764,32 @@ void print_contents_subtree(FILE *f, } -int -print_datatables(struct configTag *ct, int arch) { +int print_contentslist(struct configTag *ct, int arch) { + FILE *fc; + char contents_filename[PATH_MAX],buf[PATH_MAX]; - FILE *fbd,*fd,*fv,*fb,*fbsh,*fs,*fc,*fw; + snprintf(contents_filename, PATH_MAX, "%scontentslist-%s", ct->repository_dir, ct->arch[arch]); + + fc=fopen(contents_filename,"w"); + if (!fc) { + fprintf(stderr, "Error: can't open file for writing: %s. Aborting.\n", contents_filename); + return 1; + } + + //write contents (filenames) + logmsg(LOG_DEBUG,"writing contents file"); + print_contents_subtree(fc, ct->filetree[arch], ct, buf, PATH_MAX); + + fclose(fc); + return 0; +} + +int print_datatables(struct configTag *ct, int arch) { + + FILE *fbd,*fd,*fv,*fb,*fbsh,*fs,*fw; char builddeps_filename[PATH_MAX], deps_filename[PATH_MAX], virtual_filename[PATH_MAX], builds_filename[PATH_MAX], builds_sh_filename[PATH_MAX], sources_filename[PATH_MAX], - contents_filename[PATH_MAX], warnings_filename[PATH_MAX], buf[PATH_MAX]; + warnings_filename[PATH_MAX]; char obsoletebuf[PATH_MAX]; struct headerList *currheaderlist, *currchild; struct headerSourceList *currheadersourcelist, *oldheadersourcelist; @@ -1783,7 +1802,6 @@ print_datatables(struct configTag *ct, int arch) { snprintf(builds_filename, PATH_MAX, "%sbuilds-%s", ct->html_dir, ct->arch[arch]); snprintf(builds_sh_filename, PATH_MAX, "%sbuilds-%s.sh", ct->html_dir, ct->arch[arch]); snprintf(sources_filename, PATH_MAX, "%ssources-%s", ct->html_dir, ct->arch[arch]); - snprintf(contents_filename, PATH_MAX, "%scontentslist-%s", ct->repository_dir, ct->arch[arch]); snprintf(warnings_filename, PATH_MAX, "%swarnings-%s", ct->repository_dir, ct->arch[arch]); fbd=fopen(builddeps_filename,"w"); @@ -1822,12 +1840,6 @@ print_datatables(struct configTag *ct, int arch) { return 1; } - fc=fopen(contents_filename,"w"); - if (!fc) { - fprintf(stderr, "Error: can't open file for writing: %s. Aborting.\n", contents_filename); - return 1; - } - fw=fopen(warnings_filename,"w"); if (!fw) { fprintf(stderr, "Error: can't open file for writing: %s. Aborting.\n", warnings_filename); @@ -1933,10 +1945,6 @@ print_datatables(struct configTag *ct, int arch) { provided = provided->next; } - //write contents (filenames) - logmsg(LOG_DEBUG,"writing contents file"); - print_contents_subtree(fc, ct->filetree[arch], ct, buf, PATH_MAX); - logmsg(LOG_DEBUG,"writing deps files (2)"); currheaderlist = ct->headerlist[arch]; while (currheaderlist) { @@ -2112,7 +2120,6 @@ print_datatables(struct configTag *ct, int arch) { fclose(fbsh); fclose(fb); fclose(fs); - fclose(fc); fclose(fw); return 0;