backend-sqlite3.c: populate files table with entries related to files from packages in repository

This commit is contained in:
Silvan Calarco 2024-07-14 23:02:27 +02:00
parent 6a730ac59a
commit ec3f7b4847

View File

@ -64,10 +64,8 @@ int SQLite_commit_transaction(sqlite3 *db) {
return 0;
}
int SQLite_print_contents_subtree(sqlite3 *db,
struct fileTree* ft,
struct configTag* ct,
int arch) {
int SQLite_print_contents_subtree(sqlite3 *db, struct fileTree* ft,
struct configTag* ct, int arch) {
int thisrep, i;
@ -110,6 +108,33 @@ int SQLite_print_contents_subtree(sqlite3 *db,
return 0;
}
char* SQLite_add_file_tree_to_files(sqlite3 *db, struct fileTree *inFile, char *outPath) {
char buf[PATH_MAX] = "";
outPath[0] = 0;
while (inFile) {
snprintf(buf, PATH_MAX + 1, "/%s%s", inFile->name, outPath);
strcpy(&outPath[0], buf);
snprintf(sqlite3_query, PATH_MAX, "INSERT OR IGNORE INTO files VALUES(%ld,?,%ld,%ld,%ld,%d);",
inFile->id,
(inFile->firstchild?inFile->firstchild->id:-1),
(inFile->next?inFile->next->id:-1),
(inFile->parent?inFile->parent->id:-1),
inFile->numproviders);
sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL);
sqlite3_bind_text(stmt, 1, inFile->name, -1, SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query);
}
sqlite3_finalize(stmt);
inFile = inFile->parent;
}
return outPath;
}
#define SQLITE_TABLE_files "id INTEGER PRIMARY KEY, "\
"name STRING, firstchild INTEGER, next INTEGER, parent INTEGER, numproviders INTEGER"
/* struct headerList **provider; */
@ -174,17 +199,21 @@ int generateSQLite_files(struct configTag* ct, sqlite3 *db, int arch) {
SQLite_begin_transaction(db);
if (SQLite_print_contents_subtree(db, ct->filetree[arch], ct, arch)) return 1;
char outPath[PATH_MAX];
currpackage = ct->headerlist[arch];
while (currpackage) {
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,?,?,?);",
SQLite_add_file_tree_to_files(db, currpackage->file[i], outPath);
snprintf(sqlite3_query, PATH_MAX,
"INSERT INTO packages_files_rel VALUES(NULL,%ld,%ld,%ld,%ld,%d,?,?,?);",
currpackage->id,
(currpackage->file)[i]->id, 0L, 0L,
currpackage->file[i]->id, 0L, 0L,
//(currpackage->fileuser)[i]->id,
//(currpackage->filegroup)[i]->id,
(currpackage->fileflags)[i]);
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;