1 /*
2 * Copyright (C) 2012-2013 Red Hat, Inc.
3 *
4 * Licensed under the GNU Lesser General Public License Version 2.1
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <wordexp.h>
22
23 extern "C" {
24 #include <solv/pool.h>
25 #include <solv/repo.h>
26 #include <solv/testcase.h>
27 }
28
29 #include "libdnf/hy-repo.h"
30 #include "libdnf/hy-repo-private.hpp"
31 #include "libdnf/repo/Repo-private.hpp"
32 #include "testshared.h"
33
34 HyRepo
glob_for_repofiles(Pool * pool,const char * repo_name,const char * path)35 glob_for_repofiles(Pool *pool, const char *repo_name, const char *path)
36 {
37 HyRepo repo = hy_repo_create(repo_name);
38 const char *tmpl;
39 wordexp_t word_vector;
40
41 tmpl = pool_tmpjoin(pool, path, "/repomd.xml", NULL);
42 if (wordexp(tmpl, &word_vector, 0) || word_vector.we_wordc < 1)
43 goto fail;
44 hy_repo_set_string(repo, HY_REPO_MD_FN, word_vector.we_wordv[0]);
45
46 tmpl = pool_tmpjoin(pool, path, "/*primary.xml.gz", NULL);
47 if (wordexp(tmpl, &word_vector, WRDE_REUSE) || word_vector.we_wordc < 1)
48 goto fail;
49 hy_repo_set_string(repo, HY_REPO_PRIMARY_FN, word_vector.we_wordv[0]);
50
51 tmpl = pool_tmpjoin(pool, path, "/*filelists.xml.gz", NULL);
52 if (wordexp(tmpl, &word_vector, WRDE_REUSE) || word_vector.we_wordc < 1)
53 goto fail;
54 hy_repo_set_string(repo, HY_REPO_FILELISTS_FN, word_vector.we_wordv[0]);
55
56 tmpl = pool_tmpjoin(pool, path, "/*prestodelta.xml.gz", NULL);
57 if (wordexp(tmpl, &word_vector, WRDE_REUSE) || word_vector.we_wordc < 1)
58 goto fail;
59 hy_repo_set_string(repo, HY_REPO_PRESTO_FN, word_vector.we_wordv[0]);
60
61 tmpl = pool_tmpjoin(pool, path, "/*updateinfo.xml.gz", NULL);
62 if (wordexp(tmpl, &word_vector, WRDE_REUSE) || word_vector.we_wordc < 1)
63 goto fail;
64 hy_repo_set_string(repo, HY_REPO_UPDATEINFO_FN, word_vector.we_wordv[0]);
65
66 wordfree(&word_vector);
67 return repo;
68
69 fail:
70 wordfree(&word_vector);
71 hy_repo_free(repo);
72 return NULL;
73 }
74
75 int
load_repo(Pool * pool,const char * name,const char * path,int installed)76 load_repo(Pool *pool, const char *name, const char *path, int installed)
77 {
78 HyRepo hrepo = hy_repo_create(name);
79 Repo *r = repo_create(pool, name);
80 libdnf::repoGetImpl(hrepo)->attachLibsolvRepo(r);
81 hy_repo_free(hrepo);
82
83 FILE *fp = fopen(path, "r");
84
85 if (!fp)
86 return 1;
87 testcase_add_testtags(r, fp, 0);
88 if (installed)
89 pool_set_installed(pool, r);
90 fclose(fp);
91 return 0;
92 }
93