From: Michael Tremer Date: Fri, 15 Jul 2022 12:33:25 +0000 (+0000) Subject: archive: Expose filelist as property X-Git-Tag: 0.9.28~714 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80b4d7e66011b73f1f85d79880150cab79509b0f;p=pakfire.git archive: Expose filelist as property Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/archive.c b/src/_pakfire/archive.c index 5d9618842..b11cb403d 100644 --- a/src/_pakfire/archive.c +++ b/src/_pakfire/archive.c @@ -207,6 +207,56 @@ static PyObject* Archive_get_path(ArchiveObject* self) { return PyUnicode_FromString(path); } +static PyObject* Archive_get_filelist(ArchiveObject* self) { + int r; + + // Fetch the filelist + struct pakfire_filelist* filelist = pakfire_archive_get_filelist(self->archive); + if (!filelist) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + + const size_t size = pakfire_filelist_size(filelist); + + // Create a new Python list + PyObject* list = PyList_New(0); + if (!list) + goto ERROR; + + for (unsigned int i = 0; i < size; i++) { + struct pakfire_file* file = pakfire_filelist_get(filelist, i); + if (!file) + goto ERROR; + + // Fetch the path + const char* path = pakfire_file_get_path(file); + + // Convert path to string + PyObject* obj = PyUnicode_FromString(path); + + // Append the new object to the list + r = PyList_Append(list, obj); + Py_DECREF(obj); + + // If we could not append to the list, we will break + if (r) { + Py_DECREF(list); + list = NULL; + goto ERROR; + } + + // Free file + pakfire_file_unref(file); + } + +ERROR: + if (filelist) + pakfire_filelist_unref(filelist); + + return list; +} + static struct PyMethodDef Archive_methods[] = { { "extract", @@ -248,6 +298,13 @@ static struct PyMethodDef Archive_methods[] = { }; static struct PyGetSetDef Archive_getsetters[] = { + { + "filelist", + (getter)Archive_get_filelist, + NULL, + NULL, + NULL + }, { "format", (getter)Archive_get_format,