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

Commit

Permalink
kdb-mount: experimental strategy feature
Browse files Browse the repository at this point in the history
"--strategy unchanged" as discussed #1306
seems to be buggy:
e.g. if plugins add plugin config (like dump)
     parent keys disappear and it seems like
     the config was changed (although it was not)
  • Loading branch information
Markus Raab committed Dec 19, 2017
1 parent e53a8f3 commit 3cd0a53
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 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)
29 changes: 28 additions & 1 deletion 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,7 +103,9 @@ void MountCommand::buildBackend (Cmdline const & cl)
throw invalid_argument (mp + " is not a valid mountpoint");
}

if (cl.force)
KeySet dupMountConf = mountConf.dup ();

if (cl.force || cl.strategy != "preserve")
{
Key cutKey (Backends::mountpointsPath, KEY_END);
cutKey.addBaseName (mpk.getName ());
Expand Down Expand Up @@ -168,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 "dfqiR0123cW";
return "dfqisR0123cW";
}

virtual std::string getSynopsis () override
Expand Down

0 comments on commit 3cd0a53

Please sign in to comment.