Skip to content
This repository was archived by the owner on Feb 16, 2025. It is now read-only.

Commit

Permalink
Merge pull request #1793 from sanssecours/💖
Browse files Browse the repository at this point in the history
INI: Never Store Non-Empty Keys as Section
  • Loading branch information
markus2330 authored Jan 27, 2018
2 parents f46ed25 + f8dc0f6 commit 4ae750b
Show file tree
Hide file tree
Showing 10 changed files with 513 additions and 503 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ before_script:
CMAKE_OPT+=("-DCOMMON_FLAGS=-Werror")
fi
# use a minimal configuration for the haskell bindings to give it enough time to compile dependencies
- if [[ $HASKELL == ON ]]; then bindings="haskell"; fi
- if [[ $HASKELL == ON ]]; then plugins="resolver_fm_hpu_b;dump;ini;dini;sync;error;hosts;list;glob;profile;spec;network;tracer;timeofday;base64;haskell"; fi
- if [[ $HASKELL == ON ]]; then tools="kdb"; fi
- |
if [[ $HASKELL == ON ]]; then
bindings="haskell"
plugins="resolver_fm_hpu_b;dump;ini;dini;sync;error;hosts;list;glob;profile;spec;network;tracer;timeofday;base64;haskell"
tools="kdb"
fi
- |
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
python2_ver=$(python2 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') && \
Expand Down
16 changes: 15 additions & 1 deletion doc/man/elektra-libs.7
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "ELEKTRA\-LIBS" "7" "October 2017" "" ""
.TH "ELEKTRA\-LIBS" "7" "January 2018" "" ""
.
.SH "NAME"
\fBelektra\-libs\fR \- libs overview
Expand Down Expand Up @@ -36,6 +36,20 @@ libelektra\-plugin\.so
.P
\fBlibplugin \fIplugin/\fR\fR contains \fBelektraPlugin*\fR symbols and plugins should link against it\.
.
.SS "Libpluginprocess"
.
.nf

libelektra\-pluginprocess\.so
.
.fi
.
.P
\fBlibpluginprocess \fIpluginprocess/\fR\fR contains functions aiding in executing plugins in a separate process and communicating with those child processes\. This child process is forked from Elektra\'s main process each time such plugin is used and gets closed again afterwards\. It uses a simple communication protocol based on a KeySet that gets serialized through a pipe via the dump plugin to orchestrate the processes\.
.
.P
This is useful for plugins which cause memory leaks to be isolated in an own process\. Furthermore this is useful for runtimes or libraries that cannot be reinitialized in the same process after they have been used\.
.
.SS "Libproposal"
.
.nf
Expand Down
11 changes: 6 additions & 5 deletions doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ The interface for I/O bindings is currently experimental.

### Plugin Processes

A new library called [pluginprocess](https://github.com/ElektraInitiative/libelektra/tree/master/src/libs/pluginprocess)
A new library called [pluginprocess](https://github.com/ElektraInitiative/libelektra/tree/master/src/libs/pluginprocess)
has been added. This library contains functions that aid in executing plugins in
a separate process. This child process is forked from Elektra's main process
a separate process. This child process is forked from Elektra's main process
each time such plugin is used and gets closed again afterwards. It uses a simple
communication protocol based on a KeySet that gets serialized through a pipe via
the dump plugin to orchestrate the processes.

Such a behavior this is useful for plugins which cause memory leaks to be
isolated in an own process. Furthermore this is useful for runtimes or libraries
Such a behavior this is useful for plugins which cause memory leaks to be
isolated in an own process. Furthermore this is useful for runtimes or libraries
that cannot be reinitialized in the same process after they have been used.

### <<HIGHLIGHT2>>
Expand All @@ -103,7 +103,7 @@ We added even more functionality, which could not make it to the highlights:
- Elektra is now part of the official [Homebrew repository](http://formulae.brew.sh/formula/elektra). We still provide a
[tap](http://github.com/ElektraInitiative/homebrew-elektra), if you want to install Elektra together with plugins or bindings that require
additional libraries.
- The building and linking of the haskell bindings and haskell plugins has been
- The building and linking of the haskell bindings and haskell plugins has been
[greatly improved](https://github.com/ElektraInitiative/libelektra/pull/1698).

## Documentation
Expand Down Expand Up @@ -157,6 +157,7 @@ Many problems were resolved with the following fixes:

- We fixed [internal inconsistency](https://github.com/ElektraInitiative/libelektra/pull/1761) in the CMake code of the [Augeas plugin](https://www.libelektra.org/plugins/augeas)
- We fixed various small bugs that could potentially cause the INI plugin to crash
- The INI plugin now [converts a section to a normal key-value pair](https://github.com/ElektraInitiative/libelektra/issues/1793) if you store a value inside it. This has the advantage that you will not [lose data unexpectedly anymore](https://github.com/ElektraInitiative/libelektra/issues/1697).

## Outlook

Expand Down
23 changes: 1 addition & 22 deletions src/plugins/ini/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,27 +140,6 @@ kdb rm -r user/examples/ini
sudo kdb umount user/examples/ini
```

## Directory Values

By default the INI plugin does not store values in a directory key, if you create a leaf node below the directory key first.

```sh
sudo kdb mount config.ini /examples/ini ini

kdb set /examples/ini/aimee/man 'Deathly'
kdb file /examples/ini | xargs cat
#> [aimee]
#> man = Deathly
kdb set /examples/ini/aimee 'Save Me'
kdb get /examples/ini/aimee/man
#> Deathly
kdb get /examples/ini/aimee # 😭
#>

kdb rm -r /examples/ini
sudo kdb umount /examples/ini
```

## Binary Data

By default the INI plugin does not support binary data. You can use the [Base64 plugin](../base64/) to remove this limitation.
Expand Down Expand Up @@ -235,7 +214,7 @@ sudo kdb umount user/examples/ini
The ini plugin supports 3 different sectioning modes (via `section=`):

- `NONE` sections wont be printed as `[Section]` but as part of the key name `section/key`
- `NULL` only binary keys will be printed as `[Section]`
- `NULL` only empty keys will be printed as `[Section]`
- `ALWAYS` sections will be created automatically. This is the default setting:

```sh
Expand Down
92 changes: 42 additions & 50 deletions src/plugins/ini/ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,7 @@ static int iniKeyToElektraKey (void * vhandle, const char * section, const char

static short isSectionKey (Key * key)
{
if (!key) return 0;
if (keyGetMeta (key, "internal/ini/section"))
return 1;
else
return 0;
return key && keyGetMeta (key, "internal/ini/section");
}

static int iniSectionToElektraKey (void * vhandle, const char * section)
Expand Down Expand Up @@ -1257,7 +1253,7 @@ static int iniWriteKeySet (FILE * fh, Key * parentKey, KeySet * returned, IniPlu
}
else
{
if (isSectionKey (cur))
if (isSectionKey (cur) && keyGetValueSize (cur) <= 1)
{
if (keyIsBelow (parentKey, cur))
{
Expand All @@ -1276,64 +1272,60 @@ static int iniWriteKeySet (FILE * fh, Key * parentKey, KeySet * returned, IniPlu
fprintf (fh, "[]\n");
}
}
else if (!keyGetMeta (cur, "internal/ini/section"))
else
{
if (config->sectionHandling != NONE)
// handle possible section conflicts
const Key * parentMeta = keyGetMeta (cur, "internal/ini/parent");
if (parentMeta && !keyIsBelow (sectionKey, cur))
{
// handle possible section conflicts
const Key * parentMeta = keyGetMeta (cur, "internal/ini/parent");
if (parentMeta && !keyIsBelow (sectionKey, cur))
Key * oldSectionKey = sectionKey;
sectionKey = keyNew (keyString (parentMeta), KEY_END);
if (!keyIsBelow (oldSectionKey, sectionKey))
{
Key * oldSectionKey = sectionKey;
sectionKey = keyNew (keyString (parentMeta), KEY_END);
if (!keyIsBelow (oldSectionKey, sectionKey))
if (keyIsBelow (parentKey, sectionKey))
{
char * name = getIniName (parentKey, sectionKey);
fprintf (fh, "[%s]\n", name);
elektraFree (name);
}
else if (!strcmp (keyName (parentKey), "/") && !strcmp (keyString (parentMeta), "/"))
{
fprintf (fh, "[]\n");
}
else if (!strcmp (keyName (parentKey), "/"))
{
fprintf (fh, "[%s]\n", keyString (parentMeta));
}
else if (!strcmp (keyName (sectionKey), keyName (parentKey)))
{
fprintf (fh, "[]\n");
}
else if (keyGetNamespace (sectionKey) != keyGetNamespace (oldSectionKey))
{
if (keyIsBelow (parentKey, sectionKey))
{
char * name = getIniName (parentKey, sectionKey);
fprintf (fh, "[%s]\n", name);
elektraFree (name);
}
else if (!strcmp (keyName (parentKey), "/") &&
!strcmp (keyString (parentMeta), "/"))
{
else
fprintf (fh, "[]\n");
}
else if (!strcmp (keyName (parentKey), "/"))
{
fprintf (fh, "[%s]\n", keyString (parentMeta));
}
else if (!strcmp (keyName (sectionKey), keyName (parentKey)))
{
fprintf (fh, "[]\n");
}
else if (keyGetNamespace (sectionKey) != keyGetNamespace (oldSectionKey))
{
if (keyIsBelow (parentKey, sectionKey))
{
char * name = getIniName (parentKey, sectionKey);
fprintf (fh, "[%s]\n", name);
elektraFree (name);
}
else
fprintf (fh, "[]\n");
}

if (removeSectionKey)
{
// remove previous sectionKey
keyDel (oldSectionKey);
}

// mark allocated sectionKey to be freed later
removeSectionKey = 1;
}
else

if (removeSectionKey)
{
keyDel (sectionKey);
sectionKey = oldSectionKey;
removeSectionKey = 0;
// remove previous sectionKey
keyDel (oldSectionKey);
}

// mark allocated sectionKey to be freed later
removeSectionKey = 1;
}
else
{
keyDel (sectionKey);
sectionKey = oldSectionKey;
removeSectionKey = 0;
}
}
if (keyGetMeta (cur, "internal/ini/array") && config->array)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/mathcheck/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Full example:
```sh
# Backup-and-Restore:/examples/mathcheck

sudo kdb mount mathcheck.dump /examples/mathcheck dump mathcheck
sudo kdb mount mathcheck.dump /examples/mathcheck mathcheck

kdb set /examples/mathcheck/a 3.1
kdb set /examples/mathcheck/b 4.5
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/mathcheck/mathcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ int elektraMathcheckSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key
{
const Key * meta = keyGetMeta (cur, "check/math");
if (!meta) continue;
ELEKTRA_LOG_DEBUG ("Check key “%s” with value “%s”", keyName (cur), keyString (meta));
result = parsePrefixString (keyString (meta), cur, ksDup (returned), parentKey);
ELEKTRA_LOG_DEBUG ("Result: “%f”", result.value);
char val1[MAX_CHARS_DOUBLE];
char val2[MAX_CHARS_DOUBLE];
strncpy (val1, keyString (cur), sizeof (val1));
Expand Down Expand Up @@ -440,6 +442,7 @@ int elektraMathcheckSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key
}
else if (result.op == SET)
{
ELEKTRA_LOG_DEBUG ("Set value of “%s” to “%s”", keyName (cur), val2);
keySetString (cur, val2);
}
}
Expand Down
Loading

0 comments on commit 4ae750b

Please sign in to comment.