From 9e4a0bef841306e1ff3cc3db7f56dcf7ad2f5402 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 25 Jul 2023 12:04:33 +0000 Subject: [PATCH] libpakfire: build: Use better return codes Signed-off-by: Michael Tremer --- src/libpakfire/build.c | 33 +++++++++++---------------------- tests/libpakfire/build.c | 4 ++-- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 28c6ad796..d5326db04 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -1318,8 +1318,7 @@ static int pakfire_build_parse_id(struct pakfire_build* build, const char* id) { r = uuid_parse(id, build->id); if (r) { ERROR(build->pakfire, "Could not parse build ID '%s'\n", id); - errno = EINVAL; - return r; + return -EINVAL; } // Otherwise initialize the Build ID with something random @@ -1429,10 +1428,8 @@ static int pakfire_build_mount_ccache(struct pakfire_build* build) { return 0; // Check that the path is set - if (!*build->ccache_path) { - errno = ENOTSUP; - return 1; - } + if (!*build->ccache_path) + return -ENOTSUP; // Make sure the path exists r = pakfire_mkdir(build->ccache_path, 0755); @@ -1604,16 +1601,12 @@ PAKFIRE_EXPORT struct pakfire_build* pakfire_build_unref(struct pakfire_build* b PAKFIRE_EXPORT int pakfire_build_set_ccache_path( struct pakfire_build* build, const char* path) { // Check if this can be called - if (pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_CCACHE)) { - errno = EPERM; - return 1; - } + if (pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_CCACHE)) + return -EPERM; // Check input value - if (!path || !*path) { - errno = EINVAL; - return 1; - } + if (!path || !*path) + return -EINVAL; // Store the path return pakfire_string_set(build->ccache_path, path); @@ -1945,10 +1938,8 @@ static int pakfire_build_copy_package(struct pakfire* pakfire, const char* target = (const char*)p; - if (!target) { - errno = EINVAL; - return 1; - } + if (!target) + return -EINVAL; // Fetch the package filename const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME); @@ -2314,10 +2305,8 @@ PAKFIRE_EXPORT int pakfire_build_mkimage(struct pakfire_build* build, int r; // Check inputs - if (!type || !f) { - errno = EINVAL; - return 1; - } + if (!type || !f) + return -EINVAL; // Create a path inside the build environment r = pakfire_path(build->pakfire, path, "%s", diff --git a/tests/libpakfire/build.c b/tests/libpakfire/build.c index 576698e13..eebfeb718 100644 --- a/tests/libpakfire/build.c +++ b/tests/libpakfire/build.c @@ -46,10 +46,10 @@ static int test_create_with_invalid_ids(const struct test* t) { struct pakfire_build* build = NULL; // Try to create a build with an invalid UUID - ASSERT_ERRNO(pakfire_build_create(&build, t->pakfire, "ABC", 0), EINVAL); + ASSERT(pakfire_build_create(&build, t->pakfire, "ABC", 0) == -EINVAL); // Try to create a build with an empty UUID - ASSERT_ERRNO(pakfire_build_create(&build, t->pakfire, "", 0), EINVAL); + ASSERT(pakfire_build_create(&build, t->pakfire, "", 0) == -EINVAL); return EXIT_SUCCESS; -- 2.39.5