Exemplo n.º 1
0
END_TEST

START_TEST(test_get_files_cmdline)
{
    HySack sack = test_globals.sack;

    HyPackage pkg = by_name(sack, "tour");
    HyStringArray files;

    files = hy_package_get_files(pkg);
    fail_unless(hy_stringarray_length(files) == 6);
    hy_stringarray_free(files);
    hy_package_free(pkg);
}
Exemplo n.º 2
0
END_TEST

START_TEST(test_get_files)
{
    HySack sack = test_globals.sack;

    HyPackage pkg = by_name(sack, "tour");
    HyStringArray files = hy_package_get_files(pkg);
    char *f;
    int i;

    FOR_STRINGARRAY(f, files, i)
    ;
    fail_unless(i == 6);
    hy_stringarray_free(files);
    hy_package_free(pkg);
}
Exemplo n.º 3
0
static gboolean
handle_remove_files_from_package (GFile         *yumroot,
                                  RpmOstreeRefSack *refsack,
                                  JsonArray     *removespec,
                                  GCancellable  *cancellable,
                                  GError       **error)
{
    gboolean ret = FALSE;
    const char *pkg = json_array_get_string_element (removespec, 0);
    guint i, j, npackages;
    guint len = json_array_get_length (removespec);
    HyPackage hypkg;
    _cleanup_hyquery_ HyQuery query = NULL;
    _cleanup_hypackagelist_ HyPackageList pkglist = NULL;

    query = hy_query_create (refsack->sack);
    hy_query_filter (query, HY_PKG_NAME, HY_EQ, pkg);
    pkglist = hy_query_run (query);
    npackages = hy_packagelist_count (pkglist);
    if (npackages == 0)
    {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "Unable to find package '%s' specified in remove-files-from", pkg);
        goto out;
    }

    for (j = 0; j < npackages; j++)
    {
        _cleanup_hystringarray_ HyStringArray pkg_files = NULL;

        hypkg = hy_packagelist_get (pkglist, 0);
        pkg_files = hy_package_get_files (hypkg);

        for (i = 1; i < len; i++)
        {
            const char *remove_regex_pattern = json_array_get_string_element (removespec, i);
            GRegex *regex;
            char **strviter;

            regex = g_regex_new (remove_regex_pattern, G_REGEX_JAVASCRIPT_COMPAT, 0, error);

            if (!regex)
                goto out;

            for (strviter = pkg_files; strviter && strviter[0]; strviter++)
            {
                const char *file = *strviter;

                if (g_regex_match (regex, file, 0, NULL))
                {
                    gs_unref_object GFile *child = NULL;

                    if (file[0] == '/')
                        file++;

                    child = g_file_resolve_relative_path (yumroot, file);
                    g_print ("Deleting: %s\n", file);
                    if (!gs_shutil_rm_rf (child, cancellable, error))
                        goto out;
                }
            }
        }
    }

    ret = TRUE;
out:
    return ret;
}