18 #define _RPMGI_INTERNAL
19 #define _RPMTS_INTERNAL
77 if (!(fts_info >= 1 && fts_info <= 14))
101 fd =
Fopen(fn, fmode);
103 if (fd == NULL ||
Ferror(fd)) {
105 if (fd != NULL) (void)
Fclose(fd);
110 #if defined(POSIX_FADV_WILLNEED)
112 (void)
Fadvise(fd, 0, 0, POSIX_FADV_WILLNEED);
198 if (gi->argv != NULL && gi->argv[gi->i] != NULL) {
199 gi->keyp = gi->argv[gi->i];
225 if (gi->argv != NULL && gi->argv[gi->i] != NULL)
229 fn = gi->argv[gi->i];
231 if (strchr(
"-+=", *fn) == NULL && !(gi->flags &
RPMGI_NOHEADER)) {
236 rpmrc = (
rpmRC) gi->rc;
251 gi->argv[gi->i] = NULL;
255 gi->argv[gi->i] = fn;
299 if (strcmp(s,
".rpm"))
333 if (gi->ftsp != NULL)
334 while ((gi->fts =
Fts_read(gi->ftsp)) != NULL) {
335 if (gi->walkPathFilter)
336 rpmrc = (*gi->walkPathFilter) (gi);
355 if (gi->stash != NULL)
356 (void) (*gi->stash) (gi, gi->h);
371 for (se = s; *se; se++) {
379 for (se = s; *se; se++) {
408 while (argv[ac] != NULL)
419 while ((arg = *argv++) != NULL) {
449 fprintf(stderr,
"*** gi %p key %p[%d]\tmi %p\n", gi, gi->keyp, (
int)gi->keylen, gi->mi);
451 if (gi->argv != NULL)
452 for (av = (
const char **) gi->argv; *av != NULL; av++) {
462 if ((ae = strchr(a,
'=')) != NULL) {
478 fprintf(stderr,
"\tav %p[%d]: \"%s\" -> %s ~= \"%s\"\n", gi->argv, (
int)(av - gi->argv), *av,
tagName((
rpmTag)tag), pat);
502 gi->hdrPath =
_free(gi->hdrPath);
508 if (gi->ftsp != NULL) {
513 if (gi->fd != NULL) {
533 if (_rpmgiPool == NULL) {
539 memset(((
char *)gi)+
sizeof(gi->_item), 0,
sizeof(*gi)-
sizeof(gi->_item));
575 gi->walkPathFilter = NULL;
594 fprintf(stderr,
"--> %s(%p) tag %s\n", __FUNCTION__, gi,
tagName(gi->tag));
599 gi->hdrPath =
_free(gi->hdrPath);
611 if (rpmrc !=
RPMRC_OK || gi->mi == NULL) {
619 if (gi->mi != NULL) {
626 gi->hdrPath =
rpmExpand(
"rpmdb h# ", hnum, NULL);
646 if (gi->mi != NULL) {
653 gi->hdrPath =
rpmExpand(
"rpmdb h# ", hnum, NULL);
667 const char * teTypeString = NULL;
673 if ((p =
rpmtsiNext(gi->tsi, teType)) != NULL) {
679 case TR_ADDED: teTypeString =
"+++";
break;
682 sprintf(hnum,
"%u", (
unsigned)gi->i);
683 gi->hdrPath =
rpmExpand(
"%s h# ", teTypeString, hnum, NULL);
696 const char * path =
rpmExpand(
"%{?_query_hdlist_path}", NULL);
697 if (path == NULL || *path ==
'\0') {
701 gi->fd =
rpmgiOpen(path,
"rm%{?_rpmgio}");
705 if (gi->fd != NULL) {
707 const char item[] =
"Header";
708 const char * msg = NULL;
726 sprintf(hnum,
"%u", (
unsigned)gi->i);
727 gi->hdrPath =
rpmExpand(
"hdlist h# ", hnum, NULL);
734 if (gi->fd != NULL) (void)
Fclose(gi->fd);
742 fprintf(stderr,
"*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i]);
749 gi->hdrPath =
xstrdup(gi->argv[gi->i]);
752 if (gi->argv == NULL || gi->argv[0] == NULL)
756 gi->ftsp =
Fts_open((
char *
const *)gi->argv, gi->ftsOpts, NULL);
771 gi->hdrPath =
xstrdup(gi->fts->fts_path);
817 xx = (*gi->tsOrder) (ts);
827 gi->hdrPath =
_free(gi->hdrPath);
833 fprintf(stderr,
"<-- %s(%p) rc %d\n", __FUNCTION__, gi, rpmrc);
844 return (gi != NULL ? gi->hdrPath : NULL);
850 return (gi != NULL ? gi->h : NULL);
857 return (gi != NULL ? gi->ts : NULL);
863 return (gi != NULL ? gi->rc :
RPMRC_OK);
869 gi->ftsOpts = ftsOpts;
int rpmgiRc(rpmgi gi)
Return current iteration item(s) exit code.
FTS * Fts_open(char *const *argv, int options, int(*compar)(const FTSENT **, const FTSENT **))
Create a handle for file hierarchy traversal.
const char bson_timestamp_t * ts
rpmgiFlags rpmgiGetFlags(rpmgi gi)
Return current iteration flags.
uint32_t rpmmiInstance(rpmmi mi)
Return header instance for current position of rpmdb iterator.
Structures used for an "rpmte" transaction element.
char * xstrdup(const char *str)
FD_t Fopen(const char *path, const char *_fmode)
fopen(3) clone.
int rpmtsAddInstallElement(rpmts ts, Header h, fnpyKey key, int upgrade, rpmRelocation relocs)
Add package to be installed to transaction set.
rpmgi rpmgiLink(rpmgi gi, const char *msg)
Reference a generalized iterator instance.
int argvAppend(ARGV_t *argvp, ARGV_t av)
Append one argv array to another.
Header rpmgiHeader(rpmgi gi)
Return current iteration header.
static const char * ftsInfoStrings[]
int Fadvise(FD_t fd, off_t offset, off_t length, int advice)
posix_fadvise(2) clone.
rpmtsi rpmtsiFree(rpmtsi tsi)
Destroy transaction element iterator.
static void rpmlog(int code, const char *fmt,...)
rpmElementType rpmteType(rpmte te)
Retrieve type of transaction element.
const char * rpmgiEscapeSpaces(const char *s)
Escape isspace(3) characters in string.
rpmts rpmtsLink(rpmts ts, const char *msg)
Reference a transaction set instance.
static rpmRC rpmgiGlobArgv(rpmgi gi, ARGV_t argv)
Append globbed arg list to iterator.
struct rpmte_s * rpmte
An element of a transaction set, i.e.
rpmTag tagValue(const char *tagstr)
Return tag value from name.
enum rpmElementType_e rpmElementType
Transaction element type.
int rpmGlob(const char *patterns, int *argcPtr, const char ***argvPtr)
Return URL path(s) from a (URL prefixed) pattern glob.
static const char * ftsInfoStr(int fts_info)
const char * Fstrerror(FD_t fd)
strerror(3) clone.
void * xcalloc(size_t nmemb, size_t size)
rpmgi rpmgiNew(rpmts ts, int tag, const void *keyp, size_t keylen)
Return a generalized iterator.
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
static const char * _query_hdlist_path
int rpmcliInstallOrder(rpmts ts)
Order package elements in a transaction set, reporting problems.
enum rpmgiFlags_e rpmgiFlags
static rpmRC rpmgiInitFilter(rpmgi gi)
Return rpmdb match iterator with filters (if any) set.
enum rpmdepFlags_e rpmdepFlags
Bit(s) to control rpmtsCheck() and rpmtsOrder() operation.
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
const char * tagName(rpmTag tag)
Return tag name from value.
Routines to expand a manifest containing glob expressions into an argv list.
rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char *fn, Header *hdrp)
Return package header from file handle, verifying digests/signatures.
rpmRC rpmgiSetArgs(rpmgi gi, ARGV_t argv, int ftsOpts, rpmgiFlags flags)
Load iterator args.
The FD_t File Handle data structure.
rpmmi rpmtsInitIterator(const rpmts ts, rpmTag rpmtag, const void *keyp, size_t keylen)
Return transaction database iterator.
Header headerFree(Header h)
Dereference a header instance.
FTSENT * Fts_read(FTS *sp)
Return next node in the file hierarchy traversal.
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
static rpmRC rpmgiWalkPathFilter(rpmgi gi)
Filter file tree walk path.
static rpmgi rpmgiGetPool(rpmioPool pool)
rpmRC rpmReadPackageManifest(FD_t fd, int *argcPtr, const char ***argvPtr)
Read manifest, glob items, and append to existing args.
const char const char int arg
int rpmcliInstallSuggests(rpmts ts)
Report packages(if any) that satisfy unresolved dependencies.
rpmmi rpmmiFree(rpmmi mi)
Destroy rpm database iterator.
int Fclose(FD_t fd)
fclose(3) clone.
const char const bson int mongo_write_concern int flags
rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type)
Return next transaction element of type.
int rpmcliInstallCheck(rpmts ts)
Check package element dependencies in a transaction set, reporting problems.
Header rpmteHeader(rpmte te)
Retrieve header from transaction element.
static FD_t rpmgiOpen(const char *path, const char *fmode)
Open a file after macro expanding path.
Header headerLink(Header h)
Reference a header instance.
rpmdb rpmtsGetRdb(rpmts ts)
Get transaction set database handle.
struct rpmgi_s * rpmgi
Generalized iterator.
enum rpmRC_e rpmRC
RPM return codes.
int Ferror(FD_t fd)
ferror(3) clone.
int rpmmiAddPattern(rpmmi mi, rpmTag tag, rpmMireMode mode, const char *pattern)
Add pattern to iterator selector.
rpmdepFlags rpmtsDFlags(rpmts ts)
Get dependency flags, i.e.
rpmdepFlags rpmtsSetDFlags(rpmts ts, rpmdepFlags depFlags)
Set dependency flags, i.e.
static void rpmgiFini(void *_gi)
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
static rpmRC rpmgiLoadReadHeader(rpmgi gi)
Read next header from package, lazily expanding manifests as found.
Methods to handle package elements.
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
rpmts rpmgiTs(rpmgi gi)
Return current iteration transaction set.
struct rpmts_s * rpmts
The RPM Transaction Set.
static rpmRC rpmgiLoadNextKey(rpmgi gi)
Load next key from argv list.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Header rpmmiNext(rpmmi mi)
Return next package header from iteration.
int rpmtsAddEraseElement(rpmts ts, Header h, uint32_t hdrNum)
Add package to be erased to transaction set.
int Fts_close(FTS *sp)
Destroy a file hierarchy traversal handle.
rpmRC rpmgiNext(rpmgi gi)
Perform next iteration step.
Header rpmgiReadHeader(rpmgi gi, const char *path)
Return header from package.
const char * rpmgiHdrPath(rpmgi gi)
Return current header path.
rpmRC rpmpkgRead(const char *fn, FD_t fd, void *ptr, const char **msg)
Read item from file descriptor.
rpmtsi rpmtsiInit(rpmts ts)
Create transaction element iterator.
Access RPM indices using Berkeley DB interface(s).
static rpmRC rpmgiLoadManifest(rpmgi gi, const char *path)
Load manifest into iterator arg list.
int rpmdbBlockDBI(rpmdb db, int tag)
Block access to a single database index.
#define RPMDBI_PACKAGES
Pseudo-tags used by the rpmdb and rpmgi iterator API's.
tsmStage rpmtsSetGoal(rpmts ts, tsmStage goal)
Set goal of transaction set.
static rpmRC rpmgiWalkReadHeader(rpmgi gi)
Read header from next package, lazily walking file tree.