RPM Community Forums

Mailing List Message of <rpm-devel>

Re: [CVS] RPM: rpm/ CHANGES rpm/rpmdb/ hdrfmt.c

From: Jeff Johnson <n3npq@mac.com>
Date: Fri 08 Apr 2011 - 00:40:11 CEST
Message-id: <99E9EE63-4551-4E3F-93B5-9AB7E00028B8@mac.com>
There's more todo++ here figgering out how Distepoch:/Disttag:
SHOULD be represented in a MongoDB store.

The input I'm currently testing with is this:

	rpm -qa --wnh:primary.mongo

I haven't the foggies idea where Distepoch:/Disttag: fit
into the the MongoDB JSON/BSON analogue of repo-md primary.xml

Nor do I care that much because:

1) the template is trivially altered to include (or not) Distepoch:/Disttag:

2) whatever I am shoving into a MongoDB has diddly squat to do with repo-md
primary.xml.

But perhaps someone else wishes consistency/compatibility with the "de facto"
existing repo-md XML/SQLITE markup.

I personally stopped caring about repo-md years ago because of the
lack of anything but "de facto" markup that can never be meaningfully
changed by anyone not part of Fedorable.

73 de Jeff
On Apr 7, 2011, at 6:02 PM, Jeff Johnson wrote:

