2 * testpkg.c : Test a pacman package for validity
4 * Copyright (c) 2007 by Aaron Griffin <aaronmgriffin@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h> /* printf */
21 #include <stdarg.h> /* va_list */
25 #define BASENAME "testpkg"
27 static void output_cb(alpm_loglevel_t level
, const char *fmt
, va_list args
)
33 case ALPM_LOG_ERROR
: printf("error: "); break;
34 case ALPM_LOG_WARNING
: printf("warning: "); break;
35 default: return; /* skip other messages */
40 int main(int argc
, char *argv
[])
42 int retval
= 1; /* default = false */
43 alpm_handle_t
*handle
;
44 enum _alpm_errno_t err
;
45 alpm_pkg_t
*pkg
= NULL
;
48 fprintf(stderr
, "usage: %s <package file>\n", BASENAME
);
52 handle
= alpm_initialize(ROOTDIR
, DBPATH
, &err
);
54 fprintf(stderr
, "cannot initialize alpm: %s\n", alpm_strerror(err
));
58 /* let us get log messages from libalpm */
59 alpm_option_set_logcb(handle
, output_cb
);
61 if(alpm_pkg_load(handle
, argv
[1], 1, PM_PGP_VERIFY_OPTIONAL
, &pkg
) == -1
63 err
= alpm_errno(handle
);
66 printf("Cannot open the given file.\n");
68 case PM_ERR_LIBARCHIVE
:
69 case PM_ERR_PKG_INVALID
:
70 printf("Package is invalid.\n");
73 printf("libalpm error: %s\n", alpm_strerror(err
));
79 printf("Package is valid.\n");
83 if(alpm_release(handle
) == -1) {
84 fprintf(stderr
, "error releasing alpm\n");