return pakfire_repo_ref(pkg->repo);
}
-static void pakfire_package_dump_add_line(char** str, const char* key, const char* val) {
+static int pakfire_package_dump_add_line(char** str, const char* key, const char* val) {
if (val)
- asprintf(str, "%s%-15s: %s\n", (*str) ? *str : "", key ? key : "", val);
+ return asprintf(str, "%s%-15s: %s\n", (*str) ? *str : "", key ? key : "", val);
+
+ return 0;
}
-static void pakfire_package_dump_add_lines(char** str, const char* key, char** lines) {
+static int pakfire_package_dump_add_lines(char** str, const char* key, char** lines) {
+ int r = 0;
+
for (; *lines; lines++) {
- pakfire_package_dump_add_line(str, key, *lines);
+ r = pakfire_package_dump_add_line(str, key, *lines);
+ if (r < 0)
+ break;
// Reset the key after the first line
key = NULL;
}
+
+ return r;
}
-static void pakfire_package_dump_add_long_line(char** str, const char* key, const char* val) {
+static int pakfire_package_dump_add_long_line(char** str, const char* key, const char* val) {
char* p = NULL;
+ int r = 0;
// Copy the string onto the heap
char* buffer = strdupa(val);
if (!buffer)
- return;
+ return -errno;
const char* line = strtok_r(buffer, "\n", &p);
while (line) {
- pakfire_package_dump_add_line(str, key, line);
+ r = pakfire_package_dump_add_line(str, key, line);
+ if (r < 0)
+ break;
// Reset the key
key = NULL;
// Go to the next line
line = strtok_r(NULL, "\n", &p);
}
+
+ return r;
}
-static void pakfire_package_dump_add_line_date(char** str, const char* key, time_t date) {
+static int pakfire_package_dump_add_line_date(char** str, const char* key, time_t date) {
char buffer[1024];
int r;
// Format time
r = pakfire_strftime(buffer, "%a, %d %b %Y %T %z", date);
- if (r)
- return;
+ if (r < 0)
+ return r;
- pakfire_package_dump_add_line(str, key, buffer);
+ return pakfire_package_dump_add_line(str, key, buffer);
}
-static void pakfire_package_dump_add_line_hex(char** str,
+static int pakfire_package_dump_add_line_hex(char** str,
const char* key, const unsigned char* buffer, const size_t length) {
+ int r;
+
char* hex = __pakfire_hexlify(buffer, length);
if (!hex)
- return;
+ return -errno;
- pakfire_package_dump_add_line(str, key, hex);
+ r = pakfire_package_dump_add_line(str, key, hex);
free(hex);
+
+ return r;
}
-static void pakfire_package_dump_add_line_size(char** str, const char* key, size_t size) {
+static int pakfire_package_dump_add_line_size(char** str, const char* key, size_t size) {
char buffer[128];
// Format size in human-readable format
int r = pakfire_format_size(buffer, size);
if (r < 0)
- return;
+ return r;
- pakfire_package_dump_add_line(str, key, buffer);
+ return pakfire_package_dump_add_line(str, key, buffer);
}
static int pakfire_sort_dependencies(const void* p1, const void* p2) {
// Name
const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME);
- if (name)
- pakfire_package_dump_add_line(&string, _("Name"), name);
+ if (name) {
+ r = pakfire_package_dump_add_line(&string, _("Name"), name);
+ if (r < 0)
+ goto ERROR;
+ }
// EVR
const char* evr = pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR);
- if (evr)
- pakfire_package_dump_add_line(&string, _("Version"), evr);
+ if (evr) {
+ r = pakfire_package_dump_add_line(&string, _("Version"), evr);
+ if (r < 0)
+ goto ERROR;
+ }
// Arch
const char* arch = pakfire_package_get_string(pkg, PAKFIRE_PKG_ARCH);
- if (arch)
- pakfire_package_dump_add_line(&string, _("Arch"), arch);
+ if (arch) {
+ r = pakfire_package_dump_add_line(&string, _("Arch"), arch);
+ if (r < 0)
+ goto ERROR;
+ }
// Size
size_t size = pakfire_package_get_size(pkg);
- if (size)
- pakfire_package_dump_add_line_size(&string, _("Size"), size);
+ if (size) {
+ r = pakfire_package_dump_add_line_size(&string, _("Size"), size);
+ if (r < 0)
+ goto ERROR;
+ }
// Installed Size
if (pakfire_package_is_installed(pkg)) {
unsigned long long installsize = pakfire_package_get_num(pkg, PAKFIRE_PKG_INSTALLSIZE, 0);
- if (installsize)
- pakfire_package_dump_add_line_size(&string, _("Installed Size"), installsize);
+ if (installsize) {
+ r = pakfire_package_dump_add_line_size(&string, _("Installed Size"), installsize);
+ if (r < 0)
+ goto ERROR;
+ }
// Download Size
} else {
size_t downloadsize = pakfire_package_get_num(pkg, PAKFIRE_PKG_DOWNLOADSIZE, 0);
- if (downloadsize)
- pakfire_package_dump_add_line_size(&string, _("Download Size"), downloadsize);
+ if (downloadsize) {
+ r = pakfire_package_dump_add_line_size(&string, _("Download Size"), downloadsize);
+ if (r < 0)
+ goto ERROR;
+ }
}
// Repository
if (repo) {
if (!pakfire_repo_name_equals(repo, PAKFIRE_REPO_DUMMY)) {
const char* repo_name = pakfire_repo_get_name(repo);
- pakfire_package_dump_add_line(&string, _("Repo"), repo_name);
+
+ r = pakfire_package_dump_add_line(&string, _("Repo"), repo_name);
+ if (r < 0)
+ goto ERROR;
}
pakfire_repo_unref(repo);
// Summary
const char* summary = pakfire_package_get_string(pkg, PAKFIRE_PKG_SUMMARY);
- if (summary)
- pakfire_package_dump_add_line(&string, _("Summary"), summary);
+ if (summary) {
+ r = pakfire_package_dump_add_line(&string, _("Summary"), summary);
+ if (r < 0)
+ goto ERROR;
+ }
// Description
const char* description = pakfire_package_get_string(pkg, PAKFIRE_PKG_DESCRIPTION);
- if (description)
- pakfire_package_dump_add_long_line(&string, _("Description"), description);
+ if (description) {
+ r = pakfire_package_dump_add_long_line(&string, _("Description"), description);
+ if (r < 0)
+ goto ERROR;
+ }
// Groups
char** groups = pakfire_package_get_strings(pkg, PAKFIRE_PKG_GROUPS);
if (groups) {
- pakfire_package_dump_add_lines(&string, _("Groups"), groups);
+ r = pakfire_package_dump_add_lines(&string, _("Groups"), groups);
+ if (r < 0)
+ goto ERROR;
+
+ // XXX Needs free on error
pakfire_strings_free(groups);
}
// URL
const char* url = pakfire_package_get_string(pkg, PAKFIRE_PKG_URL);
- if (url)
+ if (url) {
pakfire_package_dump_add_line(&string, _("URL"), url);
+ if (r < 0)
+ goto ERROR;
+ }
// License
const char* license = pakfire_package_get_string(pkg, PAKFIRE_PKG_LICENSE);
- if (license)
- pakfire_package_dump_add_line(&string, _("License"), license);
+ if (license) {
+ r = pakfire_package_dump_add_line(&string, _("License"), license);
+ if (r < 0)
+ goto ERROR;
+ }
if (flags & PAKFIRE_PKG_DUMP_LONG) {
// Install Time
time_t install_time = pakfire_package_get_num(pkg, PAKFIRE_PKG_INSTALLTIME, 0);
- if (install_time)
- pakfire_package_dump_add_line_date(&string, _("Install Time"), install_time);
+ if (install_time) {
+ r = pakfire_package_dump_add_line_date(&string, _("Install Time"), install_time);
+ if (r < 0)
+ goto ERROR;
+ }
// Distribution
const char* distro = pakfire_package_get_string(pkg, PAKFIRE_PKG_DISTRO);
- if (distro)
- pakfire_package_dump_add_line(&string, _("Distribution"), distro);
+ if (distro) {
+ r = pakfire_package_dump_add_line(&string, _("Distribution"), distro);
+ if (r < 0)
+ goto ERROR;
+ }
// Packager
const char* packager = pakfire_package_get_string(pkg, PAKFIRE_PKG_PACKAGER);
- if (packager)
- pakfire_package_dump_add_line(&string, _("Packager"), packager);
+ if (packager) {
+ r = pakfire_package_dump_add_line(&string, _("Packager"), packager);
+ if (r < 0)
+ goto ERROR;
+ }
// Vendor
const char* vendor = pakfire_package_get_string(pkg, PAKFIRE_PKG_VENDOR);
- if (vendor)
- pakfire_package_dump_add_line(&string, _("Vendor"), vendor);
+ if (vendor) {
+ r = pakfire_package_dump_add_line(&string, _("Vendor"), vendor);
+ if (r < 0)
+ goto ERROR;
+ }
// UUID
const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
- if (uuid)
- pakfire_package_dump_add_line(&string, _("UUID"), uuid);
+ if (uuid) {
+ r = pakfire_package_dump_add_line(&string, _("UUID"), uuid);
+ if (r < 0)
+ goto ERROR;
+ }
// Build ID
const char* build_id = pakfire_package_get_string(pkg, PAKFIRE_PKG_BUILD_ID);
- if (build_id)
- pakfire_package_dump_add_line(&string, _("Build ID"), build_id);
+ if (build_id) {
+ r = pakfire_package_dump_add_line(&string, _("Build ID"), build_id);
+ if (r < 0)
+ goto ERROR;
+ }
// Build Arches
char** build_arches = pakfire_package_get_strings(pkg, PAKFIRE_PKG_BUILD_ARCHES);
if (build_arches) {
- pakfire_package_dump_add_lines(&string, _("Build Arch"), build_arches);
+ r = pakfire_package_dump_add_lines(&string, _("Build Arch"), build_arches);
+ if (r < 0)
+ goto ERROR;
+
+ // XXX needs free on error
pakfire_strings_free(build_arches);
}
// Digest
r = pakfire_package_get_checksum(pkg, &hash, &checksum, &checksum_length);
- if (r < 0) {
- errno = -r;
+ if (r < 0)
goto ERROR;
- }
switch (hash) {
case PAKFIRE_HASH_SHA2_512:
- pakfire_package_dump_add_line_hex(&string,
- _("SHA2-512 Checksum"), checksum, checksum_length);
+ r = pakfire_package_dump_add_line_hex(&string,
+ _("SHA2-512 Checksum"), checksum, checksum_length);
+ if (r < 0)
+ goto ERROR;
break;
case PAKFIRE_HASH_SHA2_256:
- pakfire_package_dump_add_line_hex(&string,
- _("SHA2-256 Checksum"), checksum, checksum_length);
+ r = pakfire_package_dump_add_line_hex(&string,
+ _("SHA2-256 Checksum"), checksum, checksum_length);
+ if (r < 0)
+ goto ERROR;
break;
case PAKFIRE_HASH_SHA3_512:
// Source package
const char* source_package = pakfire_package_get_string(pkg, PAKFIRE_PKG_SOURCE_PKG);
- if (source_package)
- pakfire_package_dump_add_line(&string, _("Source Package"), source_package);
+ if (source_package) {
+ r = pakfire_package_dump_add_line(&string, _("Source Package"), source_package);
+ if (r < 0)
+ goto ERROR;
+ }
// Build time
time_t build_time = pakfire_package_get_num(pkg, PAKFIRE_PKG_BUILD_TIME, 0);
- if (build_time)
- pakfire_package_dump_add_line_date(&string, _("Build Time"), build_time);
+ if (build_time) {
+ r = pakfire_package_dump_add_line_date(&string, _("Build Time"), build_time);
+ if (r < 0)
+ goto ERROR;
+ }
// Build host
const char* build_host = pakfire_package_get_string(pkg, PAKFIRE_PKG_BUILD_HOST);
- if (build_host)
- pakfire_package_dump_add_line(&string, _("Build Host"), build_host);
+ if (build_host) {
+ r = pakfire_package_dump_add_line(&string, _("Build Host"), build_host);
+ if (r < 0)
+ goto ERROR;
+ }
// Dependencies
for (const struct pakfire_dep* dep = pakfire_deps; dep->key; dep++) {
}
// Write it to the console
- pakfire_package_dump_add_lines(&string, name, deps);
+ r = pakfire_package_dump_add_lines(&string, name, deps);
+ if (r < 0)
+ goto ERROR;
+
+ // XXX needs free on error
pakfire_strings_free(deps);
}
}
pakfire_file* file = pakfire_filelist_get(filelist, i);
const char* path = pakfire_file_get_path(file);
- pakfire_package_dump_add_line(&string, prefix, path);
+ if (path) {
+ r = pakfire_package_dump_add_line(&string, prefix, path);
+ if (r < 0)
+ goto ERROR;
+ }
pakfire_file_unref(file);