#include <pakfire/dist.h>
#include <pakfire/logging.h>
#include <pakfire/package.h>
+#include <pakfire/packager.h>
#include <pakfire/parser.h>
#include <pakfire/private.h>
#include <pakfire/types.h>
"\n" \
"exit 0\n"
-static int pakfire_build_package(Pakfire pakfire, PakfireParser makefile, const char* namespace) {
+static int pakfire_build_package(Pakfire pakfire, PakfireParser makefile,
+ const char* namespace, const char* target) {
PakfireRepo repo = NULL;
PakfirePackage pkg = NULL;
+ struct pakfire_packager* packager = NULL;
int r = 1;
// Expand the handle into the package name
goto ERROR;
}
+ // Create a packager
+ r = pakfire_packager_create(&packager, pkg);
+ if (r)
+ goto ERROR;
+
#ifdef ENABLE_DEBUG
char* dump = pakfire_package_dump(pkg, PAKFIRE_PKG_DUMP_LONG);
if (dump) {
}
#endif
+ // Write the finished package
+ r = pakfire_packager_finish_to_directory(packager, target);
+ if (r) {
+ ERROR(pakfire, "pakfire_packager_finish() failed: %s\n", strerror(errno));
+ goto ERROR;
+ }
+
// Success
r = 0;
ERROR:
+ if (packager)
+ pakfire_packager_unref(packager);
if (repo)
pakfire_repo_unref(repo);
if (pkg)
return r;
}
-static int pakfire_build_packages(Pakfire pakfire, PakfireParser makefile) {
+static int pakfire_build_packages(Pakfire pakfire, PakfireParser makefile, const char* target) {
DEBUG(pakfire, "Creating packages...");
int r = 1;
// Build packages in reverse order
for (int i = num_packages - 1; i >= 0; i--) {
- r = pakfire_build_package(pakfire, makefile, packages[i]);
+ r = pakfire_build_package(pakfire, makefile, packages[i], target);
if (r)
goto ERROR;
}
PakfireParser makefile = NULL;
struct pakfire_parser_error* error = NULL;
+ // Check for valid input
+ if (!path) {
+ errno = EINVAL;
+ return 1;
+ }
+
+ // The default target is the local repository path
+ if (!target) {
+ PakfireRepo repo = pakfire_get_repo(pakfire, "local");
+ if (!repo) {
+ errno = EINVAL;
+ return 1;
+ }
+
+ target = pakfire_repo_get_path(repo);
+ pakfire_repo_unref(repo);
+ }
+
// Read makefile
int r = pakfire_read_makefile(&makefile, pakfire, path, &error);
if (r) {
}
// Create the packages
- r = pakfire_build_packages(pakfire, makefile);
+ r = pakfire_build_packages(pakfire, makefile, target);
if (r) {
ERROR(pakfire, "Could not create packages: %s\n", strerror(errno));
goto ERROR;
#include <errno.h>
#include <fts.h>
-#include <dirent.h>
#include <fcntl.h>
#include <glob.h>
#include <stddef.h>
PakfirePackage pkg = NULL;
PakfireRepo repo = NULL;
- char tempfile[PATH_MAX];
-
- // Open the target directory
- DIR* d = opendir(target);
- if (!d)
- return 1;
-
- int dfd = dirfd(d);
-
// Load makefile
int r = pakfire_read_makefile(&makefile, pakfire, path, &error);
if (r) {
if (r)
goto ERROR;
- pakfire_string_format(tempfile, "%s/.pakfire-dist.XXXXXX", target);
-
- // Create a temporary result file
- FILE* f = pakfire_mktemp(tempfile);
- if (!f)
- goto ERROR;
-
// Write the finished package
- r = pakfire_packager_finish(packager, f);
- if (r) {
- ERROR(pakfire, "pakfire_packager_finish() failed: %s\n", strerror(errno));
- goto ERROR;
- }
-
- // Close the file
- fclose(f);
-
- const char* filename = pakfire_packager_filename(packager);
- if (!filename)
- goto ERROR;
-
- // Move the temporary file to destination
- r = renameat(AT_FDCWD, tempfile, dfd, filename);
+ r = pakfire_packager_finish_to_directory(packager, target);
if (r)
goto ERROR;
ERROR:
- // Remove the temporary file
- if (*tempfile)
- unlink(tempfile);
- closedir(d);
-
if (packager)
pakfire_packager_unref(packager);
if (pkg)
const char* pakfire_packager_filename(struct pakfire_packager* packager);
int pakfire_packager_finish(struct pakfire_packager* packager, FILE* f);
+int pakfire_packager_finish_to_directory(struct pakfire_packager* packager,
+ const char* target);
int pakfire_packager_add(struct pakfire_packager* packager,
const char* sourcepath, const char* path);
#include <pakfire/downloader.h>
int pakfire_repo_import(Pakfire pakfire, struct pakfire_config* config);
+const char* pakfire_repo_get_path(PakfireRepo repo);
void pakfire_repo_internalize(PakfireRepo repo);
Id pakfire_repo_add_solvable(PakfireRepo repo);
pakfire_packager_add;
pakfire_packager_create;
pakfire_packager_finish;
+ pakfire_packager_finish_to_directory;
pakfire_packager_ref;
pakfire_packager_unref;
# #
#############################################################################*/
+#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/limits.h>
return r;
}
+PAKFIRE_EXPORT int pakfire_packager_finish_to_directory(struct pakfire_packager* packager,
+ const char* target) {
+ DIR* d = NULL;
+ char path[PATH_MAX];
+ int r = 1;
+
+ // target cannot be empty
+ if (!target) {
+ errno = EINVAL;
+ return 1;
+ }
+
+ // Create a temporary file in the target directory
+ pakfire_string_format(path, "%s/.pakfire-package.XXXXXX", target);
+
+ // Create a temporary result file
+ FILE* f = pakfire_mktemp(path);
+ if (!f)
+ goto ERROR;
+
+ // Write the finished package
+ r = pakfire_packager_finish(packager, f);
+ if (r) {
+ ERROR(packager->pakfire, "pakfire_packager_finish() failed: %s\n",
+ strerror(errno));
+ goto ERROR;
+ }
+
+ // Close the file
+ fclose(f);
+ f = NULL;
+
+ // Get the filename of the package
+ const char* filename = pakfire_packager_filename(packager);
+ if (!filename) {
+ r = 1;
+ goto ERROR;
+ }
+
+ // Open the target directory
+ d = opendir(target);
+ if (!d) {
+ r = 1;
+ goto ERROR;
+ }
+
+ // Move the temporary file to destination
+ r = renameat(AT_FDCWD, path, dirfd(d), filename);
+ if (r)
+ goto ERROR;
+
+ DEBUG(packager->pakfire, "Package written to %s/%s\n", target, filename);
+
+ // Success
+ r = 0;
+
+ERROR:
+ // Remove temporary file
+ if (r && *path)
+ unlink(path);
+ if (f)
+ fclose(f);
+ if (d)
+ closedir(d);
+
+ return 0;
+}
+
PAKFIRE_EXPORT int pakfire_packager_add(struct pakfire_packager* packager,
const char* sourcepath, const char* path) {
FILE* f = NULL;
return pakfire_string_startswith(repo->appdata->baseurl, "file://");
}
-static const char* pakfire_repo_get_path(PakfireRepo repo) {
+const char* pakfire_repo_get_path(PakfireRepo repo) {
if (!pakfire_repo_is_local(repo))
return NULL;