csomh / source-git / rpm

Forked from source-git/rpm 4 years ago
Clone
2ff057
#include "system.h"
2ff057
#include "lib/rpmfs.h"
2ff057
#include "debug.h"
2ff057
2ff057
struct rpmfs_s {
2ff057
    unsigned int fc;
2ff057
2ff057
    rpm_fstate_t * states;
2ff057
    rpmFileAction * actions;	/*!< File disposition(s). */
2ff057
2ff057
    sharedFileInfo replaced;	/*!< (TR_ADDED) to be replaced files in the rpmdb */
2ff057
    int numReplaced;
2ff057
    int allocatedReplaced;
2ff057
};
2ff057
2ff057
rpmfs rpmfsNew(rpm_count_t fc, int initState)
2ff057
{
2ff057
    rpmfs fs = xcalloc(1, sizeof(*fs));
2ff057
    fs->fc = fc;
2ff057
    fs->actions = xmalloc(fs->fc * sizeof(*fs->actions));
2ff057
    rpmfsResetActions(fs);
2ff057
    if (initState) {
2ff057
	fs->states = xmalloc(sizeof(*fs->states) * fs->fc);
2ff057
	memset(fs->states, RPMFILE_STATE_NORMAL, fs->fc);
2ff057
    }
2ff057
    return fs;
2ff057
}
2ff057
2ff057
rpmfs rpmfsFree(rpmfs fs)
2ff057
{
2ff057
    if (fs != NULL) {
2ff057
	free(fs->replaced);
2ff057
	free(fs->states);
2ff057
	free(fs->actions);
2ff057
	memset(fs, 0, sizeof(*fs)); /* trash and burn */
2ff057
	free(fs);
2ff057
    }
2ff057
    return NULL;
2ff057
}
2ff057
2ff057
rpm_count_t rpmfsFC(rpmfs fs)
2ff057
{
2ff057
    return (fs != NULL) ? fs->fc : 0;
2ff057
}
2ff057
2ff057
void rpmfsAddReplaced(rpmfs fs, int pkgFileNum, char rstate,
2ff057
			int otherPkg, int otherFileNum)
2ff057
{
2ff057
    if (!fs->replaced) {
2ff057
	fs->replaced = xcalloc(3, sizeof(*fs->replaced));
2ff057
	fs->allocatedReplaced = 3;
2ff057
    }
2ff057
    if (fs->numReplaced>=fs->allocatedReplaced) {
2ff057
	fs->allocatedReplaced += (fs->allocatedReplaced>>1) + 2;
2ff057
	fs->replaced = xrealloc(fs->replaced, fs->allocatedReplaced*sizeof(*fs->replaced));
2ff057
    }
2ff057
    fs->replaced[fs->numReplaced].pkgFileNum = pkgFileNum;
2ff057
    fs->replaced[fs->numReplaced].rstate = rstate;
2ff057
    fs->replaced[fs->numReplaced].otherPkg = otherPkg;
2ff057
    fs->replaced[fs->numReplaced].otherFileNum = otherFileNum;
2ff057
2ff057
    fs->numReplaced++;
2ff057
}
2ff057
2ff057
sharedFileInfo rpmfsGetReplaced(rpmfs fs)
2ff057
{
2ff057
    if (fs && fs->numReplaced)
2ff057
        return fs->replaced;
2ff057
    else
2ff057
        return NULL;
2ff057
}
2ff057
2ff057
sharedFileInfo rpmfsNextReplaced(rpmfs fs , sharedFileInfo replaced)
2ff057
{
2ff057
    if (fs && replaced) {
2ff057
        replaced++;
2ff057
	if (replaced - fs->replaced < fs->numReplaced)
2ff057
	    return replaced;
2ff057
    }
2ff057
    return NULL;
2ff057
}
2ff057
2ff057
void rpmfsSetState(rpmfs fs, unsigned int ix, rpmfileState state)
2ff057
{
2ff057
    assert(ix < fs->fc);
2ff057
    fs->states[ix] = state;
2ff057
}
2ff057
2ff057
rpmfileState rpmfsGetState(rpmfs fs, unsigned int ix)
2ff057
{
2ff057
    assert(ix < fs->fc);
2ff057
    if (fs->states) return fs->states[ix];
2ff057
    return RPMFILE_STATE_MISSING;
2ff057
}
2ff057
2ff057
rpm_fstate_t * rpmfsGetStates(rpmfs fs)
2ff057
{
2ff057
    return fs->states;
2ff057
}
2ff057
2ff057
rpmFileAction rpmfsGetAction(rpmfs fs, unsigned int ix)
2ff057
{
2ff057
    rpmFileAction action;
2ff057
    if (fs && fs->actions != NULL && ix < fs->fc) {
2ff057
	action = fs->actions[ix];
2ff057
    } else {
2ff057
	action = FA_UNKNOWN;
2ff057
    }
2ff057
    return action;
2ff057
}
2ff057
2ff057
void rpmfsSetAction(rpmfs fs, unsigned int ix, rpmFileAction action)
2ff057
{
2ff057
    if (fs->actions != NULL && ix < fs->fc) {
2ff057
	fs->actions[ix] = action;
2ff057
    }
2ff057
}
2ff057
2ff057
void rpmfsResetActions(rpmfs fs)
2ff057
{
2ff057
    if (fs && fs->actions) {
2ff057
	memset(fs->actions, FA_UNKNOWN, fs->fc * sizeof(*fs->actions));
2ff057
    }
2ff057
}