summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/util/testpkg.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index e32b013d..64056ce4 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -29,44 +29,58 @@
static void output_cb(pmloglevel_t level, char *fmt, va_list args)
{
- if(strlen(fmt)) {
- switch(level) {
- case PM_LOG_ERROR: printf("error: "); break;
- case PM_LOG_WARNING: printf("warning: "); break;
- default: break;
- }
- vprintf(fmt, args);
- }
+ if(fmt[0] == '\0') {
+ return;
+ }
+ switch(level) {
+ case PM_LOG_ERROR: printf("error: "); break;
+ case PM_LOG_WARNING: printf("warning: "); break;
+ default: return; /* skip other messages */
+ }
+ vprintf(fmt, args);
}
int main(int argc, char **argv)
{
- int retval = 1; /* default = false */
- pmpkg_t *pkg = NULL;
+ int retval = 1; /* default = false */
+ pmpkg_t *pkg = NULL;
- if(argc != 2) {
+ if(argc != 2) {
fprintf(stderr, "usage: %s <package file>\n", BASENAME);
return(1);
}
if(alpm_initialize() == -1) {
- fprintf(stderr, "cannot initilize alpm: %s\n", alpm_strerrorlast());
- return(1);
+ fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
+ return(1);
}
- /* let us get log messages from libalpm */
+ /* let us get log messages from libalpm */
alpm_option_set_logcb(output_cb);
if(alpm_pkg_load(argv[1], 1, &pkg) == -1 || pkg == NULL) {
- retval = 1;
+ switch(pm_errno) {
+ case PM_ERR_PKG_OPEN:
+ printf("Cannot open the given file.\n");
+ break;
+ case PM_ERR_LIBARCHIVE_ERROR:
+ case PM_ERR_PKG_INVALID:
+ printf("Package is invalid.\n");
+ break;
+ default:
+ printf("libalpm error: %s\n", alpm_strerrorlast());
+ break;
+ }
+ retval = 1;
} else {
alpm_pkg_free(pkg);
- retval = 0;
+ printf("Package is valid.\n");
+ retval = 0;
}
if(alpm_release() == -1) {
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
}
- return(retval);
+ return(retval);
}