Ejemplo n.º 1
0
void
expire(const symboldb_options &opt, database &db)
{
  if (opt.output != symboldb_options::quiet) {
    fprintf(stderr, "info: expiring URL cache\n");
  }
  db.expire_url_cache();

  if (opt.output != symboldb_options::quiet) {
    fprintf(stderr, "info: expiring unreferenced packages\n");
  }
  db.expire_packages();

  if (opt.output != symboldb_options::quiet) {
    fprintf(stderr, "info: expiring file contents\n");
  }
  db.expire_file_contents();

  if (opt.output != symboldb_options::quiet) {
    fprintf(stderr, "info: expiring java classes\n");
  }
  db.expire_java_classes();

  if (opt.output != symboldb_options::quiet) {
    fprintf(stderr, "info: expiring unused RPMs\n");
  }
  {
    typedef std::vector<std::vector<unsigned char> > digvec;
    std::tr1::shared_ptr<file_cache> fcache(opt.rpm_cache());
    digvec fcdigests;
    fcache->digests(fcdigests);
    std::sort(fcdigests.begin(), fcdigests.end());
    digvec dbdigests;
    db.referenced_package_digests(dbdigests);
    digvec result;
    std::set_difference(fcdigests.begin(), fcdigests.end(),
			dbdigests.begin(), dbdigests.end(),
			std::back_inserter(result));
    fd_handle dir;
    dir.open_directory(opt.rpm_cache_path().c_str());
    for (digvec::iterator p = result.begin(), end = result.end();
	 p != end; ++p) {
      dir.unlinkat(base16_encode(p->begin(), p->end()).c_str(), 0);
    }
  }
}
Ejemplo n.º 2
0
static int
do_show_stale_cached_rpms(const symboldb_options &opt, database &db)
{
  typedef std::vector<std::vector<unsigned char> > digvec;
  std::tr1::shared_ptr<file_cache> fcache(opt.rpm_cache());
  digvec fcdigests;
  fcache->digests(fcdigests);
  std::sort(fcdigests.begin(), fcdigests.end());
  digvec dbdigests;
  db.referenced_package_digests(dbdigests);
  digvec result;
  std::set_difference(fcdigests.begin(), fcdigests.end(),
		      dbdigests.begin(), dbdigests.end(),
		      std::back_inserter(result));
  for (digvec::iterator p = result.begin(), end = result.end();
       p != end; ++p) {
    printf("%s\n", base16_encode(p->begin(), p->end()).c_str());
  }
  return 0;
}
Ejemplo n.º 3
0
bool get_file(const symboldb_options &opt, database &db,
	      const std::vector<unsigned char> &digest, sink &target)
{
  database::files_with_digest fwd(db, digest);
  std::shared_ptr<file_cache> fcache(opt.rpm_cache());
  checksum csum;
  csum.length = checksum::no_length;
  std::string rpm_path;
  rpm_file_entry rfe;
  while (fwd.next()) {
    csum.value = fwd.rpm_digest();
    switch (csum.value.size()) {
    case 32:
      csum.type = hash_algorithm::sha256;
      break;
    case 20:
      csum.type = hash_algorithm::sha1;
      break;
    default:
      continue;
    }
    if (fcache->lookup_path(csum, rpm_path)) {
      rpm_parser rp(rpm_path.c_str());
      while (rp.read_file(rfe)) {
	typedef std::vector<rpm_file_info>::const_iterator iterator;
	const iterator end = rfe.infos.end();
	for (iterator p = rfe.infos.begin(); p != end; ++p) {
	  if (p->name == fwd.file_name()) {
	    target.write(rfe.contents);
	    return true;
	  }
	}
      }
    }
  }
  return false;
}