1996-01-06 02:12:55 +08:00
|
|
|
#include <fcntl.h>
|
1996-01-09 03:21:55 +08:00
|
|
|
#include <unistd.h>
|
1996-01-06 02:12:55 +08:00
|
|
|
|
|
|
|
#include "install.h"
|
|
|
|
#include "lib/rpmlib.h"
|
1996-01-09 03:21:55 +08:00
|
|
|
#include "messages.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-01-09 03:21:55 +08:00
|
|
|
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)) {
|
1996-01-10 05:51:53 +08:00
|
|
|
/* try opening it O_CREAT */
|
|
|
|
mode |= O_CREAT;
|
|
|
|
if (!rpmdbOpen(prefix, &db, mode, 0644)) {
|
|
|
|
fprintf(stderr, "error: cannot open %s/var/lib/rpm/packages.rpm\n",
|
|
|
|
prefix);
|
|
|
|
exit(1);
|
|
|
|
}
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1996-01-14 06:02:24 +08:00
|
|
|
rc = rpmInstallPackage(prefix, db, fd, installFlags, test);
|
1996-01-09 03:21:55 +08:00
|
|
|
if (rc == 1) {
|
1996-01-14 06:02:24 +08:00
|
|
|
fprintf(stderr, "error: %s cannot be installed\n", arg);
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
rpmdbClose(db);
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void doUninstall(char * prefix, char * arg, int test, int uninstallFlags) {
|
|
|
|
rpmdb db;
|
|
|
|
dbIndexSet matches;
|
|
|
|
int i;
|
1996-01-09 03:21:55 +08:00
|
|
|
int mode;
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-01-09 03:21:55 +08:00
|
|
|
if (test)
|
|
|
|
mode = O_RDONLY;
|
|
|
|
else
|
|
|
|
mode = O_RDWR | O_EXCL;
|
|
|
|
|
|
|
|
if (!rpmdbOpen(prefix, &db, mode, 0644)) {
|
1996-01-06 02:12:55 +08:00
|
|
|
fprintf(stderr, "cannot open %s/var/lib/rpm/packages.rpm\n", prefix);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rpmdbFindPackage(db, arg, &matches)) {
|
|
|
|
fprintf(stderr, "package %s is not installed\n", arg);
|
|
|
|
} else {
|
|
|
|
if (matches.count > 1) {
|
|
|
|
fprintf(stderr, "\"%s\" specifies multiple packages\n", arg);
|
|
|
|
}
|
1996-01-06 08:05:14 +08:00
|
|
|
else {
|
|
|
|
for (i = 0; i < matches.count; i++) {
|
|
|
|
rpmRemovePackage(prefix, db, matches.recs[i].recOffset, test);
|
|
|
|
}
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
freeDBIndexRecord(matches);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmdbClose(db);
|
|
|
|
}
|