#include <assert.h>
#include <dirent.h>
#include <expat.h>
+#include <errno.h>
#include "pool.h"
#include "repo.h"
#include "util.h"
#define DISABLE_SPLIT
#include "tools_util.h"
-#include "repo_content.h"
+#include "repo_zyppdb.h"
-//#define DUMPOUT 0
-
enum state {
- STATE_START, // 0
- STATE_PRODUCT, // 1
- STATE_NAME, // 2
- STATE_VERSION, // 3
- STATE_ARCH, // 4
- STATE_SUMMARY, // 5
- STATE_VENDOR, // 6
- STATE_INSTALLTIME, // 7
- NUMSTATES // 0
+ STATE_START,
+ STATE_PRODUCT,
+ STATE_NAME,
+ STATE_VERSION,
+ STATE_ARCH,
+ STATE_SUMMARY,
+ STATE_VENDOR,
+ STATE_INSTALLTIME,
+ NUMSTATES
};
struct stateswitch {
* find value for xml attribute
* I: txt, name of attribute
* I: atts, list of key/value attributes
- * I: dup, strdup it
* O: pointer to value of matching key, or NULL
*
*/
static inline const char *
-find_attr(const char *txt, const char **atts, int dup)
+find_attr(const char *txt, const char **atts)
{
for (; *atts; atts += 2)
{
if (!strcmp(*atts, txt))
- return dup ? solv_strdup(atts[1]) : atts[1];
+ return atts[1];
}
return 0;
}
case STATE_PRODUCT:
{
/* parse 'type' */
- const char *type = find_attr("type", atts, 0);
+ const char *type = find_attr("type", atts);
s = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
- repodata_extend(pd->data, s - pool->solvables);
pd->handle = s - pool->solvables;
if (type)
repodata_set_str(pd->data, pd->handle, PRODUCT_TYPE, type);
break;
case STATE_VERSION:
{
- const char *ver = find_attr("ver", atts, 0);
- const char *rel = find_attr("rel", atts, 0);
- /* const char *epoch = find_attr("epoch", atts, 1); ignored */
+ const char *ver = find_attr("ver", atts);
+ const char *rel = find_attr("rel", atts);
+ /* const char *epoch = find_attr("epoch", atts); ignored */
s->evr = makeevr(pd->pool, join2(&pd->jd, ver, "-", rel));
}
break;
/* <summary lang="xy">... */
case STATE_SUMMARY:
- pd->tmplang = find_attr("lang", atts, 1);
+ pd->tmplang = join_dup(&pd->jd, find_attr("lang", atts));
break;
default:
break;
break;
case STATE_SUMMARY:
repodata_set_str(pd->data, pd->handle, pool_id2langid(pd->pool, SOLVABLE_SUMMARY, pd->tmplang, 1), pd->content);
- pd->tmplang = solv_free((void *)pd->tmplang);
break;
case STATE_VENDOR:
s->vendor = pool_str2id(pd->pool, pd->content, 1);
if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
{
pool_debug(pd->pool, SOLV_ERROR, "repo_zyppdb: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
+ if (pd->solvable)
+ {
+ repo_free_solvable(pd->repo, pd->solvable - pd->pool->solvables, 1);
+ pd->solvable = 0;
+ }
return;
}
if (l == 0)
* parse each one as a product
*/
-void
+int
repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags)
{
int i;
DIR *dir;
FILE *fp;
Repodata *data;
-
+
data = repo_add_repodata(repo, flags);
memset(&pd, 0, sizeof(pd));
pd.repo = repo;
pd.sbtab[sw->to] = sw->from;
}
+ if (flags & REPO_USE_ROOTDIR)
+ dirpath = pool_prepend_rootdir(repo->pool, dirpath);
dir = opendir(dirpath);
if (dir)
{
fullpath = join2(&pd.jd, dirpath, "/", entry->d_name);
if ((fp = fopen(fullpath, "r")) == 0)
{
- perror(fullpath);
+ pool_error(repo->pool, 0, "%s: %s", fullpath, strerror(errno));
continue;
}
add_zyppdb_product(&pd, fp);
}
closedir(dir);
- solv_free((void *)pd.tmplang);
free(pd.content);
join_freemem(&pd.jd);
+ if (flags & REPO_USE_ROOTDIR)
+ solv_free((char *)dirpath);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
+ return 0;
}
/* EOF */