]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Add function to fetch the desired filename
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 30 Mar 2025 16:28:07 +0000 (16:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 30 Mar 2025 16:28:07 +0000 (16:28 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/archive.c
src/pakfire/archive.h
src/python/archive.c
tests/libpakfire/makefile.c
tests/python/dist.py

index 40dc5ce89e464293ebd922fbcc28b55e940201d2..588d83f822f8c14673f3e3606a40200948de018e 100644 (file)
@@ -1414,6 +1414,27 @@ const char* pakfire_archive_get_path(struct pakfire_archive* archive) {
        return archive->path;
 }
 
+const char* pakfire_archive_get_filename(struct pakfire_archive* self) {
+       struct pakfire_package* pkg = NULL;
+       const char* filename = NULL;
+
+       // Fetch the package
+       pkg = pakfire_archive_get_package(self);
+       if (!pkg)
+               goto ERROR;
+
+       // Fetch the filename from the package
+       filename = pakfire_package_get_filename(pkg);
+       if (!filename)
+               goto ERROR;
+
+ERROR:
+       if (pkg)
+               pakfire_package_unref(pkg);
+
+       return filename;
+}
+
 unsigned int pakfire_archive_get_format(struct pakfire_archive* archive) {
        return archive->format;
 }
index ad62fe0a72b4334f76e48781f84ed881903467b6..30e578d7cf183b76bd51a8116399f9d33107f4ab 100644 (file)
@@ -49,6 +49,7 @@ int pakfire_archive_extract(struct pakfire_archive* archive,
        const char* path, const int flags, struct pakfire_progress* parent);
 
 const char* pakfire_archive_get_path(struct pakfire_archive* archive);
+const char* pakfire_archive_get_filename(struct pakfire_archive* self);
 
 unsigned int pakfire_archive_get_format(struct pakfire_archive* archive);
 
index 1947c013251130d28edbbd6d8f8d4622f01fc9cd..9c60aa79d749c1f8a4b7cef1c0d82f5907a26688 100644 (file)
@@ -190,6 +190,14 @@ static PyObject* Archive_get_path(ArchiveObject* self) {
        return PyUnicode_FromString(path);
 }
 
+static PyObject* Archive_get_filename(ArchiveObject* self) {
+       const char* filename = pakfire_archive_get_filename(self->archive);
+       if (!filename)
+               Py_RETURN_NONE;
+
+       return PyUnicode_FromString(filename);
+}
+
 static PyObject* Archive_get_filelist(ArchiveObject* self) {
        struct pakfire_filelist* filelist = NULL;
        int r;
@@ -253,6 +261,13 @@ static struct PyGetSetDef Archive_getsetters[] = {
                NULL,
                NULL
        },
+       {
+               "filename",
+               (getter)Archive_get_filename,
+               NULL,
+               NULL,
+               NULL
+       },
        {
                "format",
                (getter)Archive_get_format,
index b34f59a3741d8eaa91ba1f74af7449e529ed5e47..5ea58749b19d339b14c5df6b81d198c738ba261c 100644 (file)
@@ -199,6 +199,9 @@ static int test_dist_dummy(const struct test* t) {
                free(dump);
        }
 
+       // Check filename
+       ASSERT_STRING_EQUALS(pakfire_archive_get_filename(archive), "dummy-1.0-1.test1.src.pfm");
+
        // Check name
        const char* name = pakfire_package_get_string(package, PAKFIRE_PKG_NAME);
        ASSERT_STRING_EQUALS(name, "dummy");
index 410a5cde1e57d0c5618eacf853003e1502414cb3..6a4f3ffd4019c9e965fe9d71f03eb59677f12e09 100755 (executable)
@@ -46,6 +46,9 @@ class DistTests(tests.TestCase):
 
                self.assertIsInstance(archive, pakfire.Archive)
 
+               # Check for the correct filename
+               self.assertEqual(archive.filename, "dummy-1.0-1.test1.src.pfm")
+
 
 if __name__ == "__main__":
        tests.main()