From 7e8774662974c8004ee254dbf34e13365e09949d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 5 May 2023 06:07:19 +0000 Subject: [PATCH] pakfire: Be more verbose when pakfire_create fails Signed-off-by: Michael Tremer --- src/libpakfire/pakfire.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 93fd58d59..0e8776b0c 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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); -- 2.39.5