#include "pool.h"
#include "repo.h"
#include "chksum.h"
-#include "repo_updateinfoxml.h"
-
-#define DISABLE_SPLIT
-#include "tools_util.h"
-
-/* #define DUMPOUT 1 */
+#include "repo_deltainfoxml.h"
/*
* <deltainfo>
/* Cumulated info about the current deltarpm or patchrpm */
struct deltarpm {
- Id locdir;
- Id locname;
- Id locevr;
- Id locsuffix;
- unsigned buildtime;
- unsigned downloadsize, archivesize;
+ char *location;
+ char *locbase;
+ unsigned int buildtime;
+ unsigned long long downloadsize;
char *filechecksum;
int filechecksumtype;
/* Baseversion. deltarpm only has one. */
};
struct parsedata {
+ int ret;
int depth;
enum state state;
int statedepth;
Pool *pool;
Repo *repo;
Repodata *data;
-
+
struct stateswitch *swtab[NUMSTATES];
enum state sbtab[NUMSTATES];
- char *tempstr;
- int ltemp;
- int atemp;
struct deltarpm delta;
Id newpkgevr;
Id newpkgname;
else if (!strcmp(*atts, "oldrelease"))
r = atts[1];
}
- if (e && !strcmp(e, "0"))
+ if (e && (!*e || !strcmp(e, "0")))
e = 0;
if (v && !e)
{
return pool_str2id(pool, pd->content, 1);
}
-static void parse_delta_location( struct parsedata *pd,
- const char* str )
-{
- Pool *pool = pd->pool;
- if (str)
- {
- /* Separate the filename into its different parts.
- rpm/x86_64/alsa-1.0.14-31_31.2.x86_64.delta.rpm
- --> dir = rpm/x86_64
- name = alsa
- evr = 1.0.14-31_31.2
- suffix = x86_64.delta.rpm. */
- char *real_str = solv_strdup(str);
- char *s = real_str;
- char *s1, *s2;
- s1 = strrchr (s, '/');
- if (s1)
- {
- pd->delta.locdir = pool_strn2id(pool, s, s1 - s, 1);
- s = s1 + 1;
- }
- /* Guess suffix. */
- s1 = strrchr (s, '.');
- if (s1)
- {
- for (s2 = s1 - 1; s2 > s; s2--)
- if (*s2 == '.')
- break;
- if (!strcmp (s2, ".delta.rpm") || !strcmp (s2, ".patch.rpm"))
- {
- s1 = s2;
- /* We accept one more item as suffix. */
- for (s2 = s1 - 1; s2 > s; s2--)
- if (*s2 == '.')
- break;
- s1 = s2;
- }
- if (*s1 == '.')
- *s1++ = 0;
- pd->delta.locsuffix = pool_str2id(pool, s1, 1);
- }
- /* Last '-'. */
- s1 = strrchr (s, '-');
- if (s1)
- {
- /* Second to last '-'. */
- for (s2 = s1 - 1; s2 > s; s2--)
- if (*s2 == '-')
- break;
- }
- else
- s2 = 0;
- if (s2 > s && *s2 == '-')
- {
- *s2++ = 0;
- pd->delta.locevr = pool_str2id(pool, s2, 1);
- }
- pd->delta.locname = pool_str2id(pool, s, 1);
- free(real_str);
- }
-}
-
static void XMLCALL
startElement(void *userData, const char *name, const char **atts)
{
{
#if 0
fprintf(stderr, "into unknown: [%d]%s (from: %d)\n", sw->to, name, sw->from);
- exit( 1 );
#endif
return;
}
case STATE_DELTA:
memset(&pd->delta, 0, sizeof(pd->delta));
- *pd->tempstr = 0;
- pd->ltemp = 0;
pd->delta.bevr = solv_extend(pd->delta.bevr, pd->delta.nbevr, 1, sizeof(Id), 7);
pd->delta.bevr[pd->delta.nbevr++] = makeevr_atts(pool, pd, atts);
break;
case STATE_FILENAME:
+ if ((str = find_attr("xml:base", atts)))
+ pd->delta.locbase = solv_strdup(str);
break;
case STATE_LOCATION:
- parse_delta_location(pd, find_attr("href", atts));
+ pd->delta.location = solv_strdup(find_attr("href", atts));
+ if ((str = find_attr("xml:base", atts)))
+ pd->delta.locbase = solv_strdup(str);
break;
case STATE_SIZE:
break;
if (!pd->delta.filechecksumtype)
pool_debug(pool, SOLV_ERROR, "unknown checksum type: '%s'\n", str);
}
+ break;
case STATE_SEQUENCE:
break;
default:
/* read all data for a deltarpm. commit into attributes */
Id handle;
struct deltarpm *d = &pd->delta;
-#ifdef DUMPOUT
- int i;
-#endif
-
-#ifdef DUMPOUT
- fprintf (stderr, "found deltarpm for %s:\n", id2str(pool, pd->newpkgname));
-#endif
handle = repodata_new_handle(pd->data);
/* we commit all handles later on in one go so that the
* repodata code doesn't need to realloc every time */
repodata_set_id(pd->data, handle, DELTA_PACKAGE_NAME, pd->newpkgname);
repodata_set_id(pd->data, handle, DELTA_PACKAGE_EVR, pd->newpkgevr);
repodata_set_id(pd->data, handle, DELTA_PACKAGE_ARCH, pd->newpkgarch);
- repodata_set_id(pd->data, handle, DELTA_LOCATION_NAME, d->locname);
- repodata_set_id(pd->data, handle, DELTA_LOCATION_DIR, d->locdir);
- repodata_set_id(pd->data, handle, DELTA_LOCATION_EVR, d->locevr);
- repodata_set_id(pd->data, handle, DELTA_LOCATION_SUFFIX, d->locsuffix);
+ if (d->location)
+ {
+ repodata_set_deltalocation(pd->data, handle, 0, 0, d->location);
+ if (d->locbase)
+ repodata_set_poolstr(pd->data, handle, DELTA_LOCATION_BASE, d->locbase);
+ }
if (d->downloadsize)
- repodata_set_num(pd->data, handle, DELTA_DOWNLOADSIZE, (d->downloadsize + 1023) / 1024);
+ repodata_set_num(pd->data, handle, DELTA_DOWNLOADSIZE, d->downloadsize);
if (d->filechecksum)
repodata_set_checksum(pd->data, handle, DELTA_CHECKSUM, d->filechecksumtype, d->filechecksum);
-#ifdef DUMPOUT
- fprintf (stderr, " loc: %s %s %s %s\n", id2str(pool, d->locdir),
- id2str(pool, d->locname), id2str(pool, d->locevr),
- id2str(pool, d->locsuffix));
- fprintf (stderr, " size: %d down\n", d->downloadsize);
- fprintf (stderr, " chek: %s\n", d->filechecksum);
-#endif
-
if (d->seqnum)
{
-#ifdef DUMPOUT
- fprintf (stderr, " base: %s\n",
- id2str(pool, d->bevr[0]));
- fprintf (stderr, " seq: %s\n",
- id2str(pool, d->seqname));
- fprintf (stderr, " %s\n",
- id2str(pool, d->seqevr));
- fprintf (stderr, " %s\n",
- d->seqnum);
-#endif
repodata_set_id(pd->data, handle, DELTA_BASE_EVR, d->bevr[0]);
repodata_set_id(pd->data, handle, DELTA_SEQ_NAME, d->seqname);
repodata_set_id(pd->data, handle, DELTA_SEQ_EVR, d->seqevr);
/* should store as binary blob! */
repodata_set_str(pd->data, handle, DELTA_SEQ_NUM, d->seqnum);
-
-#ifdef DUMPOUT
- fprintf(stderr, "OK\n");
-#endif
-
-#ifdef DUMPOUT
- if (d->seqevr != d->bevr[0])
- fprintf (stderr, "XXXXX evr\n");
- /* Name of package ("xxxx") should match the sequence info
- name. */
- if (strcmp(id2str(pool, d->seqname), id2str(pool, pd->newpkgname)))
- fprintf (stderr, "XXXXX name\n");
-#endif
}
- else
- {
-
-#ifdef DUMPOUT
- fprintf (stderr, " base:");
- for (i = 0; i < d->nbevr; i++)
- fprintf (stderr, " %s", id2str(pool, d->bevr[i]));
- fprintf (stderr, "\n");
-#endif
- }
-
}
pd->delta.filechecksum = solv_free(pd->delta.filechecksum);
pd->delta.bevr = solv_free(pd->delta.bevr);
pd->delta.nbevr = 0;
pd->delta.seqnum = solv_free(pd->delta.seqnum);
+ pd->delta.location = solv_free(pd->delta.location);
+ pd->delta.locbase = solv_free(pd->delta.locbase);
break;
case STATE_FILENAME:
- parse_delta_location(pd, pd->content);
+ pd->delta.location = solv_strdup(pd->content);
break;
case STATE_CHECKSUM:
pd->delta.filechecksum = solv_strdup(pd->content);
break;
case STATE_SIZE:
- pd->delta.downloadsize = atoi(pd->content);
+ pd->delta.downloadsize = strtoull(pd->content, 0, 10);
break;
case STATE_SEQUENCE:
if ((str = pd->content))
#define BUFF_SIZE 8192
-void
+int
repo_add_deltainfoxml(Repo *repo, FILE *fp, int flags)
{
Pool *pool = repo->pool;
pd.content = solv_malloc(256);
pd.acontent = 256;
pd.lcontent = 0;
- pd.tempstr = malloc(256);
- pd.atemp = 256;
- pd.ltemp = 0;
parser = XML_ParserCreate(NULL);
XML_SetUserData(parser, &pd);
l = fread(buf, 1, sizeof(buf), fp);
if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
{
- pool_debug(pool, SOLV_FATAL, "repo_updateinfoxml: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
- exit(1);
+ pd.ret = pool_error(pool, -1, "repo_updateinfoxml: %s at line %u:%u", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
+ break;
}
if (l == 0)
break;
}
XML_ParserFree(parser);
solv_free(pd.content);
- solv_free(pd.tempstr);
- join_freemem();
/* now commit all handles */
- for (i = 0; i < pd.nhandles; i++)
- repodata_add_flexarray(pd.data, SOLVID_META, REPOSITORY_DELTAINFO, pd.handles[i]);
+ if (!pd.ret)
+ for (i = 0; i < pd.nhandles; i++)
+ repodata_add_flexarray(pd.data, SOLVID_META, REPOSITORY_DELTAINFO, pd.handles[i]);
solv_free(pd.handles);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
+ return pd.ret;
}
/* EOF */