RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: rpm/tools/ rpmrepo.c

From: Jeff Johnson <jbj@rpm5.org>
Date: Tue 28 Sep 2010 - 01:13:29 CEST
Message-Id: <20100927231329.5C38CDA4F1@rpm5.org>
  RPM Package Manager, CVS Repository
  /cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
  Module: rpm                              Date:   28-Sep-2010 01:13:29
  Branch: HEAD                             Handle: 2010092723132800

  Modified files:
    rpm/tools               rpmrepo.c

  Log:
    - rpmrepo: finish refactoring tools/rpmrepo.c.

  Summary:
    Revision    Changes     Path
    2.31        +1  -302    rpm/tools/rpmrepo.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/tools/rpmrepo.c
  ============================================================================
  $ cvs diff -u -r2.30 -r2.31 rpmrepo.c
  --- rpm/tools/rpmrepo.c	18 Sep 2010 14:16:14 -0000	2.30
  +++ rpm/tools/rpmrepo.c	27 Sep 2010 23:13:28 -0000	2.31
  @@ -60,307 +60,6 @@
   
   /*==============================================================*/
   
  -/*==============================================================*/
  -
  -/**
  - * Read a header from a repository package file, computing package file digest.
  - * @param repo		repository
  - * @param path		package file path
  - * @return		header (NULL on error)
  - */
  -static Header repoReadHeader(rpmrepo repo, const char * path)
  -	/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
  -	/*@modifies repo, rpmGlobalMacroContext, fileSystem, internalState @*/
  -{
  -    /* XXX todo: read the payload and collect the blessed file digest. */
  -    FD_t fd = Fopen(path, "r.ufdio");
  -    Header h = NULL;
  -
  -    if (fd != NULL) {
  -	rpmts ts = repo->_ts;
  -	uint32_t algo = repo->pkgalgo;
  -	rpmRC rpmrc;
  -
  -	if (algo != PGPHASHALGO_NONE)
  -	    fdInitDigest(fd, algo, 0);
  -
  -	/* XXX what if path needs expansion? */
  -	rpmrc = rpmReadPackageFile(ts, fd, path, &h);
  -	if (algo != PGPHASHALGO_NONE) {
  -	    char buffer[32 * BUFSIZ];
  -	    size_t nb = sizeof(buffer);
  -	    size_t nr;
  -	    while ((nr = Fread(buffer, sizeof(buffer[0]), nb, fd)) == nb)
  -		{};
  -	    if (Ferror(fd)) {
  -		fprintf(stderr, _("%s: Fread(%s) failed: %s\n"),
  -			__progname, path, Fstrerror(fd));
  -		rpmrc = RPMRC_FAIL;
  -	    } else {
  -		static int asAscii = 1;
  -		const char *digest = NULL;
  -		fdFiniDigest(fd, algo, &digest, NULL, asAscii);
  -		(void) headerSetDigest(h, digest);
  -		digest = _free(digest);
  -	    }
  -	}
  -
  -	(void) Fclose(fd);
  -
  -	switch (rpmrc) {
  -	case RPMRC_NOTFOUND:
  -	case RPMRC_FAIL:
  -	default:
  -	    (void) headerFree(h);
  -	    h = NULL;
  -	    break;
  -	case RPMRC_NOTTRUSTED:
  -	case RPMRC_NOKEY:
  -	case RPMRC_OK:
  -	    if (repo->baseurl)
  -		(void) headerSetBaseURL(h, repo->baseurl);
  -	    (void) headerSetInstance(h, (uint32_t)repo->current+1);
  -	    break;
  -	}
  -    }
  -    return h;
  -}
  -
  -/**
  - * Return header query.
  - * @param h		header
  - * @param qfmt		query format
  - * @return		query format result
  - */
  -static const char * rfileHeaderSprintf(Header h, const char * qfmt)
  -	/*@globals fileSystem @*/
  -	/*@modifies h, fileSystem @*/
  -{
  -    const char * msg = NULL;
  -    const char * s = headerSprintf(h, qfmt, NULL, NULL, &msg);
  -    if (s == NULL)
  -	rpmrepoError(1, _("headerSprintf(%s): %s"), qfmt, msg);
  -assert(s != NULL);
  -    return s;
  -}
  -
  -#if defined(WITH_SQLITE)
  -/**
  - * Return header query, with "XXX" replaced by rpmdb header instance.
  - * @param h		header
  - * @param qfmt		query format
  - * @return		query format result
  - */
  -static const char * rfileHeaderSprintfHack(Header h, const char * qfmt)
  -	/*@globals fileSystem @*/
  -	/*@modifies h, fileSystem @*/
  -{
  -    static const char mark[] = "'XXX'";
  -    static size_t nmark = sizeof("'XXX'") - 1;
  -    const char * msg = NULL;
  -    char * s = (char *) headerSprintf(h, qfmt, NULL, NULL, &msg);
  -    char * f, * fe;
  -    int nsubs = 0;
  -
  -    if (s == NULL)
  -	rpmrepoError(1, _("headerSprintf(%s): %s"), qfmt, msg);
  -assert(s != NULL);
  -
  -    /* XXX Find & replace 'XXX' with '%{DBINSTANCE}' the hard way. */
  -/*@-nullptrarith@*/
  -    for (f = s; *f != '\0' && (fe = strstr(f, "'XXX'")) != NULL; fe += nmark, f = fe)
  -	nsubs++;
  -/*@=nullptrarith@*/
  -
  -    if (nsubs > 0) {
  -	char instance[64];
  -	int xx = snprintf(instance, sizeof(instance), "'%u'",
  -		(uint32_t) headerGetInstance(h));
  -	size_t tlen = strlen(s) + nsubs * ((int)strlen(instance) - (int)nmark);
  -	char * t = xmalloc(tlen + 1);
  -	char * te = t;
  -
  -	xx = xx;
  -/*@-nullptrarith@*/
  -	for (f = s; *f != '\0' && (fe = strstr(f, mark)) != NULL; fe += nmark, f = fe) {
  -	    *fe = '\0';
  -	    te = stpcpy( stpcpy(te, f), instance);
  -	}
  -/*@=nullptrarith@*/
  -	if (*f != '\0')
  -	    te = stpcpy(te, f);
  -	s = _free(s);
  -	s = t;
  -    }
  - 
  -    return s;
  -}
  -#endif
  -
  -/**
  - * Export a single package's metadata to repository metadata file(s).
  - * @param repo		repository
  - * @param rfile		repository metadata file
  - * @param h		header
  - * @return		0 on success
  - */
  -static int rpmrepoWriteMDFile(rpmrepo repo, rpmrfile rfile, Header h)
  -	/*@globals fileSystem @*/
  -	/*@modifies rfile, h, fileSystem @*/
  -{
  -    int rc = 0;
  -
  -    if (rfile->xml_qfmt != NULL) {
  -	if (rpmrfileXMLWrite(rfile, rfileHeaderSprintf(h, rfile->xml_qfmt)))
  -	    rc = 1;
  -    }
  -
  -#if defined(WITH_SQLITE)
  -    if (REPO_ISSET(DATABASE)) {
  -	if (rpmrfileSQLWrite(rfile, rfileHeaderSprintfHack(h, rfile->sql_qfmt)))
  -	    rc = 1;
  -    }
  -#endif
  -
  -    return rc;
  -}
  -
  -/**
  - * Export all package metadata to repository metadata file(s).
  - * @param repo		repository
  - * @return		0 on success
  - */
  -static int repoWriteMetadataDocs(rpmrepo repo)
  -	/*@globals h_errno, rpmGlobalMacroContext, fileSystem, internalState @*/
  -	/*@modifies repo, rpmGlobalMacroContext, fileSystem, internalState @*/
  -{
  -    const char ** pkglist = repo->pkglist;
  -    const char * pkg;
  -    int rc = 0;
  -
  -    if (pkglist)
  -    while ((pkg = *pkglist++) != NULL) {
  -	Header h = repoReadHeader(repo, pkg);
  -
  -	repo->current++;
  -
  -	/* XXX repoReadHeader() displays error. Continuing is foolish */
  -	if (h == NULL) {
  -	    rc = 1;
  -	    break;
  -	}
  -
  -#ifdef	REFERENCE
  -	/* XXX todo: rpmGetPath(mydir, "/", filematrix[mydir], NULL); */
  -	reldir = (pkgpath != NULL ? pkgpath : rpmGetPath(repo->basedir, "/", repo->directories[0], NULL));
  -	self.primaryfile.write(po.do_primary_xml_dump(reldir, baseurl=repo->baseurl))
  -	self.flfile.write(po.do_filelists_xml_dump())
  -	self.otherfile.write(po.do_other_xml_dump())
  -#endif
  -
  -	if (rpmrepoWriteMDFile(repo, &repo->primary, h)
  -	 || rpmrepoWriteMDFile(repo, &repo->filelists, h)
  -	 || rpmrepoWriteMDFile(repo, &repo->other, h))
  -	    rc = 1;
  -
  -	(void) headerFree(h);
  -	h = NULL;
  -	if (rc) break;
  -
  -	if (!repo->quiet) {
  -	    if (repo->verbose)
  -		rpmrepoError(0, "%d/%d - %s", repo->current, repo->pkgcount, pkg);
  -	    else
  -		rpmrepoProgress(repo, pkg, repo->current, repo->pkgcount);
  -	}
  -    }
  -    return rc;
  -}
  -
  -/**
  - * Write repository metadata files.
  - * @param repo		repository
  - * @return		0 on success
  - */
  -static int repoDoPkgMetadata(rpmrepo repo)
  -	/*@globals h_errno, rpmGlobalMacroContext, fileSystem, internalState @*/
  -	/*@modifies repo, rpmGlobalMacroContext, fileSystem, internalState @*/
  -{
  -    int rc = 0;
  -
  -    repo->current = 0;
  -
  -#ifdef	REFERENCE
  -    def _getFragmentUrl(self, url, fragment):
  -        import urlparse
  -        urlparse.uses_fragment.append('media')
  -        if not url:
  -            return url
  -        (scheme, netloc, path, query, fragid) = urlparse.urlsplit(url)
  -        return urlparse.urlunsplit((scheme, netloc, path, query, str(fragment)))
  -
  -    def doPkgMetadata(self):
  -        """all the heavy lifting for the package metadata"""
  -        if (argvCount(repo->directories) == 1) {
  -            MetaDataGenerator.doPkgMetadata(self)
  -            return
  -	}
  -
  -    ARGV_t roots = NULL;
  -    filematrix = {}
  -    for mydir in repo->directories {
  -	if (mydir[0] == '/')
  -	    thisdir = xstrdup(mydir);
  -	else if (mydir[0] == '.' && mydir[1] == '.' && mydir[2] == '/')
  -	    thisdir = Realpath(mydir, NULL);
  -	else
  -	    thisdir = rpmGetPath(repo->basedir, "/", mydir, NULL);
  -
  -	xx = argvAdd(&roots, thisdir);
  -	thisdir = _free(thisdir);
  -
  -	filematrix[mydir] = rpmrepoGetFileList(repo, roots, '.rpm')
  -	self.trimRpms(filematrix[mydir])
  -	repo->pkgcount = argvCount(filematrix[mydir]);
  -	roots = argvFree(roots);
  -    }
  -
  -    mediano = 1;
  -    repo->baseurl = self._getFragmentUrl(repo->baseurl, mediano)
  -#endif
  -
  -    if (rpmrepoOpenMDFile(repo, &repo->primary)
  -     || rpmrepoOpenMDFile(repo, &repo->filelists)
  -     || rpmrepoOpenMDFile(repo, &repo->other))
  -	rc = 1;
  -    if (rc) return rc;
  -
  -#ifdef	REFERENCE
  -    for mydir in repo->directories {
  -	repo->baseurl = self._getFragmentUrl(repo->baseurl, mediano)
  -	/* XXX todo: rpmGetPath(mydir, "/", filematrix[mydir], NULL); */
  -	if (repoWriteMetadataDocs(repo, filematrix[mydir]))
  -	    rc = 1;
  -	mediano++;
  -    }
  -    repo->baseurl = self._getFragmentUrl(repo->baseurl, 1)
  -#endif
  -
  -    if (repoWriteMetadataDocs(repo))
  -	rc = 1;
  -
  -    if (!repo->quiet)
  -	fprintf(stderr, "\n");
  -    if (rpmrepoCloseMDFile(repo, &repo->primary)
  -     || rpmrepoCloseMDFile(repo, &repo->filelists)
  -     || rpmrepoCloseMDFile(repo, &repo->other))
  -	rc = 1;
  -
  -    return rc;
  -}
  -
  -/*==============================================================*/
  -
   int
   main(int argc, char *argv[])
   	/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
  @@ -458,7 +157,7 @@
   	}
       }
   
  -    if ((rc = repoDoPkgMetadata(repo)) != 0)
  +    if ((rc = rpmrepoDoPkgMetadata(repo)) != 0)
   	goto exit;
       if ((rc = rpmrepoDoRepoMetadata(repo)) != 0)
   	goto exit;
  @@ .
Received on Tue Sep 28 01:13:29 2010
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.