Skip to content

Commit

Permalink
global hook approach for postget
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-wa committed Mar 14, 2016
1 parent 5143505 commit 98b1b60
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
40 changes: 39 additions & 1 deletion src/libs/elektra/kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,14 @@ static int elektraGetDoUpdate (Split * split, Key * parentKey)
keySetName (parentKey, keyName (split->parents[i]));
keySetString (parentKey, keyString (split->parents[i]));

for (size_t p = 1; p < NR_OF_PLUGINS; ++p)
for (size_t p = 1; p < 6; ++p)
{
int ret = 0;
if (backend->getplugins[p])
{
ret = backend->getplugins[p]->kdbGet (backend->getplugins[p], split->keysets[i], parentKey);
}

if (ret == -1)
{
// Ohh, an error occurred,
Expand All @@ -526,7 +527,39 @@ static int elektraGetDoUpdate (Split * split, Key * parentKey)
return 0;
}

static int elektraGetDoUpdate2 (Split * split, KeySet * ks, Key * parentKey)
{
const int bypassedSplits = 1;
for (size_t i = 0; i < split->size - bypassedSplits; i++)
{
if (!test_bit (split->syncbits[i], SPLIT_FLAG_SYNC))
{
// skip it, update is not needed
continue;
}
Backend * backend = split->handles[i];
ksRewind (split->keysets[i]);
keySetName (parentKey, keyName (split->parents[i]));
keySetString (parentKey, keyString (split->parents[i]));

for (size_t p = 6; p < NR_OF_PLUGINS; ++p)
{
int ret = 0;
if (backend->getplugins[p])
{
ret = backend->getplugins[p]->kdbGet (backend->getplugins[p], ks, parentKey);
}

if (ret == -1)
{
// Ohh, an error occurred,
// lets stop the process.
return -1;
}
}
}
return 0;
}
/**
* @brief Retrieve keys in an atomic and universal way.
*
Expand Down Expand Up @@ -693,6 +726,11 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)

ksRewind (ks);

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

keySetName (parentKey, keyName (initialParent));
elektraSplitUpdateFileName (split, handle, parentKey);
keyDel (initialParent);
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/spec/spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,10 @@ static void matchedKeyCopyMeta (Key * key, Key * specKey, Key * parentKey, const
const char * metaString = keyString (metaKey);

// name relative to parent key
const char * relativeName = strchr (keyName (specKey), '/') + strlen (strchr (keyName (parentKey), '/')) + 1;
size_t offset = 1;
if (strchr (keyName (parentKey), '/') != NULL) offset += strlen ((strchr (keyName (parentKey), '/')));

const char * relativeName = strchr (keyName (specKey), '/') + offset;

int hasWildcard = 0;
int singleWC = 0;
Expand Down Expand Up @@ -1059,7 +1062,7 @@ static int doGlobbing (Key * parentKey, KeySet * returned, KeySet * specKS, Conf
{
Key * newKey =
keyNew (strchr (keyName (specKey), '/'), KEY_CASCADING_NAME, KEY_END);
copyMeta (cur, specKey, parentKey);
copyMeta (newKey, specKey, parentKey);
ksAppendKey (returned, keyDup (newKey));
keyDel (newKey);
}
Expand Down

0 comments on commit 98b1b60

Please sign in to comment.