}
PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) {
- struct pakfire_archive* archive = NULL;
struct pakfire_package* package = NULL;
struct pakfire_parser* makefile = NULL;
char* buildroot = NULL;
if (r)
goto ERROR;
- // Open source archive
- r = pakfire_archive_open(&archive, build->pakfire, path);
- if (r) {
- ERROR(build->pakfire, "Could not open source archive %s: %m\n", path);
- goto ERROR;
- }
-
- // Fetch package metadata
- r = pakfire_archive_make_package(archive, NULL, &package);
- if (r) {
- ERROR(build->pakfire, "Could not read package metadata: %m\n");
+ // Open the source package
+ r = pakfire_commandline_add(build->pakfire, path, &package);
+ if (r)
goto ERROR;
- }
const char* nevra = pakfire_package_get_string(package, PAKFIRE_PKG_NEVRA);
ERROR:
if (makefile)
pakfire_parser_unref(makefile);
- if (archive)
- pakfire_archive_unref(archive);
if (package)
pakfire_package_unref(package);
return pakfire_repo_create_from_repo(pakfire, pakfire->pool->installed);
}
+/*
+ Convenience function to add a package to the @commandline repository
+*/
+int pakfire_commandline_add(struct pakfire* pakfire, const char* path,
+ struct pakfire_package** package) {
+ struct pakfire_repo* repo = NULL;
+ int r;
+
+ // Find the commandline repository
+ repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_COMMANDLINE);
+ if (!repo) {
+ ERROR(pakfire, "Could not find the commandline repository: %m\n");
+ return 1;
+ }
+
+ // Add the package
+ r = pakfire_repo_add(repo, path, package);
+ if (r)
+ goto ERROR;
+
+ERROR:
+ if (repo)
+ pakfire_repo_unref(repo);
+
+ return r;
+}
+
static int pakfire_search_dep(struct pakfire* pakfire, Id type, const char* what, int flags,
struct pakfire_packagelist** list) {
int r;
return strcmp(n, name) == 0;
}
+static int pakfire_repo_is_commandline(struct pakfire_repo* repo) {
+ return pakfire_repo_name_equals(repo, PAKFIRE_REPO_COMMANDLINE);
+}
+
static int pakfire_repo_retrieve(
struct pakfire_repo* repo,
const char* title,
return (r == 0);
}
+static int pakfire_repo_download(struct pakfire_repo* repo, const char* url,
+ struct pakfire_package** package) {
+ struct pakfire_downloader* downloader = NULL;
+ FILE* f = NULL;
+ int r;
+
+ char path[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-download.XXXXXX";
+
+ // Allocate a temporary file name
+ f = pakfire_mktemp(path, 0);
+ if (!f) {
+ r = 1;
+ goto ERROR;
+ }
+
+ // Create the downloader
+ r = pakfire_downloader_create(&downloader, repo->pakfire);
+ if (r)
+ goto ERROR;
+
+ // Download the file
+ r = pakfire_downloader_retrieve(downloader, NULL, NULL, NULL,
+ url, path, 0, NULL, 0, PAKFIRE_TRANSFER_NOTEMP);
+ if (r)
+ goto ERROR;
+
+ // Try to add it to this repository
+ r = pakfire_repo_add(repo, path, package);
+ if (r)
+ goto ERROR;
+
+ERROR:
+ if (downloader)
+ pakfire_downloader_unref(downloader);
+ if (f)
+ fclose(f);
+
+ return r;
+}
+
+int pakfire_repo_add(struct pakfire_repo* repo, const char* path,
+ struct pakfire_package** package) {
+ struct pakfire_archive* archive = NULL;
+ int r;
+
+ // This operation is only supported for the command line repository
+ if (!pakfire_repo_is_commandline(repo)) {
+ errno = ENOTSUP;
+ return 1;
+ }
+
+ // Download the package if we got given a URL
+ if (pakfire_string_is_url(path))
+ return pakfire_repo_download(repo, path, package);
+
+ // Try to open the archive
+ r = pakfire_archive_open(&archive, repo->pakfire, path);
+ if (r)
+ goto ERROR;
+
+ // Add it to this repository
+ r = pakfire_repo_add_archive(repo, archive, package);
+ if (r)
+ goto ERROR;
+
+ const char* nevra = pakfire_package_get_string(*package, PAKFIRE_PKG_NEVRA);
+ if (!nevra) {
+ r = 1;
+ goto ERROR;
+ }
+
+ DEBUG(repo->pakfire, "Added %s to repository '%s'\n",
+ nevra, pakfire_repo_get_name(repo));
+
+ERROR:
+ if (archive)
+ pakfire_archive_unref(archive);
+
+ return r;
+}
+
PAKFIRE_EXPORT int pakfire_repo_read_solv(struct pakfire_repo* repo, FILE *f, int flags) {
f = pakfire_xfopen(f, "r");
if (!f)