Skip to content

Commit

Permalink
added postgetcleanup placement
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-wa committed Mar 14, 2016
1 parent d5a69d4 commit fe294d0
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/include/kdbprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ typedef enum {
POSTROLLBACK,
PREGETSTORAGE,
POSTGETSTORAGE,
POSTGETCLEANUP,
PRESETSTORAGE,
PRECOMMIT,
POSTCOMMIT,
Expand Down
8 changes: 6 additions & 2 deletions src/libs/elektra/kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,11 +726,15 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)

ksRewind (ks);

if (elektraGetDoUpdate2(split, ks, parentKey) == -1)
if (elektraGetDoUpdate2 (split, ks, parentKey) == -1)
{
goto error;
}

if (handle->globalPlugins[POSTGETCLEANUP])
{
handle->globalPlugins[POSTGETCLEANUP]->kdbGet (handle->globalPlugins[POSTGETCLEANUP], ks, parentKey);
}

keySetName (parentKey, keyName (initialParent));
elektraSplitUpdateFileName (split, handle, parentKey);
keyDel (initialParent);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/elektra/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ int elektraMountGlobals (KDB * kdb, KeySet * keys, KeySet * modules, Key * error
continue;
const char * placement = keyBaseName (cur);
const char * pluginName = keyString (cur);
const char * globalPlacements[NR_GLOBAL_PLUGINS] = { "prerollback", "postrollback", "pregetstorage", "postgetstorage",
const char * globalPlacements[NR_GLOBAL_PLUGINS] = { "prerollback", "postrollback", "pregetstorage", "postgetstorage", "postgetcleanup",
"presetstorage", "precommit", "postcommit" };


Expand Down
37 changes: 30 additions & 7 deletions src/plugins/list/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,35 @@
#include <stdlib.h>
#include <string.h>

typedef enum { preGetStorage = 0, postGetStorage, postGetCleanup, getEnd } GetPlacements;
typedef enum
{
preGetStorage = 0,
postGetStorage,
postGetCleanup,
getEnd
} GetPlacements;

typedef enum { preSetStorage = 0, preCommit, postCommit, setEnd } SetPlacements;
typedef enum
{
preSetStorage = 0,
preCommit,
postCommit,
setEnd
} SetPlacements;

typedef enum { preRollback = 0, postRollback, errEnd } ErrPlacements;
typedef enum
{
preRollback = 0,
postRollback,
errEnd
} ErrPlacements;

typedef enum { GET, SET, ERR } OP;
typedef enum
{
GET,
SET,
ERR
} OP;

typedef struct
{
Expand All @@ -37,7 +59,7 @@ typedef struct

ErrPlacements errPlacements[2]; // prerollback and postrollback
SetPlacements setPlacements[3]; // presetstorage, precommit and postcommit
GetPlacements getPlacements[3]; // pregetstorage and postgetstorage
GetPlacements getPlacements[3]; // pregetstorage, postgetstorage, postgetclenaup

// each keyset contains the list of plugin names for a given placement
KeySet * setKS[3];
Expand Down Expand Up @@ -153,7 +175,7 @@ int elektraListOpen (Plugin * handle, Key * errorKey ELEKTRA_UNUSED)
if (sub)
{
const char * getString = keyString (sub);
const char * getStrings[] = { "pregetstorage", "postgetstorage" };
const char * getStrings[] = { "pregetstorage", "postgetstorage", "postgetcleanup" };
GetPlacements getPlacement = preGetStorage;
while (getPlacement != getEnd)
{
Expand Down Expand Up @@ -193,6 +215,7 @@ int elektraListClose (Plugin * handle, Key * errorKey)
Placements * placements = elektraPluginGetData (handle);
ksDel (placements->getKS[0]);
ksDel (placements->getKS[1]);
ksDel (placements->getKS[2]);
ksDel (placements->setKS[0]);
ksDel (placements->setKS[1]);
ksDel (placements->setKS[2]);
Expand All @@ -215,7 +238,7 @@ int elektraListClose (Plugin * handle, Key * errorKey)
}

static int runPlugins (KeySet * pluginKS, KeySet * modules, KeySet * plugins, KeySet * configOrig, KeySet * returned, Key * parentKey,
OP op, Key * (*traversalFunction) (KeySet *))
OP op, Key * (*traversalFunction)(KeySet *))
{
Key * current;

Expand Down
135 changes: 95 additions & 40 deletions src/plugins/spec/spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ typedef struct
OnConflict missing;
} ConflictHandling;

typedef struct
{
KeySet * ks;
int counter;
} PluginConfig;

static char * keyNameToMatchingString (const Key * key)
{
uint8_t arrayCount = 0;
Expand Down Expand Up @@ -939,6 +945,25 @@ static void matchedKeyCopyMeta (Key * key, Key * specKey, Key * parentKey, const
}
}

static void removeMeta (Key * key, Key * specKey, Key * parentKey)
{
keyRewindMeta (specKey);
while (keyNextMeta (specKey) != NULL)
{
const Key * meta = keyCurrentMeta (specKey);
const char * name = keyName (meta);
if (!(!strcmp (name, "array") || !strcmp (name, "required") || !strncmp (name, "conflict/", 9) ||
!strcmp (name, "require")))
{
const Key * oldMeta;
if ((oldMeta = keyGetMeta (key, name)) != NULL)
{
keySetMeta (key, name, 0);
}
}
}
}

static void copyMeta (Key * key, Key * specKey, Key * parentKey)
{
keyRewindMeta (specKey);
Expand Down Expand Up @@ -986,7 +1011,7 @@ static int hasRequired (Key * key, Key * specKey, KeySet * ks)
return 1;
}

static int doGlobbing (Key * parentKey, KeySet * returned, KeySet * specKS, ConflictHandling * ch, Direction dir)
static int doGlobbing (Key * parentKey, KeySet * returned, KeySet * specKS, ConflictHandling * ch, Direction dir, int clean)
{
Key * specKey;
ksRewind (specKS);
Expand Down Expand Up @@ -1015,42 +1040,49 @@ static int doGlobbing (Key * parentKey, KeySet * returned, KeySet * specKS, Conf
cursor_t cursor = ksGetCursor (returned);
if (matchPatternToKey (pattern, cur))
{
found = 1;
if (require)
if (!clean)
{
if (hasRequired (cur, specKey, returned)) copyMeta (cur, specKey, parentKey);
}
else if (keyGetMeta (cur, "conflict/invalid"))
{
copyMeta (cur, specKey, parentKey);
}
else if (keyGetMeta (cur, "spec/internal/valid"))
{
copyMeta (cur, specKey, parentKey);
}
else if (elektraArrayValidateName (cur) == 1)
{
validateArray (returned, cur, specKey);
copyMeta (cur, specKey, parentKey);
}
else if (!(strcmp (keyBaseName (specKey), "_")))
{
validateWildcardSubs (returned, cur, specKey);
copyMeta (cur, specKey, parentKey);
}
else
{
if (hasArray (cur))
found = 1;
if (require)
{
if (isValidArrayKey (cur))
{
copyMeta (cur, specKey, parentKey);
}
if (hasRequired (cur, specKey, returned)) copyMeta (cur, specKey, parentKey);
}
else
else if (keyGetMeta (cur, "conflict/invalid"))
{
copyMeta (cur, specKey, parentKey);
}
else if (keyGetMeta (cur, "spec/internal/valid"))
{
copyMeta (cur, specKey, parentKey);
}
else if (elektraArrayValidateName (cur) == 1)
{
validateArray (returned, cur, specKey);
copyMeta (cur, specKey, parentKey);
}
else if (!(strcmp (keyBaseName (specKey), "_")))
{
validateWildcardSubs (returned, cur, specKey);
copyMeta (cur, specKey, parentKey);
}
else
{
if (hasArray (cur))
{
if (isValidArrayKey (cur))
{
copyMeta (cur, specKey, parentKey);
}
}
else
{
copyMeta (cur, specKey, parentKey);
}
}
}
else
{
removeMeta (cur, specKey, parentKey);
}
}
ksSetCursor (returned, cursor);
Expand All @@ -1060,8 +1092,7 @@ static int doGlobbing (Key * parentKey, KeySet * returned, KeySet * specKS, Conf
{
if (keyGetMeta (specKey, "assign/condition")) // hardcoded for now because only assign/conditional currently exists
{
Key * newKey =
keyNew (strchr (keyName (specKey), '/'), KEY_CASCADING_NAME, KEY_END);
Key * newKey = keyNew (strchr (keyName (specKey), '/'), KEY_CASCADING_NAME, KEY_END);
copyMeta (newKey, specKey, parentKey);
ksAppendKey (returned, keyDup (newKey));
keyDel (newKey);
Expand Down Expand Up @@ -1151,6 +1182,22 @@ int elektraSpecGet (Plugin * handle, KeySet * returned, Key * parentKey)
onConflict = IGNORE;
}
}
int clean = 0;
PluginConfig * pluginConfig = elektraPluginGetData (handle);
if (pluginConfig)
{
++(pluginConfig->counter);
}
else
{
pluginConfig = elektraMalloc (sizeof (PluginConfig));
pluginConfig->counter = 0;
pluginConfig->ks = NULL;
}
if (pluginConfig->counter == 1)
{
clean = 1;
}
ch->member = onConflict;
ch->invalid = onConflict;
ch->count = onConflict;
Expand All @@ -1163,12 +1210,13 @@ int elektraSpecGet (Plugin * handle, KeySet * returned, Key * parentKey)
ksDel (conflictCut);
Key * specKey = keyNew ("spec", KEY_END);
KeySet * specKS = ksCut (returned, specKey);
elektraPluginSetData (handle, ksDup (specKS));
pluginConfig->ks = ksDup (specKS);
elektraPluginSetData (handle, pluginConfig);
keyDel (specKey);
KeySet * ks = ksCut (returned, parentKey);
ksRewind (ks);
ksRewind (specKS);
int ret = doGlobbing (parentKey, ks, specKS, ch, GET);
int ret = doGlobbing (parentKey, ks, specKS, ch, GET, clean);
ksAppend (returned, specKS);
ksAppend (returned, ks);
ksDel (ks);
Expand Down Expand Up @@ -1206,21 +1254,28 @@ int elektraSpecSet (Plugin * handle, KeySet * returned, Key * parentKey)
ch->conflict = onConflict;
ch->range = onConflict;
ch->missing = onConflict;

PluginConfig * pluginConfig = elektraPluginGetData (handle);
if (pluginConfig) pluginConfig->counter = 0;
KeySet * conflictCut = ksCut (config, onConflictConf);
parseConfig (conflictCut, ch);
ksAppend (config, conflictCut);
ksDel (conflictCut);
KeySet * specKS = elektraPluginGetData (handle);
KeySet * specKS = NULL;
if (pluginConfig) specKS = pluginConfig->ks;
KeySet * ks = ksCut (returned, parentKey);
ksRewind (ks);
ksRewind (specKS);
int ret = doGlobbing (parentKey, ks, specKS, ch, SET);
int ret = 0;
if (specKS)
{
ksRewind (specKS);
ret = doGlobbing (parentKey, ks, specKS, ch, SET, 0);
}
ksAppend (returned, ks);
ksDel (ks);
ksDel (specKS);
if (specKS) ksDel (specKS);
elektraFree (ch);
ksRewind (returned);
elektraPluginSetData (handle, pluginConfig);
return ret; // success
}

Expand Down

0 comments on commit fe294d0

Please sign in to comment.