Example #1
0
END_TEST

START_TEST(test_sack_create)
{
    g_autoptr(HifSack) sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    fail_if(sack == NULL, NULL);
    fail_if(hif_sack_get_pool(sack) == NULL, NULL);
}
Example #2
0
END_TEST

START_TEST(test_filelist_from_cache)
{
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    setup_yum_sack(sack, YUM_REPO_NAME);

    HyRepo repo = hrepo_by_name(sack, YUM_REPO_NAME);
    fail_unless(repo->state_filelists == _HY_LOADED_CACHE);
    check_filelist(hif_sack_get_pool(sack));
    g_object_unref(sack);
}
Example #3
0
END_TEST

START_TEST(test_sack_create)
{
    g_autoptr(GError) error = NULL;
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    fail_if(sack == NULL, NULL);
    fail_if(hif_sack_get_pool(sack) == NULL, NULL);
    g_object_unref(sack);

    sack = hif_sack_new ();
    fail_if(hif_sack_set_arch(sack, "", &error));
    fail_if(error == NULL);
}
Example #4
0
END_TEST

START_TEST(test_load_repo_err)
{
    g_autoptr(GError) error = NULL;
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, &error));
    g_assert(sack != NULL);
    HyRepo repo = hy_repo_create("crabalocker");
    g_assert(repo != NULL);
    hy_repo_set_string(repo, HY_REPO_MD_FN, "/non/existing");
    fail_unless(!hif_sack_load_repo(sack, repo, 0, &error));
    fail_unless(g_error_matches (error, HIF_ERROR, HIF_ERROR_FILE_INVALID));
    hy_repo_free(repo);
    g_object_unref(sack);
}
Example #5
0
END_TEST

START_TEST(test_list_arches)
{
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    hif_sack_set_arch(sack, TEST_FIXED_ARCH, NULL);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    const char ** arches = hif_sack_list_arches(sack);

    /* noarch, x86_64, athlon, i686, i586, i486, i386 */
    fail_unless(g_strv_length((gchar**)arches), 7);
    ck_assert_str_eq(arches[3], "i686");

    g_free(arches);
    g_object_unref(sack);
}
Example #6
0
END_TEST

START_TEST(test_give_cache_fn)
{
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));

    char *path = hif_sack_give_cache_fn(sack, "rain", NULL);
    fail_if(strstr(path, "rain.solv") == NULL);
    g_free(path);

    path = hif_sack_give_cache_fn(sack, "rain", HY_EXT_FILENAMES);
    fail_if(strstr(path, "rain-filenames.solvx") == NULL);
    g_free(path);
    g_object_unref(sack);
}
Example #7
0
END_TEST

