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
;
45 alpm_pkg_t
*pkg
= NULL
;
46 const alpm_siglevel_t level
= ALPM_SIG_PACKAGE
| ALPM_SIG_PACKAGE_OPTIONAL
;
49 fprintf(stderr
, "usage: %s <package file>\n", BASENAME
);
53 handle
= alpm_initialize(ROOTDIR
, DBPATH
, &err
);
55 fprintf(stderr
, "cannot initialize alpm: %s\n", alpm_strerror(err
));
59 /* let us get log messages from libalpm */
60 alpm_option_set_logcb(handle
, output_cb
);
62 /* set gpgdir to default */
63 alpm_option_set_gpgdir(handle
, GPGDIR
);
65 if(alpm_pkg_load(handle
, argv
[1], 1, level
, &pkg
) == -1
67 err
= alpm_errno(handle
);
69 case ALPM_ERR_PKG_NOT_FOUND
:
70 printf("Cannot find the given file.\n");
72 case ALPM_ERR_PKG_OPEN
:
73 printf("Cannot open the given file.\n");
75 case ALPM_ERR_LIBARCHIVE
:
76 case ALPM_ERR_PKG_INVALID
:
77 printf("Package is invalid.\n");
80 printf("libalpm error: %s\n", alpm_strerror(err
));
86 printf("Package is valid.\n");
90 if(alpm_release(handle
) == -1) {
91 fprintf(stderr
, "error releasing alpm\n");