From d221895352955d5ee0503855f71c4bc242019273 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 12 Mar 2010 08:32:15 +0200 Subject: [PATCH] Split file state structures + routines out of rpmte to separate sources - no functional changes --- lib/Makefile.am | 2 +- lib/rpmfs.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/rpmfs.h | 55 +++++++++++++++++++++++++ lib/rpmte.c | 98 -------------------------------------------- lib/rpmte_internal.h | 73 +-------------------------------- 5 files changed, 171 insertions(+), 170 deletions(-) create mode 100644 lib/rpmfs.c create mode 100644 lib/rpmfs.h diff --git a/lib/Makefile.am b/lib/Makefile.am index fb7e7bf..8c8cf3a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -29,7 +29,7 @@ librpm_la_SOURCES = \ rpmal.c rpmal.h rpmchecksig.c rpmds.c rpmfi.c rpmfi_internal.h rpmgi.c \ rpminstall.c rpmts_internal.h \ rpmlead.c rpmlead.h rpmps.c rpmrc.c \ - rpmte.c rpmte_internal.h rpmts.c \ + rpmte.c rpmte_internal.h rpmts.c rpmfs.h rpmfs.c \ rpmvercmp.c signature.c signature.h transaction.c \ verify.c rpmlock.c rpmlock.h misc.h \ rpmscript.h rpmscript.c legacy.c merge.c \ diff --git a/lib/rpmfs.c b/lib/rpmfs.c new file mode 100644 index 0000000..50ed6d9 --- /dev/null +++ b/lib/rpmfs.c @@ -0,0 +1,113 @@ +#include "system.h" +#include "lib/rpmfs.h" +#include "debug.h" + +struct rpmfs_s { + unsigned int fc; + + rpm_fstate_t * states; + rpmFileAction * actions; /*!< File disposition(s). */ + + sharedFileInfo replaced; /*!< (TR_ADDED) to be replaced files in the rpmdb */ + int numReplaced; + int allocatedReplaced; +}; + +rpmfs rpmfsNew(unsigned int fc, rpmElementType type) { + rpmfs fs = xmalloc(sizeof(*fs)); + fs->fc = fc; + fs->replaced = NULL; + fs->states = NULL; + if (type == TR_ADDED) { + fs->states = xmalloc(sizeof(*fs->states) * fs->fc); + memset(fs->states, RPMFILE_STATE_NORMAL, fs->fc); + } + fs->actions = xmalloc(fc * sizeof(*fs->actions)); + memset(fs->actions, FA_UNKNOWN, fc * sizeof(*fs->actions)); + fs->numReplaced = fs->allocatedReplaced = 0; + return fs; +} + +rpmfs rpmfsFree(rpmfs fs) { + fs->replaced = _free(fs->replaced); + fs->states = _free(fs->states); + fs->actions = _free(fs->actions); + + fs = _free(fs); + return fs; +} + +rpm_count_t rpmfsFC(rpmfs fs) { + return fs->fc; +} + +void rpmfsAddReplaced(rpmfs fs, int pkgFileNum, int otherPkg, int otherFileNum) +{ + if (!fs->replaced) { + fs->replaced = xcalloc(3, sizeof(*fs->replaced)); + fs->allocatedReplaced = 3; + } + if (fs->numReplaced>=fs->allocatedReplaced) { + fs->allocatedReplaced += (fs->allocatedReplaced>>1) + 2; + fs->replaced = xrealloc(fs->replaced, fs->allocatedReplaced*sizeof(*fs->replaced)); + } + fs->replaced[fs->numReplaced].pkgFileNum = pkgFileNum; + fs->replaced[fs->numReplaced].otherPkg = otherPkg; + fs->replaced[fs->numReplaced].otherFileNum = otherFileNum; + + fs->numReplaced++; +} + +sharedFileInfo rpmfsGetReplaced(rpmfs fs) +{ + if (fs && fs->numReplaced) + return fs->replaced; + else + return NULL; +} + +sharedFileInfo rpmfsNextReplaced(rpmfs fs , sharedFileInfo replaced) +{ + if (fs && replaced) { + replaced++; + if (replaced - fs->replaced < fs->numReplaced) + return replaced; + } + return NULL; +} + +void rpmfsSetState(rpmfs fs, unsigned int ix, rpmfileState state) +{ + assert(ix < fs->fc); + fs->states[ix] = state; +} + +rpmfileState rpmfsGetState(rpmfs fs, unsigned int ix) +{ + assert(ix < fs->fc); + if (fs->states) return fs->states[ix]; + return RPMFILE_STATE_MISSING; +} + +rpm_fstate_t * rpmfsGetStates(rpmfs fs) +{ + return fs->states; +} + +rpmFileAction rpmfsGetAction(rpmfs fs, unsigned int ix) +{ + rpmFileAction action; + if (fs->actions != NULL && ix < fs->fc) { + action = fs->actions[ix]; + } else { + action = FA_UNKNOWN; + } + return action; +} + +void rpmfsSetAction(rpmfs fs, unsigned int ix, rpmFileAction action) +{ + if (fs->actions != NULL && ix < fs->fc) { + fs->actions[ix] = action; + } +} diff --git a/lib/rpmfs.h b/lib/rpmfs.h new file mode 100644 index 0000000..c9ba8da --- /dev/null +++ b/lib/rpmfs.h @@ -0,0 +1,55 @@ +#ifndef _RPMFS_H +#define _RPMFS_H + +#include +#include + +/** \ingroup rpmfs + * Transaction element file states. + */ +typedef struct rpmfs_s * rpmfs; +typedef struct sharedFileInfo_s * sharedFileInfo; +typedef char rpm_fstate_t; + +/* XXX psm needs access to these */ +struct sharedFileInfo_s { + int pkgFileNum; + int otherPkg; + int otherFileNum; +}; + +RPM_GNUC_INTERNAL +rpmfs rpmfsNew(unsigned int fc, rpmElementType type); + +RPM_GNUC_INTERNAL +rpmfs rpmfsFree(rpmfs fs); + +RPM_GNUC_INTERNAL +rpm_count_t rpmfsFC(rpmfs fs); + +RPM_GNUC_INTERNAL +void rpmfsAddReplaced(rpmfs fs, int pkgFileNum, int otherPkg, int otherFileNum); + +RPM_GNUC_INTERNAL +sharedFileInfo rpmfsGetReplaced(rpmfs fs); + +RPM_GNUC_INTERNAL +sharedFileInfo rpmfsNextReplaced(rpmfs fs , sharedFileInfo replaced); + +RPM_GNUC_INTERNAL +void rpmfsSetState(rpmfs fs, unsigned int ix, rpmfileState state); + +RPM_GNUC_INTERNAL +rpmfileState rpmfsGetState(rpmfs fs, unsigned int ix); + +/* May return NULL */ +RPM_GNUC_INTERNAL +rpm_fstate_t * rpmfsGetStates(rpmfs fs); + +RPM_GNUC_INTERNAL +rpmFileAction rpmfsGetAction(rpmfs fs, unsigned int ix); + +/* XXX this should be internal too but build code needs for now */ +void rpmfsSetAction(rpmfs fs, unsigned int ix, rpmFileAction action); + +#endif /* _RPMFS_H */ diff --git a/lib/rpmte.c b/lib/rpmte.c index c7ae0cb..9764c7c 100644 --- a/lib/rpmte.c +++ b/lib/rpmte.c @@ -735,101 +735,3 @@ rpmfs rpmteGetFileStates(rpmte te) { return te->fs; } -rpmfs rpmfsNew(unsigned int fc, rpmElementType type) { - rpmfs fs = xmalloc(sizeof(*fs)); - fs->fc = fc; - fs->replaced = NULL; - fs->states = NULL; - if (type == TR_ADDED) { - fs->states = xmalloc(sizeof(*fs->states) * fs->fc); - memset(fs->states, RPMFILE_STATE_NORMAL, fs->fc); - } - fs->actions = xmalloc(fc * sizeof(*fs->actions)); - memset(fs->actions, FA_UNKNOWN, fc * sizeof(*fs->actions)); - fs->numReplaced = fs->allocatedReplaced = 0; - return fs; -} - -rpmfs rpmfsFree(rpmfs fs) { - fs->replaced = _free(fs->replaced); - fs->states = _free(fs->states); - fs->actions = _free(fs->actions); - - fs = _free(fs); - return fs; -} - -rpm_count_t rpmfsFC(rpmfs fs) { - return fs->fc; -} - -void rpmfsAddReplaced(rpmfs fs, int pkgFileNum, int otherPkg, int otherFileNum) -{ - if (!fs->replaced) { - fs->replaced = xcalloc(3, sizeof(*fs->replaced)); - fs->allocatedReplaced = 3; - } - if (fs->numReplaced>=fs->allocatedReplaced) { - fs->allocatedReplaced += (fs->allocatedReplaced>>1) + 2; - fs->replaced = xrealloc(fs->replaced, fs->allocatedReplaced*sizeof(*fs->replaced)); - } - fs->replaced[fs->numReplaced].pkgFileNum = pkgFileNum; - fs->replaced[fs->numReplaced].otherPkg = otherPkg; - fs->replaced[fs->numReplaced].otherFileNum = otherFileNum; - - fs->numReplaced++; -} - -sharedFileInfo rpmfsGetReplaced(rpmfs fs) -{ - if (fs && fs->numReplaced) - return fs->replaced; - else - return NULL; -} - -sharedFileInfo rpmfsNextReplaced(rpmfs fs , sharedFileInfo replaced) -{ - if (fs && replaced) { - replaced++; - if (replaced - fs->replaced < fs->numReplaced) - return replaced; - } - return NULL; -} - -void rpmfsSetState(rpmfs fs, unsigned int ix, rpmfileState state) -{ - assert(ix < fs->fc); - fs->states[ix] = state; -} - -rpmfileState rpmfsGetState(rpmfs fs, unsigned int ix) -{ - assert(ix < fs->fc); - if (fs->states) return fs->states[ix]; - return RPMFILE_STATE_MISSING; -} - -rpm_fstate_t * rpmfsGetStates(rpmfs fs) -{ - return fs->states; -} - -rpmFileAction rpmfsGetAction(rpmfs fs, unsigned int ix) -{ - rpmFileAction action; - if (fs->actions != NULL && ix < fs->fc) { - action = fs->actions[ix]; - } else { - action = FA_UNKNOWN; - } - return action; -} - -void rpmfsSetAction(rpmfs fs, unsigned int ix, rpmFileAction action) -{ - if (fs->actions != NULL && ix < fs->fc) { - fs->actions[ix] = action; - } -} diff --git a/lib/rpmte_internal.h b/lib/rpmte_internal.h index a3080b6..edf9a9f 100644 --- a/lib/rpmte_internal.h +++ b/lib/rpmte_internal.h @@ -3,46 +3,13 @@ #include #include - -/** \ingroup rpmte - * Dependncy ordering information. - */ - -/** - */ -typedef struct sharedFileInfo_s * sharedFileInfo; +#include "lib/rpmfs.h" /** \ingroup rpmte * Transaction element ordering chain linkage. */ typedef struct tsortInfo_s * tsortInfo; -/** \ingroup rpmte - * Transaction element file states. - */ -typedef struct rpmfs_s * rpmfs; - -/** - */ -struct sharedFileInfo_s { - int pkgFileNum; - int otherPkg; - int otherFileNum; -}; - -typedef char rpm_fstate_t; - -struct rpmfs_s { - unsigned int fc; - - rpm_fstate_t * states; - rpmFileAction * actions; /*!< File disposition(s). */ - - sharedFileInfo replaced; /*!< (TR_ADDED) to be replaced files in the rpmdb */ - int numReplaced; - int allocatedReplaced; -}; - RPM_GNUC_INTERNAL rpmfi rpmteSetFI(rpmte te, rpmfi fi); @@ -76,45 +43,9 @@ tsortInfo rpmteTSI(rpmte te); RPM_GNUC_INTERNAL void rpmteSetTSI(rpmte te, tsortInfo tsi); -//RPM_GNUC_INTERNAL +/* XXX should be internal too but build code needs for now... */ rpmfs rpmteGetFileStates(rpmte te); -RPM_GNUC_INTERNAL -rpmfs rpmfsNew(unsigned int fc, rpmElementType type); - -RPM_GNUC_INTERNAL -rpmfs rpmfsFree(rpmfs fs); - -RPM_GNUC_INTERNAL -rpm_count_t rpmfsFC(rpmfs fs); - -RPM_GNUC_INTERNAL -void rpmfsAddReplaced(rpmfs fs, int pkgFileNum, int otherPkg, int otherFileNum); - -RPM_GNUC_INTERNAL -sharedFileInfo rpmfsGetReplaced(rpmfs fs); - -RPM_GNUC_INTERNAL -sharedFileInfo rpmfsNextReplaced(rpmfs fs , sharedFileInfo replaced); - -RPM_GNUC_INTERNAL -void rpmfsSetState(rpmfs fs, unsigned int ix, rpmfileState state); - -RPM_GNUC_INTERNAL -rpmfileState rpmfsGetState(rpmfs fs, unsigned int ix); - -/* - * May return NULL - */ -RPM_GNUC_INTERNAL -rpm_fstate_t * rpmfsGetStates(rpmfs fs); - -RPM_GNUC_INTERNAL -rpmFileAction rpmfsGetAction(rpmfs fs, unsigned int ix); - -//RPM_GNUC_INTERNAL -void rpmfsSetAction(rpmfs fs, unsigned int ix, rpmFileAction action); - /* XXX here for now... */ /** * Relocate files in header. -- 2.7.4