<commit_before>/* vim: sw=2 et cino=>4,n-2,{1s
 */

/*
 * Copyright (c) 2009, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */


#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <zlib.h>

#include "pool.h"
#include "poolarch.h"
#include "repo_solv.h"
#ifndef DEBIAN
#include "repo_susetags.h"
#include "repo_rpmmd.h"
#else
#include "repo_deb.h"
#endif
#include "solver.h"
#include "solv_xfopen.h"


void
usage(char** argv)
{
  printf("Usage:\n%s: <arch> [options..] repo [--nocheck repo]...\n"
         "\t--exclude <pattern>\twhitespace-separated list of (sub-)"
         "packagenames to ignore\n"
         "\t--withsrc\t\tAlso check dependencies of src.rpm\n\n"
         , argv[0]);
  exit(1);
}


int
main(int argc, char **argv)
{
  Pool *pool;
  Solver *solv;
  Queue job;
  Queue rids;
  Queue cand;
  Queue archlocks;
  char *arch, *exclude_pat;
  int i, j;
  Id p;
  Id rpmid, rpmarch, rpmrel, archlock;
  int status = 0;
  int nocheck = 0;
  int withsrc = 0;

  exclude_pat = 0;
  archlock = 0;
  if (argc < 3)
    usage(argv);

  arch = argv[1];
  pool = pool_create();
  pool_setarch(pool, arch);
  for (i = 2; i < argc; i++)
    {
      FILE *fp;
      int l;

      if (!strcmp(argv[i], "--withsrc"))
	{
	  withsrc++;
	  continue;
	}
      if (!strcmp(argv[i], "--nocheck"))
	{
	  if (!nocheck)
	    nocheck = pool->nsolvables;
	  continue;
	}
      if (!strcmp(argv[i], "--exclude"))
        {
          if (i + 1 >= argc)
            {
              printf("--exclude needs a whitespace separated list of substrings as parameter\n");
              exit(1);
            }
          exclude_pat = argv[i + 1];
          ++i;
          continue;
        }
      l = strlen(argv[i]);
      if (!strcmp(argv[i], "-"))
	fp = stdin;
      else if ((fp = solv_xfopen(argv[i], 0)) == 0)
	{
	  perror(argv[i]);
	  exit(1);
	}
      Repo *repo = repo_create(pool, argv[i]);
#ifndef DEBIAN
      if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
	{
	  repo_add_susetags(repo, fp, 0, 0, 0);
	}
      else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
	{
	  repo_add_susetags(repo, fp, 0, 0, 0);
	}
      else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
	{
	  repo_add_rpmmd(repo, fp, 0, 0);
	}
#else
      if (l >= 8 && !strcmp(argv[i] + l - 8, "Packages"))
	{
	  repo_add_debpackages(repo, fp, 0);
	}
      else if (l >= 11 && !strcmp(argv[i] + l - 11, "Packages.gz"))
	{
	  repo_add_debpackages(repo, fp, 0);
	}
#endif
      else if (repo_add_solv(repo, fp))
	{
	  fprintf(stderr, "could not add repo %s\n", argv[i]);
	  exit(1);
	}
      if (fp != stdin)
        fclose(fp);
    }
  pool_addfileprovides(pool);
  pool_createwhatprovides(pool);
  rpmid = pool_str2id(pool, "rpm", 0);
  rpmarch = pool_str2id(pool, arch, 0);
  rpmrel = 0;
#ifndef DEBIAN
  if (rpmid && rpmarch)
    {
      for (p = 1; p < pool->nsolvables; p++)
	{
	  Solvable *s = pool->solvables + p;
	  if (s->name == rpmid && s->arch == rpmarch)
	    break;
	}
      if (p < pool->nsolvables)
        rpmrel = pool_rel2id(pool, rpmid, rpmarch, REL_ARCH, 1);
    }
#endif
  
  queue_init(&job);
  queue_init(&rids);
  queue_init(&cand);
  queue_init(&archlocks);
  for (p = 1; p < pool->nsolvables; p++)
    {
      Solvable *s = pool->solvables + p;
      if (!s->repo)
	continue;
      if (withsrc && (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC))
	{
	  queue_push(&cand, p);
	  continue;
	}
      if (!pool_installable(pool, s))
	continue;
      if (rpmrel && s->arch != rpmarch)
	{
	  Id rp, rpp;
	  FOR_PROVIDES(rp, rpp, s->name)
	    {
	      if (pool->solvables[rp].name != s->name)
		continue;
	      if (pool->solvables[rp].arch == rpmarch)
		break;
	    }
	  if (rp)
	    {
	      queue_push(&archlocks, p);
	      continue;
	    }
	}
      queue_push(&cand, p);
    }
  
  if (archlocks.count)
    {
      archlock = pool_queuetowhatprovides(pool, &archlocks);
    }
  /* prune cand by doing weak installs */
  while (cand.count)
    {
      solv = solver_create(pool);
      queue_empty(&job);
      for (i = 0; i < cand.count; i++)
	{
	  p = cand.elements[i];
	  queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
	  queue_push(&job, p);
	}
      if (rpmrel)
	{
	  queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME);
	  queue_push(&job, rpmrel);
	}
      if (archlock)
	{<commit_msg>Add --withobsoletes which checks for obsoleted packages<commit_after>/* vim: sw=2 et cino=>4,n-2,{1s
 */

/*
 * Copyright (c) 2009, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */


#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <zlib.h>

#include "pool.h"
#include "poolarch.h"
#include "repo_solv.h"
#ifndef DEBIAN
#include "repo_susetags.h"
#include "repo_rpmmd.h"
#else
#include "repo_deb.h"
#endif
#include "solver.h"
#include "solv_xfopen.h"


void
usage(char** argv)
{
  printf("Usage:\n%s: <arch> [options..] repo [--nocheck repo]...\n"
         "\t--exclude <pattern>\twhitespace-separated list of (sub-)"
         "packagenames to ignore\n"
         "\t--withobsoletes\t\tCheck for obsoletes on packages contained in repos\n"
         "\t--nocheck\t\tDo not warn about all following repos (only use them to fulfill dependencies)\n"
         "\t--withsrc\t\tAlso check dependencies of src.rpm\n\n"
         , argv[0]);
  exit(1);
}


int
main(int argc, char **argv)
{
  Pool *pool;
  Solver *solv;
  Queue job;
  Queue rids;
  Queue cand;
  Queue archlocks;
  char *arch, *exclude_pat;
  int i, j;
  Id p;
  Id rpmid, rpmarch, rpmrel, archlock;
  int status = 0;
  int nocheck = 0;
  int withsrc = 0;
  int obsoletepkgcheck = 0;

  exclude_pat = 0;
  archlock = 0;
  if (argc < 3)
    usage(argv);

  arch = argv[1];
  pool = pool_create();
  pool_setarch(pool, arch);
  for (i = 2; i < argc; i++)
    {
      FILE *fp;
      int l;

      if (!strcmp(argv[i], "--withsrc"))
	{
	  withsrc++;
	  continue;
	}
      if (!strcmp(argv[i], "--withobsoletes"))
        {
          obsoletepkgcheck++;
          continue;
        }
      if (!strcmp(argv[i], "--nocheck"))
	{
	  if (!nocheck)
	    nocheck = pool->nsolvables;
	  continue;
	}
      if (!strcmp(argv[i], "--exclude"))
        {
          if (i + 1 >= argc)
            {
              printf("--exclude needs a whitespace separated list of substrings as parameter\n");
              exit(1);
            }
          exclude_pat = argv[i + 1];
          ++i;
          continue;
        }
      l = strlen(argv[i]);
      if (!strcmp(argv[i], "-"))
	fp = stdin;
      else if ((fp = solv_xfopen(argv[i], 0)) == 0)
	{
	  perror(argv[i]);
	  exit(1);
	}
      Repo *repo = repo_create(pool, argv[i]);
#ifndef DEBIAN
      if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
	{
	  repo_add_susetags(repo, fp, 0, 0, 0);
	}
      else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
	{
	  repo_add_susetags(repo, fp, 0, 0, 0);
	}
      else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
	{
	  repo_add_rpmmd(repo, fp, 0, 0);
	}
#else
      if (l >= 8 && !strcmp(argv[i] + l - 8, "Packages"))
	{
	  repo_add_debpackages(repo, fp, 0);
	}
      else if (l >= 11 && !strcmp(argv[i] + l - 11, "Packages.gz"))
	{
	  repo_add_debpackages(repo, fp, 0);
	}
#endif
      else if (repo_add_solv(repo, fp))
	{
	  fprintf(stderr, "could not add repo %s\n", argv[i]);
	  exit(1);
	}
      if (fp != stdin)
        fclose(fp);
    }
  pool_addfileprovides(pool);
  pool_createwhatprovides(pool);
  rpmid = pool_str2id(pool, "rpm", 0);
  rpmarch = pool_str2id(pool, arch, 0);
  rpmrel = 0;
#ifndef DEBIAN
  if (rpmid && rpmarch)
    {
      for (p = 1; p < pool->nsolvables; p++)
	{
	  Solvable *s = pool->solvables + p;
	  if (s->name == rpmid && s->arch == rpmarch)
	    break;
	}
      if (p < pool->nsolvables)
        rpmrel = pool_rel2id(pool, rpmid, rpmarch, REL_ARCH, 1);
    }
#endif
  
  queue_init(&job);
  queue_init(&rids);
  queue_init(&cand);
  queue_init(&archlocks);
  for (p = 1; p < pool->nsolvables; p++)
    {
      Solvable *s = pool->solvables + p;
      if (!s->repo)
	continue;
      if (withsrc && (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC))
	{
	  queue_push(&cand, p);
	  continue;
	}
      if (!pool_installable(pool, s))
	continue;
      if (rpmrel && s->arch != rpmarch)
	{
	  Id rp, rpp;
	  FOR_PROVIDES(rp, rpp, s->name)
	    {
	      if (pool->solvables[rp].name != s->name)
		continue;
	      if (pool->solvables[rp].arch == rpmarch)
		break;
	    }
	  if (rp)
	    {
	      queue_push(&archlocks, p);
	      continue;
	    }
	}
      queue_push(&cand, p);
    }
  
  if (archlocks.count)
    {
      archlock = pool_queuetowhatprovides(pool, &archlocks);
    }


  if (obsoletepkgcheck)
    for (i = 0; i < cand.count; i++)
      {
        Solvable *s;
        s = pool->solvables + cand.elements[i];

        if (s->obsoletes)
          {
            Id op, opp;
            Id obs, *obsp = s->repo->idarraydata + s->obsoletes;

            while ((obs = *obsp++) != 0)
              {
                FOR_PROVIDES(op, opp, obs)
                  {
                    if (nocheck && op >= nocheck)
                      continue;

                    if (!solvable_identical(s, pool_id2solvable(pool, op))
                        && pool_match_nevr(pool, pool_id2solvable(pool, op), obs))
                        {
                          status = 2;
                          printf("can't install %s:\n", pool_solvid2str(pool, op));
                          printf("  package is obsoleted by %s\n", pool_solvable2str(pool, s));
                        }
                  }
              }
          }
      }

  /* prune cand by doing weak installs */
  while (cand.count)
    {
      solv = solver_create(pool);
      queue_empty(&job);
      for (i = 0; i < cand.count; i++)
	{
	  p = cand.elements[i];
	  queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
	  queue_push(&job, p);
	}
      if (rpmrel)
	{
	  queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME);
	  queue_push(&job, rpmrel);
	}
      if (archlock)
	{
{'fraction_non_alphanumeric': 0.1659974537263735, 'fraction_numerical': 0.012731368132406228, 'mean_word_length': 2.2470588235294118, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5860754', 'n_tokens_mistral': 4246, 'n_tokens_neox': 3950, 'n_words': 909}