summaryrefslogtreecommitdiff
path: root/tools/rpmdb2solv.c
blob: 81d58bd8121d70fa69956e4596390770dc7496b1 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (c) 2007, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

/*
 * rpmdb2solv
 * 
 */

#include <sys/types.h>
#include <limits.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "pool.h"
#include "repo.h"
#include "repo_rpmdb.h"
#include "repo_solv.h"
#include "common_write.h"

int
main(int argc, char **argv)
{
  Pool *pool = pool_create();
  Repo *repo, *ref = 0;
  FILE *fp;
  Pool *refpool;
  int c;
  const char *root = "/";
  const char *basefile = 0;

  while ((c = getopt (argc, argv, "b:r:")) >= 0)
    switch (c)
      {
      case 'r':
        root = optarg;
        break;
      case 'b':
        basefile = optarg;
        break;
      default:
	exit(1);
      }
  
  if (optind < argc)
    {
      refpool = pool;
      if ((fp = fopen(argv[optind], "r")) == NULL)
        {
          perror(argv[optind]);
          exit(1);
        }
      ref = repo_create(refpool, "ref");
      repo_add_solv(ref, fp);
      fclose(fp);
    }

  repo = repo_create(pool, "installed");
  repo_add_rpmdb(repo, ref, root);
  if (ref)
    {
      if (ref->pool != pool)
	pool_free(ref->pool);
      else
	repo_free(ref, 1);
      ref = 0;
    }

  tool_write(repo, basefile, 0);
  pool_free(pool);

  exit(0);
}