From bd01c5d1edef5d08625b7893136daf961d0dfce5 Mon Sep 17 00:00:00 2001 From: ewt Date: Mon, 8 Jan 1996 19:21:55 +0000 Subject: [PATCH] wrote doInstall() CVS patchset: 176 CVS date: 1996/01/08 19:21:55 --- install.c | 42 +++++++++++++++++++++++++++++++++++++++--- install.h | 2 +- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/install.c b/install.c index 1110e8d..fe7896f 100644 --- a/install.c +++ b/install.c @@ -1,18 +1,54 @@ #include +#include #include "install.h" #include "lib/rpmlib.h" +#include "messages.h" -void doInstall(char * prefix, int test, int installFlags) { - printf("I can't install packages yet"); +void doInstall(char * prefix, char * arg, int test, int installFlags) { + rpmdb db; + int fd; + int mode, rc; + + if (test) + mode = O_RDONLY; + else + mode = O_RDWR | O_EXCL; + + if (!rpmdbOpen(prefix, &db, mode, 0644)) { + fprintf(stderr, "error: cannot open %s/var/lib/rpm/packages.rpm\n", prefix); + exit(1); + } + + message(MESS_DEBUG, "installing %s\n", arg); + fd = open(arg, O_RDONLY); + if (fd < 0) { + rpmdbClose(db); + fprintf(stderr, "error: cannot open %s\n", arg); + return; + } + + rc = rpmInstallPackage(prefix, db, fd, test); + if (rc == 1) { + fprintf(stderr, "error: %s is not a RPM package\n", arg); + } + + close(fd); + rpmdbClose(db); } void doUninstall(char * prefix, char * arg, int test, int uninstallFlags) { rpmdb db; dbIndexSet matches; int i; + int mode; - if (!rpmdbOpen(prefix, &db, O_RDWR | O_EXCL, 0644)) { + if (test) + mode = O_RDONLY; + else + mode = O_RDWR | O_EXCL; + + if (!rpmdbOpen(prefix, &db, mode, 0644)) { fprintf(stderr, "cannot open %s/var/lib/rpm/packages.rpm\n", prefix); exit(1); } diff --git a/install.h b/install.h index 5874751..ebd3f92 100644 --- a/install.h +++ b/install.h @@ -1,7 +1,7 @@ #ifndef _H_INSTALL #define _H_INSTALL -void doInstall(char * prefix, int test, int installFlags); +void doInstall(char * prefix, char * arg, int test, int installFlags); void doUninstall(char * prefix, char * arg, int test, int uninstallFlags); #endif -- 2.7.4