Exemplo n.º 1
0
int
main(int argc, char **argv)
{
  const char **debs = 0;
  char *manifest = 0;
  int manifest0 = 0;
  int c, i, res, ndebs = 0;
  Pool *pool = pool_create();
  Repo *repo;
  FILE *fp;
  char buf[4096], *p;
  const char *basefile = 0;
  int is_repo = 0;

  while ((c = getopt(argc, argv, "0b:m:r")) >= 0)
    {
      switch(c)
	{
	case 'b':
	  basefile = optarg;
	  break;
	case 'm':
	  manifest = optarg;
	  break;
	case 'r':
	  is_repo = 1;
	  break;
	case '0':
	  manifest0 = 1;
	  break;
	default:
	  exit(1);
	}
    }
  if (manifest)
    {
      if (!strcmp(manifest, "-"))
        fp = stdin;
      else if ((fp = fopen(manifest, "r")) == 0)
	{
	  perror(manifest);
	  exit(1);
	}
      for (;;)
	{
	  if (manifest0)
	    {
	      if (!fgets0(buf, sizeof(buf), fp))
		break;
	    }
	  else
	    {
	      if (!fgets(buf, sizeof(buf), fp))
		break;
	      if ((p = strchr(buf, '\n')) != 0)
		*p = 0;
	    }
          debs = solv_extend(debs, ndebs, 1, sizeof(char *), 15);
	  debs[ndebs++] = strdup(buf);
	}
      if (fp != stdin)
        fclose(fp);
    }
  while (optind < argc)
    {
      debs = solv_extend(debs, ndebs, 1, sizeof(char *), 15);
      debs[ndebs++] = strdup(argv[optind++]);
    }
  repo = repo_create(pool, "deb2solv");
  repo_add_repodata(repo, 0);
  res = 0;
  if (!ndebs && !manifest && is_repo)
    {
      if (repo_add_debpackages(repo, stdin, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE))
	{
	  fprintf(stderr, "deb2solv: %s\n", pool_errstr(pool));
	  res = 1;
	}
    }
  for (i = 0; i < ndebs; i++)
    {
      if (is_repo)
	{
	  if ((fp = fopen(debs[i], "r")) == 0)
	    {
	      perror(debs[i]);
	      res = 1;
	      continue;
	    }
	  if (repo_add_debpackages(repo, fp, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE))
	    {
	      fprintf(stderr, "deb2solv: %s\n", pool_errstr(pool));
	      res = 1;
	    }
	  fclose(fp);
	  continue;
	}
      if (repo_add_deb(repo, debs[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE) == 0)
	{
	  fprintf(stderr, "deb2solv: %s\n", pool_errstr(pool));
	  res = 1;
	}
    }
  repo_internalize(repo);
  tool_write(repo, basefile, 0);
  pool_free(pool);
  for (c = 0; c < ndebs; c++)
    free((char *)debs[c]);
  solv_free(debs);
  exit(res);
}
Exemplo n.º 2
0
int
main(int argc, char **argv)
{
    const char **rpms = 0;
    char *manifest = 0;
    int manifest0 = 0;
    int c, i, res, nrpms = 0;
    Pool *pool = pool_create();
    Repo *repo;
    FILE *fp;
    char buf[4096], *p;
    const char *basefile = 0;
#ifdef ENABLE_PUBKEY
    int pubkeys = 0;
#endif

    while ((c = getopt(argc, argv, "0kKb:m:")) >= 0)
    {
        switch(c)
        {
        case 'b':
            basefile = optarg;
            break;
        case 'm':
            manifest = optarg;
            break;
        case '0':
            manifest0 = 1;
            break;
#ifdef ENABLE_PUBKEY
        case 'k':
            pubkeys = 1;
            break;
        case 'K':
            pubkeys = 2;
            break;
#endif
        default:
            exit(1);
        }
    }
    if (manifest)
    {
        if (!strcmp(manifest, "-"))
            fp = stdin;
        else if ((fp = fopen(manifest, "r")) == 0)
        {
            perror(manifest);
            exit(1);
        }
        for (;;)
        {
            if (manifest0)
            {
                if (!fgets0(buf, sizeof(buf), fp))
                    break;
            }
            else
            {
                if (!fgets(buf, sizeof(buf), fp))
                    break;
                if ((p = strchr(buf, '\n')) != 0)
                    *p = 0;
            }
            rpms = solv_extend(rpms, nrpms, 1, sizeof(char *), 15);
            rpms[nrpms++] = strdup(buf);
        }
        if (fp != stdin)
            fclose(fp);
    }
    while (optind < argc)
    {
        rpms = solv_extend(rpms, nrpms, 1, sizeof(char *), 15);
        rpms[nrpms++] = strdup(argv[optind++]);
    }
    repo = repo_create(pool, "rpms2solv");
    repo_add_repodata(repo, 0);
    res = 0;
    for (i = 0; i < nrpms; i++)
    {
#ifdef ENABLE_PUBKEY
        if (pubkeys == 2)
        {
            FILE *fp = solv_xfopen(rpms[i], "r");
            if (!fp)
            {
                perror(rpms[i]);
                res = 1;
                continue;
            }
            if (repo_add_keyring(repo, fp, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE|ADD_WITH_KEYSIGNATURES))
            {
                fprintf(stderr, "rpms2solv: %s\n", pool_errstr(pool));
                res = 1;
            }
            fclose(fp);
            continue;
        }
        if (pubkeys)
        {
            if (repo_add_pubkey(repo, rpms[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE|ADD_WITH_KEYSIGNATURES) == 0)
            {
                fprintf(stderr, "rpms2solv: %s\n", pool_errstr(pool));
                res = 1;
            }
            continue;
        }
#endif
        if (repo_add_rpm(repo, rpms[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE) == 0)
        {
            fprintf(stderr, "rpms2solv: %s\n", pool_errstr(pool));
            res = 1;
        }
    }
    repo_internalize(repo);
    tool_write(repo, basefile, 0);
    pool_free(pool);
    for (c = 0; c < nrpms; c++)
        free((char *)rpms[c]);
    solv_free(rpms);
    exit(res);
}