Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1745 from ElektraInitiative/kdb-mount
Browse files Browse the repository at this point in the history
Kdb mount
  • Loading branch information
markus2330 authored Dec 21, 2017
2 parents 6448179 + 0b0bd9c commit 41d3bc9
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 20 deletions.
6 changes: 4 additions & 2 deletions doc/help/elektra-merge-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Currently the following strategies exist:
* cut:
Removes existing keys below the resultpath and replaces them with the merged keyset.

* import:
* unchanged: (EXPERIMENTAL, only for kdb-mount)
Do not fail if the operation does not change anything.

* import: (DEPRECATED, avoid using it)
Preserves existing keys in the resultpath if they do not exist in the merged keyset.
If the key does exist in the merged keyset, it will be overwritten.
(avoid using it)
2 changes: 2 additions & 0 deletions doc/help/kdb-mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Use `kdb file <path>` to determine where the file(s) are.
Add a plugin configuration for all plugins.
- `-W`, `--with-recommends`:
Also add recommended plugins and warn if they are not available.
- `-f`, `--force`:
Unmount before mounting: Does not fail on already existing mountpoints.



Expand Down
4 changes: 2 additions & 2 deletions doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For more information, visit [https://libelektra.org](https://libelektra.org).
- Fosdem Talk about Elektra
- CC-licensed book about Elektra published
- Maturing of plugins
- Elektra with encryption:
- Elektra with encryption
- Preparation for switch to INI as default storage

### Fosdem Talk about Elektra in Main Track
Expand Down Expand Up @@ -85,7 +85,7 @@ While `crypto` encrypts individual values within configuration files, `fcrypt` e

For this release Peter Nirschl prepared a demo showing Elektra's cryptographic abilities:

![asciicast](https://asciinema.org/a/153014.png)](https://asciinema.org/a/153014)
[![asciicast](https://asciinema.org/a/153014.png)](https://asciinema.org/a/153014)

Thanks to Peter Nirschl for this great work!

Expand Down
18 changes: 14 additions & 4 deletions src/libs/tools/src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ void Backend::setMountpoint (Key mountpoint, KeySet mountConf)
alreadyUsedMountpoints.push_back (Key ("user" + name, KEY_END).getName ());
alreadyUsedMountpoints.push_back (Key ("system" + name, KEY_END).getName ());
}
else
{
alreadyUsedMountpoints.push_back (name);
}

// always add name itself, too
alreadyUsedMountpoints.push_back (name);

namesAsString += name;
namesAsString += " ";
}
Expand Down Expand Up @@ -142,6 +142,11 @@ void Backend::setMountpoint (Key mountpoint, KeySet mountConf)
// STEP 3: check for name match
if (smp == "/")
{
if (std::find (alreadyUsedMountpoints.begin (), alreadyUsedMountpoints.end (), "/") != alreadyUsedMountpoints.end ())
{
throw MountpointAlreadyInUseException (
"Root mountpoint not possible, because the root mountpoint already exists.\n");
}
Key specmp ("spec", KEY_END);
if (std::find (alreadyUsedMountpoints.begin (), alreadyUsedMountpoints.end (), specmp.getName ()) !=
alreadyUsedMountpoints.end ())
Expand Down Expand Up @@ -169,6 +174,11 @@ void Backend::setMountpoint (Key mountpoint, KeySet mountConf)
}
else if (smp.at (0) == '/')
{
if (std::find (alreadyUsedMountpoints.begin (), alreadyUsedMountpoints.end (), smp) != alreadyUsedMountpoints.end ())
{
throw MountpointAlreadyInUseException ("Cascading mountpoint " + smp +
" not possible, because cascading mountpoint " + smp + " already exists.\n");
}
Key dkmp ("dir" + smp, KEY_END);
if (std::find (alreadyUsedMountpoints.begin (), alreadyUsedMountpoints.end (), dkmp.getName ()) !=
alreadyUsedMountpoints.end ())
Expand Down
18 changes: 16 additions & 2 deletions src/plugins/dini/dini.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ int elektraDiniOpen (Plugin * handle, Key * errorKey ELEKTRA_UNUSED)
dini->iniConfig = ksDup (elektraPluginGetConfig (handle));
dini->dump = elektraInvokeOpen ("dump", dini->dumpConfig);
dini->ini = elektraInvokeOpen ("ini", dini->iniConfig);
dini->bin = elektraInvokeOpen ("binary", dini->iniConfig);

dini->dumpErrors = keyNew ("", KEY_END);

Expand All @@ -32,6 +33,7 @@ int elektraDiniClose (Plugin * handle, Key * errorKey ELEKTRA_UNUSED)
{
Dini * dini = elektraPluginGetData (handle);

elektraInvokeClose (dini->bin);
elektraInvokeClose (dini->ini);
elektraInvokeClose (dini->dump);

Expand Down Expand Up @@ -73,14 +75,26 @@ int elektraDiniGet (Plugin * handle, KeySet * returned, Key * parentKey)
return ELEKTRA_PLUGIN_STATUS_SUCCESS;
}

return elektraInvoke2Args (dini->ini, "get", returned, parentKey);
int ret = elektraInvoke2Args (dini->ini, "get", returned, parentKey);
if (dini->bin)
{
ret |= elektraInvoke2Args (dini->bin, "get", returned, parentKey); // postgetstorage
}
return ret;
}

int elektraDiniSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
{
// set all keys
Dini * dini = elektraPluginGetData (handle);
return elektraInvoke2Args (dini->ini, "set", returned, parentKey);

int ret = 0;
if (dini->bin)
{
elektraInvoke2Args (dini->bin, "set", returned, parentKey); // presetstorage
}
ret |= elektraInvoke2Args (dini->ini, "set", returned, parentKey);
return ret;
}

Plugin * ELEKTRA_PLUGIN_EXPORT (dini)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/dini/dini.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct
KeySet * modules;
ElektraInvokeHandle * dump;
ElektraInvokeHandle * ini;
ElektraInvokeHandle * bin;
KeySet * dumpConfig;
KeySet * iniConfig;
Key * dumpErrors;
Expand Down
34 changes: 34 additions & 0 deletions src/tools/kdb/mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <cmdline.hpp>
#include <mount.hpp>

#include <keysetio.hpp>

#include <fstream>
#include <iostream>
#include <iterator>
Expand Down Expand Up @@ -101,6 +103,15 @@ void MountCommand::buildBackend (Cmdline const & cl)
throw invalid_argument (mp + " is not a valid mountpoint");
}

KeySet dupMountConf = mountConf.dup ();

if (cl.force || cl.strategy != "preserve")
{
Key cutKey (Backends::mountpointsPath, KEY_END);
cutKey.addBaseName (mpk.getName ());
mountConf.cut (cutKey);
}

backend.setMountpoint (mpk, mountConf);

backend.setBackendConfig (cl.getPluginsConfig ("system/"));
Expand Down Expand Up @@ -161,6 +172,29 @@ void MountCommand::buildBackend (Cmdline const & cl)
// Call it a day
outputMissingRecommends (backend.resolveNeeds (cl.withRecommends));
backend.serialize (mountConf);

if (cl.strategy == "unchanged" && cl.debug)
{
cout << "The new configuration is:" << endl;
std::cout << mountConf;
std::cout << "------------------------" << std::endl;
cout << "The configuration originally was:" << endl;
std::cout << dupMountConf;
}

if (!cl.force && (cl.strategy == "unchanged" && mountConf != dupMountConf))
{
// throw error because it is not unchanged
try
{
backend.setMountpoint (mpk, dupMountConf);
}
catch (MountpointAlreadyInUseException const & e)
{
throw MountpointAlreadyInUseException (
std::string ("Requested unchanged mountpoint but mount would lead to changes\n") + e.what ());
}
}
}

void MountCommand::readPluginConfig (KeySet & pluginConfig)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/kdb/mount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MountCommand : public MountBaseCommand

virtual std::string getShortOptions () override
{
return "dqiR0123cW";
return "dfqisR0123cW";
}

virtual std::string getSynopsis () override
Expand Down
10 changes: 1 addition & 9 deletions src/tools/kdb/mountbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,7 @@ void MountBaseCommand::getMountpoint (Cmdline const & cl)
{
if (cur.getBaseName () == "mountpoint")
{
if (cur.getString ().at (0) == '/')
{
mountpoints.push_back (Key ("user" + cur.getString (), KEY_END).getName ());
mountpoints.push_back (Key ("system" + cur.getString (), KEY_END).getName ());
}
else
{
mountpoints.push_back (cur.getString ());
}
mountpoints.push_back (cur.getString ());
};
}

Expand Down

0 comments on commit 41d3bc9

Please sign in to comment.