Example #1
0
/**
 * hif_db_get_dir_for_package:
 **/
static gchar *
hif_db_get_dir_for_package(HifDb *db, HifPackage *package)
{
    const gchar *pkgid;
    HifDbPrivate *priv = GET_PRIVATE(db);
    const gchar *instroot;
#ifdef BUILDOPT_USE_DNF_YUMDB
    static const gchar *yumdb_dir = "/var/lib/dnf/yumdb";
#else
    static const gchar *yumdb_dir = "/var/lib/yum/yumdb";
#endif

    pkgid = hif_package_get_pkgid(package);
    if (pkgid == NULL)
        return NULL;

    instroot = hif_context_get_install_root(priv->context);
    if (g_strcmp0(instroot, "/") == 0)
        instroot = "";

    return g_strdup_printf("%s%s/%c/%s-%s-%s-%s-%s",
                          instroot,
                          yumdb_dir,
                          hif_package_get_name(package)[0],
                          pkgid,
                          hif_package_get_name(package),
                          hif_package_get_version(package),
                          hif_package_get_release(package),
                          hif_package_get_arch(package));
}
Example #2
0
/**
 * hif_package_get_package_id:
 * @pkg: a #HifPackage *instance.
 *
 * Gets the package-id as used by PackageKit.
 *
 * Returns: the package_id string, or %NULL, e.g. "hal;2:0.3.4;i386;installed:fedora"
 *
 * Since: 0.1.0
 **/
const gchar *
hif_package_get_package_id(HifPackage *pkg)
{
    HifPackagePrivate *priv;
    const gchar *reponame;
    g_autofree gchar *reponame_tmp = NULL;

    priv = hif_package_get_priv(pkg);
    if (priv == NULL)
        return NULL;
    if (priv->package_id != NULL)
        goto out;

    /* calculate and cache */
    reponame = hif_package_get_reponame(pkg);
    if (g_strcmp0(reponame, HY_SYSTEM_REPO_NAME) == 0) {
        /* origin data to munge into the package_id data field */
        if (priv->origin != NULL) {
            reponame_tmp = g_strdup_printf("installed:%s", priv->origin);
            reponame = reponame_tmp;
        } else {
            reponame = "installed";
        }
    } else if (g_strcmp0(reponame, HY_CMDLINE_REPO_NAME) == 0) {
        reponame = "local";
    }
    priv->package_id = hif_package_id_build(hif_package_get_name(pkg),
                        hif_package_get_evr(pkg),
                        hif_package_get_arch(pkg),
                        reponame);
out:
    return priv->package_id;
}