Beispiel #1
0
END_TEST

START_TEST(test_goal_get_reason)
{
    HyPackage pkg = get_latest_pkg(test_globals.sack, "walrus");
    HyGoal goal = hy_goal_create(test_globals.sack);
    hy_goal_install(goal, pkg);
    hy_package_free(pkg);
    hy_goal_run(goal);

    HyPackageList plist = hy_goal_list_installs(goal);
    int i;
    int set = 0;
    FOR_PACKAGELIST(pkg, plist, i) {
	if (!strcmp(hy_package_get_name(pkg), "walrus")) {
	    set |= 1 << 0;
	    fail_unless(hy_goal_get_reason(goal, pkg) == HY_REASON_USER);
	}
	if (!strcmp(hy_package_get_name(pkg), "semolina")) {
	    set |= 1 << 1;
	    fail_unless(hy_goal_get_reason(goal, pkg) == HY_REASON_DEP);
	}
    }
    fail_unless(set == 3);

    hy_packagelist_free(plist);
    hy_goal_free(goal);
}
Beispiel #2
0
/**
 * hif_db_get_dir_for_package:
 **/
static gchar *
hif_db_get_dir_for_package (HyPackage package)
{
	const gchar *pkgid;
	gchar *dir = NULL;

	pkgid = hif_package_get_pkgid (package);
	if (pkgid == NULL)
		goto out;
	dir = g_strdup_printf ("/var/lib/yum/yumdb/%c/%s-%s-%s-%s-%s",
			       hy_package_get_name (package)[0],
			       pkgid,
			       hy_package_get_name (package),
			       hy_package_get_version (package),
			       hy_package_get_release (package),
			       hy_package_get_arch (package));
out:
	return dir;
}
Beispiel #3
0
END_TEST

START_TEST(test_filter_latest2)
{
    HyQuery q = hy_query_create(test_globals.sack);
    hy_query_filter(q, HY_PKG_NAME, HY_EQ, "flying");
    hy_query_filter_latest_per_arch(q, 1);
    HyPackageList plist = hy_query_run(q);
    fail_unless(hy_packagelist_count(plist) == 2);
    HyPackage pkg = hy_packagelist_get(plist, 0);
    fail_if(strcmp(hy_package_get_name(pkg), "flying"));
    fail_if(strcmp(hy_package_get_evr(pkg), "3.1-0"));
    pkg = hy_packagelist_get(plist, 1);
    fail_if(strcmp(hy_package_get_name(pkg), "flying"));
    fail_if(strcmp(hy_package_get_evr(pkg), "3.2-0"));

    hy_query_free(q);
    hy_packagelist_free(plist);

}
Beispiel #4
0
END_TEST

START_TEST(test_query_provides_in)
{
    HyPackage pkg;
    HyPackageList plist;
    char* pkg_names[] = { "P", "fool <= 2.0", "fool-lib > 3-3", NULL };
    HyQuery q = hy_query_create(test_globals.sack);
    hy_query_filter_provides_in(q, pkg_names);
    plist = hy_query_run(q);
    pkg = hy_packagelist_get(plist, 0);
    ck_assert_str_eq(hy_package_get_name(pkg), "fool");
    ck_assert_str_eq(hy_package_get_evr(pkg), "1-3");
    pkg = hy_packagelist_get(plist, 1);
    ck_assert_str_eq(hy_package_get_name(pkg), "penny");
    pkg = hy_packagelist_get(plist, 2);
    ck_assert_str_eq(hy_package_get_name(pkg), "fool");
    ck_assert_str_eq(hy_package_get_evr(pkg), "1-5");
    fail_unless(size_and_free(q) == 3);
    hy_packagelist_free(plist);
}
Beispiel #5
0
  FOR_PACKAGELIST(pkg, new_pkglist, i)
    {
      _cleanup_hyquery_ HyQuery query = NULL;
      _cleanup_hypackagelist_ HyPackageList pkglist = NULL;
      
      query = hy_query_create (orig_sack->sack);
      hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg));
      hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
      pkglist = hy_query_run (query);

      if (hy_packagelist_count (pkglist) == 0)
        g_ptr_array_add (ret_added, _rpm_ostree_package_new (new_sack, pkg));
    }
Beispiel #6
0
END_TEST

START_TEST(test_query_enhances)
{
    HyPackageList plist;
    HyPackage pkg;
    HyQuery q = hy_query_create(test_globals.sack);
    hy_query_filter(q, HY_PKG_ENHANCES, HY_EQ, "flying");
    plist = hy_query_run(q);
    pkg = hy_packagelist_get(plist, 0);
    ck_assert_str_eq(hy_package_get_name(pkg), "walrus");
    hy_query_free(q);
    hy_packagelist_free(plist);
}
Beispiel #7
0
END_TEST

START_TEST(test_query_supplements)
{
    HyPackageList plist;
    HyPackage pkg;
    HyQuery q = hy_query_create(test_globals.sack);
    hy_query_filter(q, HY_PKG_SUPPLEMENTS, HY_EQ, "flying");
    plist = hy_query_run(q);
    pkg = hy_packagelist_get(plist, 0);
    ck_assert_str_eq(hy_package_get_name(pkg), "baby");
    hy_query_free(q);
    hy_packagelist_free(plist);
}
static gboolean
print_rpmdb_diff (GFile          *oldroot,
                  GFile          *newroot,
                  GCancellable   *cancellable,
                  GError        **error)
{
  gboolean ret = FALSE;
  _cleanup_hysack_ HySack old_sack = NULL;
  _cleanup_hypackagelist_ HyPackageList old_pkglist = NULL;
  _cleanup_hysack_ HySack new_sack = NULL;
  _cleanup_hypackagelist_ HyPackageList new_pkglist = NULL;
  guint i;
  HyPackage pkg;
  gboolean printed_header = FALSE;

  if (!rpmostree_get_pkglist_for_root (oldroot, &old_sack, &old_pkglist,
                                       cancellable, error))
    goto out;

  if (!rpmostree_get_pkglist_for_root (newroot, &new_sack, &new_pkglist,
                                       cancellable, error))
    goto out;
  
  printed_header = FALSE;
  FOR_PACKAGELIST(pkg, new_pkglist, i)
    {
      _cleanup_hyquery_ HyQuery query = NULL;
      _cleanup_hypackagelist_ HyPackageList pkglist = NULL;
      
      query = hy_query_create (old_sack);
      hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg));
      hy_query_filter (query, HY_PKG_EVR, HY_NEQ, hy_package_get_evr (pkg));
      hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
      pkglist = hy_query_run (query);
      if (hy_packagelist_count (pkglist) > 0)
        {
          gs_free char *nevra = hy_package_get_nevra (pkg);
          if (!printed_header)
            {
              g_print ("Changed:\n");
              printed_header = TRUE;
            }
          g_print ("  %s\n", nevra);
        }
    }
Beispiel #9
0
END_TEST

START_TEST(test_goal_install_selector_file)
{
    HySack sack = test_globals.sack;
    HySelector sltr = hy_selector_create(sack);
    HyGoal goal = hy_goal_create(sack);
    fail_if(hy_selector_set(sltr, HY_PKG_FILE, HY_EQ|HY_GLOB, "/*/answers"));
    fail_if(hy_goal_erase_selector(goal, sltr));
    fail_if(hy_goal_run(goal));
    assert_iueo(goal, 0, 0, 1, 0);
    HyPackageList plist = hy_goal_list_erasures(goal);
    HyPackage pkg = hy_packagelist_get(plist, 0);
    ck_assert_str_eq("fool", hy_package_get_name(pkg));
    hy_selector_free(sltr);
    hy_packagelist_free(plist);
    hy_goal_free(goal);
}
Beispiel #10
0
END_TEST

static void
assert_list_names(HyPackageList plist, ...)
{
    va_list names;
    char *name;
    int count = hy_packagelist_count(plist), i = 0;

    va_start(names, plist);
    while ((name = va_arg(names, char *)) != NULL) {
	if (i >= count)
	    fail("assert_list_names(): list too short");
	HyPackage pkg = hy_packagelist_get(plist, i++);
	ck_assert_str_eq(hy_package_get_name(pkg), name);
    }
    fail_unless(i == count, "assert_list_names(): too many items in the list");
    va_end(names);
}
 FOR_PACKAGELIST(pkg, new_pkglist, i)
   {
     _cleanup_hyquery_ HyQuery query = NULL;
     _cleanup_hypackagelist_ HyPackageList pkglist = NULL;
     
     query = hy_query_create (old_sack);
     hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg));
     hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
     pkglist = hy_query_run (query);
     if (hy_packagelist_count (pkglist) == 0)
       {
         gs_free char *nevra = hy_package_get_nevra (pkg);
         if (!printed_header)
           {
             g_print ("Added:\n");
             printed_header = TRUE;
           }
         g_print ("  %s\n", nevra);
       }
   }
Beispiel #12
0
END_TEST

START_TEST(test_filter_files)
{
    HyQuery q = hy_query_create(test_globals.sack);
    hy_query_filter(q, HY_PKG_FILE, HY_EQ, "/etc/takeyouaway");
    HyPackageList plist = hy_query_run(q);
    fail_unless(hy_packagelist_count(plist) == 1);
    HyPackage pkg = hy_packagelist_get(plist, 0);
    fail_if(strcmp(hy_package_get_name(pkg), "tour"));
    hy_packagelist_free(plist);
    hy_query_free(q);

    q = hy_query_create(test_globals.sack);
    hy_query_filter(q, HY_PKG_FILE, HY_GLOB, "/usr/*");
    plist = hy_query_run(q);
    fail_unless(hy_packagelist_count(plist) == 2);
    hy_packagelist_free(plist);
    hy_query_free(q);
}
Beispiel #13
0
HyPackageDelta
hy_package_get_delta_from_evr(HyPackage pkg, const char *from_evr)
{
    Pool *pool = package_pool(pkg);
    Solvable *s = get_solvable(pkg);
    HyPackageDelta delta = NULL;
    Dataiterator di;
    Id checksum_type;
    const unsigned char *checksum;
    const char *name = hy_package_get_name(pkg);

    dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, name,
		      SEARCH_STRING);
    dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
    while (dataiterator_step(&di)) {
	dataiterator_setpos_parent(&di);
	if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
	    pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
	    continue;
	const char * base_evr = pool_id2str(pool, pool_lookup_id(pool, SOLVID_POS,
								 DELTA_BASE_EVR));
	if (strcmp(base_evr, from_evr))
	    continue;

	// we have the right delta info, set up HyPackageDelta and break out:
	delta = delta_create();
	delta->location = solv_strdup(pool_lookup_deltalocation(pool, SOLVID_POS, 0));
	delta->baseurl = solv_strdup(pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_BASE));
	delta->downloadsize = pool_lookup_num(pool, SOLVID_POS, DELTA_DOWNLOADSIZE, 0);
	checksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &checksum_type);
	if (checksum) {
	    delta->checksum_type = checksumt_l2h(checksum_type);
	    delta->checksum = solv_memdup((void*)checksum, checksum_type2length(delta->checksum_type));
	}

	break;
    }
    dataiterator_free(&di);

    return delta;
}
Beispiel #14
0
uint32_t
TDNFTransAddErasePkg(
    PTDNFRPMTS pTS,
    HyPackage hPkg
    )
{
    uint32_t dwError = 0;
    Header pRpmHeader = NULL;
    rpmdbMatchIterator pIterator = NULL;
    const char* pszName = NULL;
    unsigned int nOffset = 0;

    if(!pTS || !hPkg)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pszName = hy_package_get_name(hPkg);

    pIterator = rpmtsInitIterator(pTS->pTS, (rpmTag)RPMDBI_LABEL, pszName, 0);
    while ((pRpmHeader = rpmdbNextIterator(pIterator)) != NULL)
    {
        nOffset = rpmdbGetIteratorOffset(pIterator);
        if(nOffset)
        {
            dwError = rpmtsAddEraseElement(pTS->pTS, pRpmHeader, nOffset);
            BAIL_ON_TDNF_ERROR(dwError);
        }
    }

cleanup:
    if(pIterator)
    {
        rpmdbFreeIterator(pIterator);
    }
    return dwError;

error:
    goto cleanup;
}
Beispiel #15
0
/**
 * rpm_ostree_db_diff:
 * @repo: An OSTree repository
 * @orig_ref: Original ref (branch or commit)
 * @new_ref: New ref (branch or commit)
 * @out_removed: (out) (transfer container) (element-type RpmOstreePackage): Return location for removed packages
 * @out_added: (out) (transfer container) (element-type RpmOstreePackage): Return location for added packages
 * @out_modified_old: (out) (transfer container) (element-type RpmOstreePackage): Return location for modified old packages
 * @out_modified_new: (out) (transfer container) (element-type RpmOstreePackage): Return location for modified new packages
 *
 * Compute the RPM package delta between two commits.  Currently you
 * must use %NULL for the @query parameter; in a future version this
 * function may allow looking at a subset of the packages.
 *
 * The @out_modified_old and @out_modified_new arrays will always be
 * the same length, and indicies will refer to the same base package
 * name.  It is possible in RPM databases to have multiple packages
 * installed with the same name; in this case, the behavior will
 * depend on whether the package set is transitioning from 1 -> N or N
 * -> 1.  In the former case, an arbitrary single instance of one of
 * the new packages will be in @out_modified_new.  If the latter, then
 * multiple entries with the same name will be returned in
 * the array @out_modified_old, with each having a reference to the
 * single corresponding new package.
 */
