Created
October 6, 2015 15:56
-
-
Save zeph1e/4a360f5e647df4016be9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* RPM C API test based on : | |
* http://rpm5.org/docs/api/rpminstall_8c-source.html#l00287 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <sys/stat.h> | |
#include <rpm/rpmlib.h> | |
#include <rpm/rpmts.h> | |
#include <rpm/rpmps.h> | |
#include <rpm/rpmcli.h> | |
int main(int argc, char *argv[]) | |
{ | |
rpmdb db; | |
QVA_t ia; | |
rpmts ts = 0; | |
rpmps ps = 0; | |
FD_t fd = 0; | |
Header header = 0; | |
int rc = -1; | |
if (argc < 2) { | |
fprintf(stderr, "Usage: %s <rpmfile>\n", argv[0]); | |
goto terminate; | |
} | |
rpmReadConfigFiles(0, 0); | |
fd = Fopen(argv[1], "r.fpio"); | |
if (!fd || Ferror(fd)) { | |
fprintf(stderr, "Failed to open file: %s\n", argv[1]); | |
goto terminate; | |
} | |
ts = rpmtsCreate(); | |
if (rpmReadPackageFile(ts, fd, argv[1], &header)) { | |
fprintf(stderr, "Failed to read header from : %s\n", argv[1]); | |
goto terminate; | |
} | |
rpmtsSetRootDir(ts, "/"); | |
// concern about http://rpm5.org/docs/api/rpminstall_8c-source.html#l00561 | |
{ | |
int type, count; | |
char * buf; | |
headerGetEntry(header, RPMTAG_NAME, &type, (void**) &buf, &count); | |
//headerNVR(header, &buf, 0, 0); | |
printf("%s\n", buf); | |
headerFreeData(buf, type); | |
} | |
rpmtsSetNotifyCallback(ts, rpmShowProgress, 0); | |
if (rpmtsAddInstallElement(ts, header, (fnpyKey)argv[1], 1, 0)) { | |
fprintf(stderr, "rpmtsAddInstallElement: %d\n", rc); | |
goto terminate; | |
} | |
rpmtsClean(ts); | |
rc = rpmtsRun(ts, 0, RPMPROB_FILTER_NONE); | |
if (rc) | |
fprintf(stderr, "rpmtsRun failed\n"); | |
terminate: | |
if (header) headerFree(header); | |
if (ts) rpmtsFree(ts); | |
if (fd) Fclose(fd); | |
return rc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment