return (*name == '@');
}
+static int pakfire_repo_retrieve(struct pakfire_repo* repo, const char* title,
+ const char* url, const char* path, enum pakfire_transfer_flags flags) {
+ struct pakfire_downloader* downloader;
+ int r = pakfire_downloader_create(&downloader, repo->pakfire);
+ if (r)
+ return r;
+
+ // Fetch mirrorlist
+ struct pakfire_mirrorlist* mirrorlist = pakfire_repo_get_mirrorlist(repo);
+
+ // Retrieve the database file
+ r = pakfire_downloader_retrieve(downloader, repo->appdata->baseurl, mirrorlist,
+ title, url, path, flags);
+
+ if (mirrorlist)
+ pakfire_mirrorlist_unref(mirrorlist);
+ pakfire_downloader_unref(downloader);
+
+ return r;
+}
+
+static int pakfire_repo_import_key(struct pakfire_repo* repo, const char* url) {
+ const char* name = pakfire_repo_get_name(repo);
+ DEBUG(repo->pakfire, "Importing key for repository %s from %s...\n", name, url);
+
+ char path[PATH_MAX] = PAKFIRE_CACHE_PATH "/tmp/XXXXXX";
+ struct pakfire_key** keys = NULL;
+
+ // Allocate a temporary file name
+ FILE* f = pakfire_mktemp(path);
+ if (!f)
+ return 1;
+
+ // Try to download the key
+ int r = pakfire_repo_retrieve(repo, NULL, url, path,
+ PAKFIRE_TRANSFER_NOTEMP|PAKFIRE_TRANSFER_NOPROGRESS);
+ if (r)
+ goto ERROR;
+
+ // Try importing the key
+ r = pakfire_key_import(repo->pakfire, f, &keys);
+ if (r)
+ goto ERROR;
+
+ r = 0;
+
+ERROR:
+ if (f)
+ fclose(f);
+ unlink(path);
+
+ // Free keys
+ if (keys) {
+ for (struct pakfire_key** key = keys; *key; key++)
+ pakfire_key_unref(*key);
+ free(keys);
+ }
+
+ return r;
+}
+
int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config) {
char** sections = pakfire_config_sections(config);
if (mirrors)
pakfire_repo_set_mirrorlist_url(repo, mirrors);
+ // Key
+ const char* key = pakfire_config_get(config, *section, "key", NULL);
+ if (key) {
+ r = pakfire_repo_import_key(repo, key);
+ if (r) {
+ pakfire_repo_unref(repo);
+ goto ERROR;
+ }
+ }
+
pakfire_repo_unref(repo);
}
return pakfire_mirrorlist_ref(repo->mirrorlist);
}
-static int pakfire_repo_retrieve(struct pakfire_repo* repo, const char* title,
- const char* url, const char* path, enum pakfire_transfer_flags flags) {
- struct pakfire_downloader* downloader;
- int r = pakfire_downloader_create(&downloader, repo->pakfire);
- if (r)
- return r;
-
- // Fetch mirrorlist
- struct pakfire_mirrorlist* mirrorlist = pakfire_repo_get_mirrorlist(repo);
-
- // Retrieve the database file
- r = pakfire_downloader_retrieve(downloader, repo->appdata->baseurl, mirrorlist,
- title, url, path, flags);
-
- if (mirrorlist)
- pakfire_mirrorlist_unref(mirrorlist);
- pakfire_downloader_unref(downloader);
-
- return r;
-}
-
static int pakfire_repo_download_database(struct pakfire_repo* repo, const char* database,
const char* cache_path) {
char title[NAME_MAX];