gboolean
rpm_ostree_db_diff (OstreeRepo               *repo,
                    const char               *orig_ref,
                    const char               *new_ref,
                    GPtrArray               **out_removed,
                    GPtrArray               **out_added,
                    GPtrArray               **out_modified_old,
                    GPtrArray               **out_modified_new,
                    GCancellable             *cancellable,
                    GError                  **error)
{
  gboolean ret = FALSE;
  g_autoptr(RpmOstreeRefSack) orig_sack = NULL;
  g_autoptr(RpmOstreeRefSack) new_sack = NULL;
  _cleanup_hypackagelist_ HyPackageList orig_pkglist = NULL;
  _cleanup_hypackagelist_ HyPackageList new_pkglist = NULL;
  g_autoptr(GPtrArray) ret_removed = g_ptr_array_new_with_free_func (g_object_unref);
  g_autoptr(GPtrArray) ret_added = g_ptr_array_new_with_free_func (g_object_unref);
  g_autoptr(GPtrArray) ret_modified_old = g_ptr_array_new_with_free_func (g_object_unref);
  g_autoptr(GPtrArray) ret_modified_new = g_ptr_array_new_with_free_func (g_object_unref);
  guint i;
  HyPackage pkg;

  g_return_val_if_fail (out_removed != NULL && out_added != NULL &&
                        out_modified_old != NULL && out_modified_new != NULL, FALSE);

  orig_sack = _rpm_ostree_get_refsack_for_commit (repo, orig_ref, cancellable, error);
  if (!orig_sack)
    goto out;

  { _cleanup_hyquery_ HyQuery query = hy_query_create (orig_sack->sack);
    hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
    orig_pkglist = hy_query_run (query);
  }

  new_sack = _rpm_ostree_get_refsack_for_commit (repo, new_ref, cancellable, error);
  if (!new_sack)
    goto out;

  { _cleanup_hyquery_ HyQuery query = hy_query_create (new_sack->sack);
    hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
    new_pkglist = hy_query_run (query);
  }

  FOR_PACKAGELIST(pkg, new_pkglist, i)
    {
      _cleanup_hyquery_ HyQuery query = NULL;
      _cleanup_hypackagelist_ HyPackageList pkglist = NULL;
      guint count;
      HyPackage oldpkg;
      
      query = hy_query_create (orig_sack->sack);
      hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg));
      hy_query_filter (query, HY_PKG_EVR, HY_NEQ, hy_package_get_evr (pkg));
      hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
      pkglist = hy_query_run (query);

      count = hy_packagelist_count (pkglist);
      if (count > 0)
        {
          /* See comment above about transitions from N -> 1 */
          oldpkg = hy_packagelist_get (pkglist, 0);
          
          g_ptr_array_add (ret_modified_old, _rpm_ostree_package_new (orig_sack, oldpkg));
          g_ptr_array_add (ret_modified_new, _rpm_ostree_package_new (new_sack, pkg));
        }
    }
Beispiel #16
0
uint32_t
TDNFTransAddDowngradePkgs(
    PTDNFRPMTS pTS,
    PTDNF pTdnf
    )
{
    uint32_t dwError = 0;
    int i = 0;
    HyPackage hPkg = NULL;
    HyPackageList hPkgList = NULL;
    HyPackage hInstalledPkg = NULL;

    hPkgList = hy_goal_list_downgrades(pTdnf->hGoal);
    if(!hPkgList)
    {
        dwError = ERROR_TDNF_NO_DATA;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    for(i = 0; (hPkg = hy_packagelist_get(hPkgList, i)) != NULL; ++i)
    {
        dwError = TDNFTransAddInstallPkg(pTS, pTdnf, hPkg, 0);
        BAIL_ON_TDNF_ERROR(dwError);

        //Downgrade is a removal of existing and installing old.
        const char* pszName = NULL;
        pszName = hy_package_get_name(hPkg);
        if(IsNullOrEmptyString(pszName))
        {
            dwError = hy_get_errno();
            if(dwError == 0)
            {
                dwError = HY_E_FAILED;
            }
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
        }
        dwError = TDNFFindInstalledPkgByName(pTdnf->hSack, pszName, &hInstalledPkg);
        BAIL_ON_TDNF_ERROR(dwError);

        dwError = TDNFTransAddErasePkg(pTS, hInstalledPkg);
        BAIL_ON_TDNF_ERROR(dwError);

        hy_package_free(hInstalledPkg);
        hInstalledPkg = NULL;
    }

cleanup:
    if(hInstalledPkg)
    {
        hy_package_free(hInstalledPkg);
    }
    if(hPkgList)
    {
        hy_packagelist_free(hPkgList);
    }
    return dwError;

error:
    if(dwError == ERROR_TDNF_NO_DATA)
    {
        dwError = 0;
    }
    goto cleanup;
}