#include <errno.h>
#include <pakfire/constants.h>
+#include <pakfire/dist.h>
#include <pakfire/execute.h>
#include <pakfire/logging.h>
#include <pakfire/packagelist.h>
return ret;
}
+static PyObject* Pakfire_dist(PakfireObject* self, PyObject* args) {
+ const char* path = NULL;
+ const char* target = NULL;
+
+ if (!PyArg_ParseTuple(args, "s|z", &path, &target))
+ return NULL;
+
+ int r = pakfire_dist(self->pakfire, path, target);
+ if (r) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
static struct PyMethodDef Pakfire_methods[] = {
+ {
+ "dist",
+ (PyCFunction)Pakfire_dist,
+ METH_VARARGS,
+ NULL
+ },
{
"execute",
(PyCFunction)Pakfire_execute,
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2021 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <errno.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+#include <pakfire/dist.h>
+#include <pakfire/logging.h>
+#include <pakfire/package.h>
+#include <pakfire/packager.h>
+#include <pakfire/pakfire.h>
+#include <pakfire/parser.h>
+#include <pakfire/private.h>
+#include <pakfire/repo.h>
+#include <pakfire/types.h>
+
+PAKFIRE_EXPORT int pakfire_dist(Pakfire pakfire, const char* path, const char* target) {
+ PakfireParser makefile;
+ struct pakfire_parser_error* error = NULL;
+
+ struct pakfire_packager* packager = NULL;
+ PakfirePackage pkg = NULL;
+
+ char* filename = 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 (error)
+ pakfire_parser_error_unref(error);
+
+ return r;
+ }
+
+ PakfireRepo repo = pakfire_repo_create(pakfire, "dummy");
+ if (!repo)
+ goto ERROR;
+
+ // Get the package object
+ r = pakfire_parser_create_package(makefile, &pkg, repo, NULL);
+ if (r)
+ goto ERROR;
+
+ // Set architecture to source
+ pakfire_package_set_arch(pkg, "src");
+
+ // Create a packager
+ r = pakfire_packager_create(&packager, pkg);
+ if (r)
+ goto ERROR;
+
+ // Add the makefile
+ r = pakfire_packager_add(packager, path);
+ if (r)
+ goto ERROR;
+
+ snprintf(tempfile, PATH_MAX - 1, "%s/.pakfire-dist.XXXXXX", target);
+
+ // Create a temporary result file
+ int fd = mkostemp(tempfile, O_CLOEXEC);
+ if (fd < 0)
+ goto ERROR;
+
+ // Re-open as file handle
+ FILE* f = fdopen(fd, "w");
+
+ // Write the finished package
+ filename = pakfire_packager_finish(packager, f);
+ if (!filename) {
+ ERROR(pakfire, "pakfire_packager_finish() failed: %s\n", strerror(errno));
+ goto ERROR;
+ }
+
+ // Close the file
+ fclose(f);
+
+ // Move the temporary file to destination
+ r = renameat(AT_FDCWD, tempfile, dfd, filename);
+ if (r)
+ goto ERROR;
+
+ERROR:
+ // Remove the temporary file
+ if (*tempfile)
+ unlink(tempfile);
+
+ if (filename)
+ free(filename);
+ closedir(d);
+
+ if (packager)
+ pakfire_packager_unref(packager);
+ if (pkg)
+ pakfire_package_unref(pkg);
+ if (repo)
+ pakfire_repo_unref(repo);
+ pakfire_parser_unref(makefile);
+
+ return r;
+}
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2021 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef PAKFIRE_DIST_H
+#define PAKFIRE_DIST_H
+
+#include <pakfire/types.h>
+
+int pakfire_dist(Pakfire pakfire, const char* path, const char* target);
+
+#endif /* PAKFIRE_DIST_H */