return pakfire_repo_refresh_metadata(repo, force);
}
-static int pakfire_repo_write_database(struct pakfire_repo* repo, const char* path,
- char* filename, size_t length) {
+static int pakfire_repo_sign_database(struct pakfire_repo* repo, struct pakfire_key* key,
+ const char* database_path) {
+ char signature_path[PATH_MAX];
+ FILE* f = NULL;
+ FILE* s = NULL;
+ int r;
+
+ // Compose the signature path
+ r = pakfire_string_format(signature_path, "%s.sig", database_path);
+ if (r)
+ return r;
+
+ // Open the signature file for writing
+ s = fopen(signature_path, "w");
+ if (!s) {
+ ERROR(repo->pakfire, "Could not open %s for writing: %m\n", signature_path);
+ r = 1;
+ goto ERROR;
+ }
+
+ // Open the database for reading
+ f = fopen(database_path, "r");
+ if (!f) {
+ ERROR(repo->pakfire, "Could not open %s for reading: %m\n", database_path);
+ r = 1;
+ goto ERROR;
+ }
+
+ // Create the signature
+ r = pakfire_key_signf(key, s, f, "Database Signature");
+ if (r) {
+ ERROR(repo->pakfire, "Could not sign the database: %m\n");
+ goto ERROR;
+ }
+
+ERROR:
+ if (f)
+ fclose(f);
+ if (s)
+ fclose(s);
+
+ return r;
+}
+
+static int pakfire_repo_write_database(struct pakfire_repo* repo, struct pakfire_key* key,
+ const char* path, char* filename, size_t length) {
char database[PATH_MAX];
char tmp[PATH_MAX];
int r;
goto ERROR;
}
+ // Sign the database
+ if (key) {
+ r = pakfire_repo_sign_database(repo, key, database);
+ if (r) {
+ ERROR(repo->pakfire, "Could not sign the database: %m\n");
+ goto ERROR;
+ }
+ }
+
ERROR:
if (f)
fclose(f);
return r;
}
-static int pakfire_repo_sign_database(struct pakfire_repo* repo, struct pakfire_key* key,
- const char* database_path) {
- char signature_path[PATH_MAX];
- FILE* f = NULL;
- FILE* s = NULL;
- int r;
-
- // Compose the signature path
- r = pakfire_string_format(signature_path, "%s.sig", database_path);
- if (r)
- return r;
-
- // Open the signature file for writing
- s = fopen(signature_path, "w");
- if (!s) {
- ERROR(repo->pakfire, "Could not open %s for writing: %m\n", signature_path);
- r = 1;
- goto ERROR;
- }
-
- // Open the database for reading
- f = fopen(database_path, "r");
- if (!f) {
- ERROR(repo->pakfire, "Could not open %s for reading: %m\n", database_path);
- r = 1;
- goto ERROR;
- }
-
- // Create the signature
- r = pakfire_key_signf(key, s, f, "Database Signature");
- if (r) {
- ERROR(repo->pakfire, "Could not sign the database: %m\n");
- goto ERROR;
- }
-
-ERROR:
- if (f)
- fclose(f);
- if (s)
- fclose(s);
-
- return r;
-}
-
static int pakfire_repo_write_metadata(struct pakfire_repo* repo, struct pakfire_key* key) {
struct json_object* repomd = NULL;
FILE* f = NULL;
char database[PATH_MAX];
// Write the database
- r = pakfire_repo_write_database(repo, path, database, sizeof(database));
+ r = pakfire_repo_write_database(repo, key, path, database, sizeof(database));
if (r)
return r;
- // Sign the database
- if (key) {
- r = pakfire_repo_sign_database(repo, key, database);
- if (r) {
- ERROR(repo->pakfire, "Could not sign the database: %m\n");
- goto ERROR;
- }
- }
-
// Compose JSON object
repomd = json_object_new_object();
if (!repomd) {