예제 #1
0
/**
 * dnf_package_check_filename:
 * @pkg: a #DnfPackage *instance.
 * @valid: Set to %TRUE if the package is valid.
 * @error: a #GError or %NULL..
 *
 * Checks the package is already downloaded and valid.
 *
 * Returns: %TRUE if the package was checked successfully
 *
 * Since: 0.1.0
 **/
gboolean
dnf_package_check_filename(DnfPackage *pkg, gboolean *valid, GError **error)
{
    LrChecksumType checksum_type_lr;
    char *checksum_valid = NULL;
    const gchar *path;
    const unsigned char *checksum;
    gboolean ret = TRUE;
    int checksum_type_hy;
    int fd;

    /* check if the file does not exist */
    path = dnf_package_get_filename(pkg);
    g_debug("checking if %s already exists...", path);
    if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
        *valid = FALSE;
        goto out;
    }

    /* check the checksum */
    checksum = dnf_package_get_chksum(pkg, &checksum_type_hy);
    checksum_valid = hy_chksum_str(checksum, checksum_type_hy);
    checksum_type_lr = dnf_repo_checksum_hy_to_lr(checksum_type_hy);
    fd = g_open(path, O_RDONLY, 0);
    if (fd < 0) {
        ret = FALSE;
        g_set_error(error,
                 DNF_ERROR,
                 DNF_ERROR_INTERNAL_ERROR,
                 "Failed to open %s", path);
        goto out;
    }
    ret = lr_checksum_fd_cmp(checksum_type_lr,
                 fd,
                 checksum_valid,
                 TRUE, /* use xattr value */
                 valid,
                 error);
    if (!ret) {
        g_close(fd, NULL);
        goto out;
    }
    ret = g_close(fd, error);
    if (!ret)
        goto out;
out:
    g_free(checksum_valid);
    return ret;
}
예제 #2
0
파일: hth.c 프로젝트: Tojaj/hawkey
static void execute_print(HySack sack, HyQuery q, int show_obsoletes)
{
    HyPackageList plist;

    plist = hy_query_run(q);
    const int count = hy_packagelist_count(plist);
    for (int i = 0; i < count; ++i) {
	HyPackage pkg = hy_packagelist_get(plist, i);
	char *nvra = hy_package_get_nevra(pkg);
	const char *reponame = hy_package_get_reponame(pkg);

	printf("found package: %s [%s]\n", nvra, reponame);
	if (strcmp(reponame, HY_SYSTEM_REPO_NAME) == 0) {
	    int type;
	    const unsigned char * hdrid = hy_package_get_hdr_chksum(pkg, &type);
	    char *str = hy_chksum_str(hdrid, type);

	    printf("\tsha1 header id: %s\n", str);
	    hy_free(str);
	}
	if (show_obsoletes) {
	    HyReldepList obsoletes = hy_package_get_obsoletes(pkg);
	    HyQuery qobs = hy_query_create(sack);

	    hy_query_filter(qobs, HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME);
	    hy_query_filter_reldep_in(qobs, HY_PKG_PROVIDES, obsoletes);
	    HyPackageList olist = hy_query_run(qobs);
	    const int ocount = hy_packagelist_count(olist);
	    for (int j = 0; j < ocount; ++j) {
		HyPackage opkg = hy_packagelist_get(olist, j);
		char *onvra = hy_package_get_nevra(opkg);
		printf("obsoleting: %s\n", onvra);
		hy_free(onvra);
	    }
	    hy_packagelist_free(olist);
	    hy_query_free(qobs);
	    hy_reldeplist_free(obsoletes);
	}
	hy_free(nvra);
    }
    hy_packagelist_free(plist);
}
예제 #3
0
/**
 * dnf_package_get_pkgid:
 * @pkg: a #DnfPackage *instance.
 *
 * Gets the pkgid, which is the SHA hash of the package header.
 *
 * Returns: pkgid string, or NULL
 *
 * Since: 0.1.0
 **/
const gchar *
dnf_package_get_pkgid(DnfPackage *pkg)
{
    const unsigned char *checksum;
    DnfPackagePrivate *priv;
    int checksum_type;

    priv = dnf_package_get_priv(pkg);
    if (priv == NULL)
        return NULL;
    if (priv->checksum_str != NULL)
        goto out;

    /* calculate and cache */
    checksum = dnf_package_get_hdr_chksum(pkg, &checksum_type);
    if (checksum == NULL)
        goto out;
    priv->checksum_str = hy_chksum_str(checksum, checksum_type);
out:
    return priv->checksum_str;
}
예제 #4
0
static void execute_print(HifSack *sack, HyQuery q, int show_obsoletes)
{
    GPtrArray *plist;

    plist = hy_query_run(q);
    const int count = plist->len;
    for (int i = 0; i < count; ++i) {
        HifPackage *pkg = g_ptr_array_index(plist, i);
        const char *nvra = hif_package_get_nevra(pkg);
        const char *reponame = hif_package_get_reponame(pkg);

        printf("found package: %s [%s]\n", nvra, reponame);
        if (strcmp(reponame, HY_SYSTEM_REPO_NAME) == 0) {
            int type;
            const unsigned char * hdrid = hif_package_get_hdr_chksum(pkg, &type);
            char *str = hy_chksum_str(hdrid, type);

            printf("\tsha1 header id: %s\n", str);
            g_free(str);
        }
        if (show_obsoletes) {
            HifReldepList *obsoletes = hif_package_get_obsoletes(pkg);
            HyQuery qobs = hy_query_create(sack);

            hy_query_filter(qobs, HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME);
            hy_query_filter_reldep_in(qobs, HY_PKG_PROVIDES, obsoletes);
            GPtrArray *olist = hy_query_run(qobs);
            const int ocount = olist->len;
            for (int j = 0; j < ocount; ++j) {
                HifPackage *opkg = g_ptr_array_index(olist, j);
                const char *onvra = hif_package_get_nevra(opkg);
                printf("obsoleting: %s\n", onvra);
            }
            g_ptr_array_unref(olist);
            hy_query_free(qobs);
            g_object_unref(obsoletes);
        }
    }
    g_ptr_array_unref(plist);
}