]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Be more verbose when pakfire_create fails
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 May 2023 06:07:19 +0000 (06:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 May 2023 06:07:19 +0000 (06:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 93fd58d59563acc719b9248a0dc461315b1ff9d5..0e8776b0c270f3671f593e3968306f8c805559a6 100644 (file)
@@ -821,18 +821,6 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
        if (!arch)
                arch = pakfire_arch_native();
 
-       // Check if the architecture is supported
-       if (!pakfire_arch_supported(arch)) {
-               errno = EINVAL;
-               return 1;
-       }
-
-       // Path must be absolute
-       if (path && !pakfire_string_startswith(path, "/")) {
-               errno = EINVAL;
-               return 1;
-       }
-
        struct pakfire* p = calloc(1, sizeof(*p));
        if (!p)
                return 1;
@@ -840,9 +828,6 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
        p->nrefs = 1;
        p->flags = flags;
 
-       // Set architecture
-       pakfire_string_set(p->arch, arch);
-
        // Setup logging
        if (log_callback)
                pakfire_set_log_callback(p, log_callback, log_data);
@@ -858,6 +843,24 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
                        pakfire_log_set_priority(p, log_priority(env));
        }
 
+
+       // Check if the architecture is supported
+       if (!pakfire_arch_supported(arch)) {
+               ERROR(p, "Unsupported architecture: %s\n", arch);
+               errno = EINVAL;
+               goto ERROR;
+       }
+
+       // Set architecture
+       pakfire_string_set(p->arch, arch);
+
+       // Path must be absolute
+       if (path && !pakfire_string_startswith(path, "/")) {
+               ERROR(p, "Invalid path: %s\n", path);
+               errno = EINVAL;
+               goto ERROR;
+       }
+
        // Generate a random path if none is set
        if (!path) {
                path = pakfire_mkdtemp(tempdir);