>  RPM Package Manager, CVS Repository
>  http://rpm5.org/cvs/
>  ____________________________________________________________________________
> 
>  Server: rpm5.org                         Name:   Jeff Johnson
>  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
>  Module: rpm                              Date:   08-Apr-2011 00:02:10
>  Branch: HEAD                             Handle: 2011040722020901
> 
>  Modified files:
>    rpm                     CHANGES
>    rpm/rpmdb               hdrfmt.c
> 
>  Log:
>    - spewage: fix: rework sql/json markup to use the EVRD parser.
> 
>  Summary:
>    Revision    Changes     Path
>    1.3605      +1  -0      rpm/CHANGES
>    1.153       +71 -44     rpm/rpmdb/hdrfmt.c
>  ____________________________________________________________________________
> 
>  patch -p0 <<'@@ .'
>  Index: rpm/CHANGES
>  ============================================================================
>  $ cvs diff -u -r1.3604 -r1.3605 CHANGES
>  --- rpm/CHANGES	6 Apr 2011 23:33:17 -0000	1.3604
>  +++ rpm/CHANGES	7 Apr 2011 22:02:09 -0000	1.3605
>  @@ -1,4 +1,5 @@
>   5.4.0 -> 5.4.1:
>  +    - jbj: spewage: fix: rework sql/json markup to use the EVRD parser.
>       - jbj: build: fix: resurrect %description -l XY yet again.
>       - jbj: build: fix: attempt arbitrary '%foo' tag iff '%' is seen.
>       - jbj: mongo: drag-in the test suite. grdfs/replica_sets todo++.
>  @@ .
>  patch -p0 <<'@@ .'
>  Index: rpm/rpmdb/hdrfmt.c
>  ============================================================================
>  $ cvs diff -u -r1.152 -r1.153 hdrfmt.c
>  --- rpm/rpmdb/hdrfmt.c	25 Jan 2011 18:11:53 -0000	1.152
>  +++ rpm/rpmdb/hdrfmt.c	7 Apr 2011 22:02:10 -0000	1.153
>  @@ -527,7 +527,8 @@
>   /*@unchecked@*/ /*@observer@*/ 
>   static const struct spew_s _json_spew = {
>       .spew_name		= "json",
>  -    .spew_init		= "db.Packages.save({\n",
>  +    /* XXX non-functional atm, /usr/lib/rpm/qf *.mongo template for now. */
>  +    .spew_init		= "db.%{?__mongodb_collection}%{!?__mongodb_collection:packages}.save({\n",
>       .spew_fini		= "});\n",
>       .spew_strlen	= jsonstrlen,
>       .spew_strcpy	= jsonstrcpy
>  @@ -3284,19 +3285,20 @@
>   }
> 
>   static int PRCOSkip(rpmTag tag, rpmTagData N, rpmTagData EVR, rpmTagData F,
>  -		rpmuint32_t i)
>  +		uint32_t i)
>   	/*@*/
>   {
>       int a = -2, b = -2;
>  +    int rc = 0;
>  +
>  +assert(N.argv[i] != NULL && *N.argv[i] != '\0');
> 
>  -    if (N.argv[i] == NULL || *N.argv[i] == '\0')
>  -	return 1;
>       if (tag == RPMTAG_REQUIRENAME && i > 0
>        && !(a=strcmp(N.argv[i], N.argv[i-1]))
>        && !(b=strcmp(EVR.argv[i], EVR.argv[i-1]))
>        && (F.ui32p[i] & 0x4e) == ((F.ui32p[i-1] & 0x4e)))
>  -	return 1;
>  -    return 0;
>  +	rc = 1;
>  +    return rc;
>   }
> 
>   static int PRCOxmlTag(Header h, HE_t he, rpmTag EVRtag, rpmTag Ftag)
>  @@ -3308,9 +3310,9 @@
>       rpmTagData EVR = { .ptr = NULL };
>       rpmTagData F = { .ptr = NULL };
>       size_t nb;
>  -    rpmuint32_t ac;
>  -    rpmuint32_t c;
>  -    rpmuint32_t i;
>  +    uint32_t ac;
>  +    uint32_t c;
>  +    uint32_t i;
>       char *t;
>       int rc = 1;		/* assume failure */
>       int xx;
>  @@ -3520,10 +3522,10 @@
>       rpmTagData F = { .ptr = NULL };
>       char instance[64];
>       size_t nb;
>  -    rpmuint32_t ac;
>  -    rpmuint32_t c;
>  -    rpmuint32_t i;
>  -    char *t;
>  +    uint32_t ac;
>  +    uint32_t c;
>  +    uint32_t i;
>  +    char *te;
>       int rc = 1;		/* assume failure */
>       int xx;
> 
>  @@ -3544,7 +3546,7 @@
>       F.ui32p = he->p.ui32p;
> 
>       xx = snprintf(instance, sizeof(instance), "'%u'", (unsigned)headerGetInstance(h));
>  -    nb = sizeof(*he->p.argv);
>  +    nb = 0;
>       ac = 0;
>       for (i = 0; i < c; i++) {
>   /*@-nullstate@*/	/* EVR.argv might be NULL */
>  @@ -3552,63 +3554,88 @@
>   	    continue;
>   /*@=nullstate@*/
>   	ac++;
>  -	nb += sizeof(*he->p.argv);
>  -	nb += strlen(instance) + sizeof(", '', '', '', '', ''");
>  +	nb += strlen(instance) + sizeof(", '', '', '', '', ''") - 1;
>   	if (tag == RPMTAG_REQUIRENAME)
>   	    nb += sizeof(", ''") - 1;
>   	nb += strlen(N.argv[i]);
>   	if (EVR.argv != NULL && EVR.argv[i] != NULL && *EVR.argv[i] != '\0') {
>  -	    nb += strlen(EVR.argv[i]);
>  -	    nb += sizeof("EQ0") - 1;
>  +	    uint32_t Fx = ((F.ui32p[i] >> 1) & 0x7);
>  +	    EVR_t Revr = rpmEVRnew(Fx, 1);
>  +	    int xx = rpmEVRparse(xstrdup(EVR.argv[i]), Revr);
>  +	    const char * E = Revr->F[RPMEVR_E];
>  +	    const char * V = Revr->F[RPMEVR_V];
>  +	    const char * R = Revr->F[RPMEVR_R];
>  +#ifdef	NOTYET	/* XXX turning this on breaks rpmrepo */
>  +	    const char * D = Revr->F[RPMEVR_D];
>  +#endif
>  +	    xx = xx;
>  +	    nb += (sizeof(", 'EQ'")-1);
>  +	    nb += (sizeof(", ''")-1) + strlen(E);
>  +	    nb += (sizeof(", ''")-1) + strlen(V);
>  +	    nb += (sizeof(", ''")-1) + strlen(R);
>  +#ifdef	NOTYET	/* XXX turning this on breaks rpmrepo */
>  +	    nb += (sizeof(", ''")-1) + strlen(D);
>  +#endif
>  +	    Revr = rpmEVRfree(Revr);
>   	}
>   #ifdef	NOTNOW
>   	if (tag == RPMTAG_REQUIRENAME && (F.ui32p[i] & 0x40))
>   	    nb += sizeof("1") - 1;
>   #endif
>  +	nb++;
>       }
> 
>  +    nb += (ac + 1) * sizeof(*he->p.argv);
>  +
>       he->t = RPM_STRING_ARRAY_TYPE;
>       he->c = ac;
>       he->freeData = 1;
>  -    he->p.argv = xmalloc(nb + BUFSIZ);	/* XXX hack: leave slop */
>  -    t = (char *) &he->p.argv[he->c + 1];
>  +    he->p.argv = xmalloc(nb);
>  +    te = (char *) &he->p.argv[ac + 1];
>  +    *te = '\0';
>       ac = 0;
>       for (i = 0; i < c; i++) {
>   /*@-nullstate@*/	/* EVR.argv might be NULL */
>   	if (PRCOSkip(tag, N, EVR, F, i))
>   	    continue;
>   /*@=nullstate@*/
>  -	he->p.argv[ac++] = t;
>  -	t = stpcpy(t, instance);
>  -	t = stpcpy( stpcpy( stpcpy(t, ", '"), N.argv[i]), "'");
>  +	he->p.argv[ac++] = te;
>  +	te = stpcpy(te, instance);
>  +	te = stpcpy(te, ", '");
>  +	te = stpcpy(te, N.argv[i]);
>  +	te = stpcpy(te, "'");
>   /*@-readonlytrans@*/
>   	if (EVR.argv != NULL && EVR.argv[i] != NULL && *EVR.argv[i] != '\0') {
>  -	    static char *Fstr[] = { "?0","LT","GT","?3","EQ","LE","GE","?7" };
>  -	    rpmuint32_t Fx = ((F.ui32p[i] >> 1) & 0x7);
>  -	    const char *E, *V, *R;
>  -	    char *f, *fe;
>  -	    t = stpcpy( stpcpy( stpcpy(t, ", '"), Fstr[Fx]), "'");
>  -	    f = (char *) EVR.argv[i];
>  -	    for (fe = f; *fe != '\0' && *fe >= '0' && *fe <= '9'; fe++)
>  -		{};
>  -	    if (*fe == ':') { *fe++ = '\0'; E = f; f = fe; } else E = NULL;
>  -	    V = f;
>  -	    for (fe = f; *fe != '\0' && *fe != '-'; fe++)
>  -		{};
>  -	    if (*fe == '-') { *fe++ = '\0'; R = fe; } else R = NULL;
>  -	    t = stpcpy( stpcpy( stpcpy(t, ", '"), (E && *E ? E : "0")), "'");
>  -	    t = stpcpy( stpcpy( stpcpy(t, ", '"), V), "'");
>  -	    t = stpcpy( stpcpy( stpcpy(t, ", '"), (R ? R : "")), "'");
>  -	} else
>  -	    t = stpcpy(t, ", '', '', '', ''");
>  +	    static const char *Fstr[] = { "?0","LT","GT","?3","EQ","LE","GE","?7" };
>  +	    uint32_t Fx = ((F.ui32p[i] >> 1) & 0x7);
>  +	    EVR_t Revr = rpmEVRnew(Fx, 1);
>  +	    int xx = rpmEVRparse(xstrdup(EVR.argv[i]), Revr);
>  +	    const char * E = Revr->F[RPMEVR_E];
>  +	    const char * V = Revr->F[RPMEVR_V];
>  +	    const char * R = Revr->F[RPMEVR_R];
>  +#ifdef	NOTYET	/* XXX turning this on breaks rpmrepo */
>  +	    const char * D = Revr->F[RPMEVR_D];
>  +#endif
>  +	    xx = xx;
>  +	    te = stpcpy( stpcpy( stpcpy(te, ", '"), Fstr[Fx]), "'");
>  +	    te = stpcpy( stpcpy( stpcpy(te, ", '"), E), "'");
>  +	    te = stpcpy( stpcpy( stpcpy(te, ", '"), V), "'");
>  +	    te = stpcpy( stpcpy( stpcpy(te, ", '"), R), "'");
>  +#ifdef	NOTYET	/* XXX turning this on breaks rpmrepo */
>  +	    te = stpcpy( stpcpy( stpcpy(te, ", '"), D), "'");
>  +#endif
>  +	    Revr = rpmEVRfree(Revr);
>  +	} else {
>  +	    te = stpcpy(te, ", '', '', '', ''");
>  +	}
>   /*@=readonlytrans@*/
>   #ifdef	NOTNOW
>   	if (tag == RPMTAG_REQUIRENAME)
>  -	    t = stpcpy(stpcpy(stpcpy(t, ", '"),(F.ui32p[i] & 0x40) ? "1" : "0"), "'");
>  +	    te = stpcpy(stpcpy(stpcpy(te, ", '"),(F.ui32p[i] & 0x40) ? "1" : "0"), "'");
>   #endif
>  -	*t++ = '\0';
>  +	*te++ = '\0';
>       }
>  -    he->p.argv[he->c] = NULL;
>  +    he->p.argv[ac] = NULL;
>   /*@=compmempass@*/
>       rc = 0;
> 
>  @@ .
> ______________________________________________________________________
> RPM Package Manager                                    http://rpm5.org
> CVS Sources Repository                                rpm-cvs@rpm5.org
Received on Fri Apr 8 00:41:06 2011
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.