wrote doInstall()
authorewt <devnull@localhost>
Mon, 8 Jan 1996 19:21:55 +0000 (19:21 +0000)
committerewt <devnull@localhost>
Mon, 8 Jan 1996 19:21:55 +0000 (19:21 +0000)
CVS patchset: 176
CVS date: 1996/01/08 19:21:55

install.c
install.h

index 1110e8d..fe7896f 100644 (file)
--- a/install.c
+++ b/install.c
@@ -1,18 +1,54 @@
 #include <fcntl.h>
+#include <unistd.h>
 
 #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);
     }
index 5874751..ebd3f92 100644 (file)
--- 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