return 0;
}
-static int pakfire_repo_write_database(
- struct pakfire_repo* repo, char* filename, size_t length) {
+static int pakfire_repo_write_database(struct pakfire_repo* self,
+ struct json_object* repomd, char* filename, size_t length) {
char database[PATH_MAX];
char tmp[PATH_MAX];
int r;
// Create path for a temporary database export file
- r = pakfire_repo_path(repo, tmp, "%s", "repodata/.pakfire-solv.XXXXXX");
+ r = pakfire_repo_path(self, tmp, "%s", "repodata/.pakfire-solv.XXXXXX");
if (r < 0)
return r;
// Create a temporary file to write to
FILE* f = pakfire_mktemp(tmp, 0644);
if (!f) {
- ERROR(repo->ctx, "Could not open temporary file for writing: %m\n");
+ ERROR(self->ctx, "Could not open temporary file for writing: %m\n");
return 1;
}
// Initialize the output being compressed
f = pakfire_zstdfopen(f, "w19");
if (!f) {
- ERROR(repo->ctx, "Could not initialize compression: %m\n");
+ ERROR(self->ctx, "Could not initialize compression: %m\n");
return 1;
}
// Write the SOLV database to the temporary file
- r = pakfire_repo_write_solv(repo, f, 0);
+ r = pakfire_repo_write_solv(self, f, 0);
if (r) {
- ERROR(repo->ctx, "Could not write SOLV data: %m\n");
+ ERROR(self->ctx, "Could not write SOLV data: %m\n");
goto ERROR;
}
// Create a filename for the database file
r = __pakfire_strftime_now(filename, length, "%Y-%m-%d-%H%M.%s.solv.zst");
if (r) {
- ERROR(repo->ctx, "Could not format database filename: %m\n");
+ ERROR(self->ctx, "Could not format database filename: %m\n");
goto ERROR;
}
// Make final database path
- r = pakfire_repo_path(repo, database, "repodata/%s", filename);
+ r = pakfire_repo_path(self, database, "repodata/%s", filename);
if (r < 0) {
- ERROR(repo->ctx, "Could not join database path: %m\n");
+ ERROR(self->ctx, "Could not join database path: %m\n");
goto ERROR;
}
// Link database to its destination
r = link(tmp, database);
if (r < 0) {
- ERROR(repo->ctx, "Could not link database %s: %m\n", database);
+ ERROR(self->ctx, "Could not link database %s: %m\n", database);
r = -errno;
goto ERROR;
}
+ // Add the database name to the repository metadata
+ r = pakfire_json_add_string(repomd, "database", filename);
+ if (r < 0)
+ goto ERROR;
+
ERROR:
if (f)
fclose(f);
if (r < 0)
goto ERROR;
- // Write the database
- r = pakfire_repo_write_database(self, database, sizeof(database));
- if (r < 0)
- goto ERROR;
-
// Compose JSON object
repomd = json_object_new_object();
if (!repomd) {
if (r < 0)
goto ERROR;
+ // Write the database
+ r = pakfire_repo_write_database(self, repomd, database, sizeof(database));
+ if (r < 0)
+ goto ERROR;
+
// XXX database hash is missing
// Open repomd.json for writing