]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: build: Use better return codes
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Jul 2023 12:04:33 +0000 (12:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Jul 2023 12:58:49 +0000 (12:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
tests/libpakfire/build.c

index 28c6ad796a24b678e5e47554e92d05b203905e2f..d5326db042b4397d6b707e8d089e7ca6be78301d 100644 (file)
@@ -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",
index 576698e13d28d3f86971aab190293bd05d84bf0f..eebfeb718a7f09b879e1e4d708493e6d43806a5c 100644 (file)
@@ -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;