}
static PyObject* Pakfire_repo_compose(PakfireObject* self, PyObject* args, PyObject* kwargs) {
- char* kwlist[] = { "path", NULL };
+ char* kwlist[] = { "path", "files", NULL };
const char* path = NULL;
+ PyObject* list = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &path))
+ PyObject* ret = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO", kwlist, &path, &list))
+ return NULL;
+
+ // List must be a sequence
+ if (!PySequence_Check(list)) {
+ PyErr_SetString(PyExc_ValueError, "Expected a sequence.");
return NULL;
+ }
const int flags = 0;
- int r = pakfire_repo_compose(self->pakfire, path, flags);
+ // How many new files do we have?
+ ssize_t num_files = PySequence_Length(list);
+ if (num_files < 0)
+ return NULL;
+
+ // Allocate files array
+ const char** files = calloc(num_files + 1, sizeof(*files));
+ if (!files) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+
+ for (int i = 0; i < num_files; i++) {
+ PyObject* file = PySequence_GetItem(list, i);
+ if (!file)
+ goto ERROR;
+
+ // Check if file is a Unicode object
+ if (!PyUnicode_Check(file)) {
+ PyErr_SetString(PyExc_ValueError, "Expected a string.");
+ goto ERROR;
+ }
+
+ // Add pointer to string to files array
+ files[i] = PyUnicode_AsUTF8(file);
+ if (!files[i])
+ goto ERROR;
+
+ Py_DECREF(file);
+ }
+
+ int r = pakfire_repo_compose(self->pakfire, path, flags, files);
if (r) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
- Py_RETURN_NONE;
+ // Return None on success
+ ret = Py_None;
+ Py_INCREF(ret);
+
+ERROR:
+ if (files)
+ free(files);
+
+ return ret;
}
static struct PyMethodDef Pakfire_methods[] = {
// Compose
-int pakfire_repo_compose(struct pakfire* pakfire, const char* path, int flags);
+int pakfire_repo_compose(struct pakfire* pakfire, const char* path, int flags,
+ const char** files);
#ifdef PAKFIRE_PRIVATE
return 0;
}
-PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* path, int flags) {
+PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* path,
+ int flags, const char** files) {
struct pakfire_repo* repo = NULL;
int r;
return 1;
}
+ size_t num_files = 0;
+
+ // Count files
+ if (files) {
+ for (const char** file = files; *file; file++)
+ num_files++;
+ }
+
char baseurl[PATH_MAX];
// Prefix path with file:// to form baseurl
goto ERROR;
}
- // XXX Add more files
+ struct pakfire_archive* archive = NULL;
+ struct pakfire_package* package = NULL;
+ char destination_path[PATH_MAX];
+
+ DEBUG(pakfire, "Adding %zu file(s) to the repository\n", num_files);
+
+ // Add more files
+ if (files) {
+ for (const char** file = files; *file; file++) {
+ DEBUG(pakfire, "Adding %s to repository...\n", *file);
+
+ // Open source archive
+ r = pakfire_archive_open(&archive, pakfire, *file);
+ if (r) {
+ ERROR(pakfire, "Could not open %s: %m\n", *file);
+ goto OUT;
+ }
+
+ // Add package metadata
+ r = pakfire_repo_add_archive(repo, archive, &package);
+ if (r) {
+ ERROR(pakfire, "Could not add %s to the repository: %m\n", *file);
+ goto OUT;
+ }
+
+ const char* filename = pakfire_package_get_filename(package);
+
+ // Make new path
+ r = pakfire_path_join(destination_path, path, filename);
+ if (r < 0)
+ goto OUT;
+
+ // Copying archive to destination
+ r = pakfire_archive_copy(archive, destination_path);
+ if (r) {
+ ERROR(pakfire, "Could not copy archive to %s: %m\n", destination_path);
+ goto OUT;
+ }
+
+ const char* repo_path = pakfire_path_relpath(path, destination_path);
+
+ // Update package location relative to the repository directory
+ pakfire_package_set_path(package, repo_path);
+
+OUT:
+ if (archive) {
+ pakfire_archive_unref(archive);
+ archive = NULL;
+ }
+ if (package) {
+ pakfire_package_unref(package);
+ package = NULL;
+ }
+
+ if (r)
+ goto ERROR;
+ }
+ }
// Write metadata to disk
r = pakfire_repo_write_metadata(repo);
repo_compose.add_argument("path",
help=_("The path to the repository"),
)
- repo_compose.add_argument("archive", nargs="+",
- help=_("Archives to be added to this repository")
+ repo_compose.add_argument("file", nargs="+",
+ help=_("Files to be added to this repository")
)
repo_compose.add_argument("--key",
help=_("Key used to sign archives"),
Composes a repository
"""
p = self.pakfire(ns)
- p.repo_compose(ns.path)
+ p.repo_compose(ns.path, files=ns.file)
def _shell(self, ns):
"""