aboutsummaryrefslogtreecommitdiffstats
path: root/rpm-find-leaves.c
blob: c72337a254495a3f3ac3571cae8b912b6588e66f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <rpm/rpmlib.h>
#include <rpm/header.h>

static Header header;

#define die(f) { perror(f); exit(1); }

rpmdb open_rpmdb(void) {
  rpmdb db;
  if (rpmdbOpen("", &db, O_RDONLY, 0644)) die("rpmdbOpen");
  return db;
}

char *get(int_32 tag) {
  int_32 type, count;
  char *s;
  if (headerGetEntry(header, tag, &type, (void **) &s, &count) != 1) die("bad header ??");
  return s;
}


int main() {
  rpmTransactionSet trans;
  struct rpmDependencyConflict *conflicts;
  int numConflicts;
  rpmdb db;
  int i;

  rpmReadConfigFiles(NULL, NULL);

  db = open_rpmdb();

  for(i = rpmdbFirstRecNum(db); i; i = rpmdbNextRecNum(db, i)) {
    trans = rpmtransCreateSet(db, NULL);
    rpmtransRemovePackage(trans, i);
    if (rpmdepCheck(trans, &conflicts, &numConflicts)) die("rpmdepCheck");
    if (numConflicts == 0) {
      header = rpmdbGetRecord(db, i);
      printf("%s-%s-%s\n", get(RPMTAG_NAME), get(RPMTAG_VERSION), get(RPMTAG_RELEASE));
      headerFree(header);
    }
    rpmdepFreeConflicts(conflicts, numConflicts);
    rpmtransFree(trans);
  }
  exit(0);
}