START_TEST(test_repo_written)
{
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    char *filename = hif_sack_give_cache_fn(sack, "test_sack_written", NULL);

    fail_unless(access(filename, R_OK|W_OK));
    setup_yum_sack(sack, "test_sack_written");

    HyRepo repo = hrepo_by_name(sack, "test_sack_written");
    fail_if(repo == NULL);
    fail_unless(repo->state_main == _HY_WRITTEN);
    fail_unless(repo->state_filelists == _HY_WRITTEN);
    fail_unless(repo->state_presto == _HY_WRITTEN);
    fail_if(access(filename, R_OK|W_OK));

    g_free(filename);
    g_object_unref(sack);
}
Example #8
0
int main(int argc, const char **argv)
{
    HifSack *sack = hif_sack_new ();
    HyRepo repo;
    char *md_repo;
    char *md_primary_xml;
    char *md_filelists;
    char *md_repo_updates;
    char *md_primary_updates_xml;
    char *md_filelists_updates;
    int ret;
    g_autoptr(GError) error = NULL;

    if (!hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL))
        return 1;

    if (read_repopaths(&md_repo, &md_primary_xml, &md_filelists, &md_repo_updates,
                       &md_primary_updates_xml, &md_filelists_updates)) {
        fprintf(stderr,
                "This is hawkey testing hack, it needs a readable %s file "
                "containing the following paths on separate lines:\n"
                "<main repomd.xml path>\n"
                "<main primary.xml.gz path>\n"
                "<main filelist.xml.gz path>\n"
                "<updates repomd.xml path>\n"
                "<updates primary.xml.gz path>\n"
                "<updates filelists.xml.gz path>\n", CFG_FILE);
        return 1;
    }
    int load_flags = HIF_SACK_LOAD_FLAG_BUILD_CACHE;
    /* rpmdb */
    repo = hy_repo_create(HY_SYSTEM_REPO_NAME);
    hif_sack_load_system_repo(sack, NULL, load_flags, &error);
    hy_repo_free(repo);

    if (need_filelists(argc, argv))
        load_flags |= HIF_SACK_LOAD_FLAG_USE_FILELISTS;
    /* Fedora repo */
    repo = config_repo("Fedora", md_repo, md_primary_xml, md_filelists);
    ret = hif_sack_load_repo(sack, repo, load_flags, &error);
    assert(ret == 0);
    (void)ret;
    hy_repo_free(repo);
    /* Fedora updates repo */
    repo = config_repo("updates", md_repo_updates, md_primary_updates_xml,
                       md_filelists_updates);
    ret = hif_sack_load_repo(sack, repo, load_flags, &error);
    assert(ret == 0);
    (void)ret;
    hy_repo_free(repo);
    free(md_repo);
    free(md_primary_xml);
    free(md_filelists);
    free(md_repo_updates);
    free(md_primary_updates_xml);
    free(md_filelists_updates);

    hif_sack_set_installonly(sack, installonly);
    hif_sack_set_installonly_limit(sack, 3);

    if (argc == 2 && !strcmp(argv[1], "-o")) {
        obsoletes(sack);
    } else if (argc == 2) {
        search_and_print(sack, argv[1]);
    } else if (argc == 3 && !strcmp(argv[1], "-f")) {
        search_filter_files(sack, argv[2]);
    } else if (argc == 3 && !strcmp(argv[1], "-r")) {
        search_filter_repos(sack, argv[2]);
    } else if (argc == 3 && !strcmp(argv[1], "-u")) {
        updatables_query_name(sack, argv[2]);
    } else if (argc == 3 && !strcmp(argv[1], "-ul")) {
        update_local(sack, argv[2]);
    } else if (argc == 3 && !strcmp(argv[1], "-ur")) {
        update_remote(sack, argv[2]);
    } else if (argc == 3 && !strcmp(argv[1], "-e")) {
        erase(sack, argv[2]);
    } else if (argc == 3) {
        search_anded(sack, argv[1], argv[2]);
    } else if (argc == 4 && !strcmp(argv[1], "-p")) {
        search_provides(sack, argv[2], argv[3]);
    }

    g_object_unref(sack);

    return 0;
}
Example #9
0
static int
sack_init(_SackObject *self, PyObject *args, PyObject *kwds)
{
    g_autoptr(GError) error = NULL;
    PyObject *custom_class = NULL;
    PyObject *custom_val = NULL;
    const char *cachedir = NULL;
    const char *arch = NULL;
    const char *rootdir = NULL;
    PyObject *tmp_py_str = NULL;
    PyObject *tmp2_py_str = NULL;
    PyObject *cachedir_py = NULL;
    int make_cache_dir = 0;
    const char *kwlist[] = {"cachedir", "arch", "rootdir", "pkgcls",
                      "pkginitval", "make_cache_dir", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OssOOi", (char**) kwlist,
                                     &cachedir_py, &arch, &rootdir,
                                     &custom_class, &custom_val,
                                     &make_cache_dir))
        return -1;
    if (cachedir_py != NULL)
        cachedir = pycomp_get_string(cachedir_py, &tmp_py_str);
    int flags = 0;
    if (make_cache_dir)
        flags |= HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR;
    self->sack = hif_sack_new();
    Py_XDECREF(tmp_py_str);
    Py_XDECREF(tmp2_py_str);
    if (!hif_sack_set_arch(self->sack, arch, &error)) {
        PyErr_SetString(HyExc_Arch, "Unrecognized arch for the sack.");
        return -1;
    }
    hif_sack_set_rootdir(self->sack, rootdir);
    hif_sack_set_cachedir(self->sack, cachedir);
    if (!hif_sack_setup(self->sack, flags, &error)) {
        switch (error->code) {
        case HIF_ERROR_FILE_INVALID:
            PyErr_SetString(PyExc_IOError,
                            "Failed creating working files for the Sack.");
            break;
        case HIF_ERROR_INVALID_ARCHITECTURE:
            PyErr_SetString(HyExc_Arch, "Unrecognized arch for the sack.");
            break;
        default:
            assert(0);
        }
        return -1;
    }

    if (custom_class && custom_class != Py_None) {
        if (!PyType_Check(custom_class)) {
            PyErr_SetString(PyExc_TypeError, "Expected a class object.");
            return -1;
        }
        Py_INCREF(custom_class);
        self->custom_package_class = custom_class;
    }
    if (custom_val && custom_val != Py_None) {
        Py_INCREF(custom_val);
        self->custom_package_val = custom_val;

    }
    return 0;
}