-
Notifications
You must be signed in to change notification settings - Fork 123
Opts plugin #2471
Opts plugin #2471
Changes from 36 commits
cb4b2a1
ed5c798
4e4a5af
19b420d
da908a0
f9860a6
4c4d812
c46fc89
f77c480
b5f98ff
6ca1fb1
7bc960d
aeb860d
197c785
4f24207
d8faf43
ef896ca
4448503
79ceb9e
24a5885
dfb41d6
8925478
de7bab3
74b6308
71bacc8
08f0cef
65130e5
cb74c10
aa7e40f
7370a5f
844f566
b81e6a0
c79c67d
9f72f93
41ee812
71076e4
a5dbd40
31e9534
6767523
f078edf
d4fe121
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,25 @@ the `type` plugin will ignore the key. We now also support converting enum value | |
To switch from `boolean` to the new `type`, you don't have to do anything, if you used the default config. If you used a custom configuration | ||
please take a look at the [README](https://www.libelektra.org/plugins/type). | ||
|
||
### <<HIGHLIGHT2>> | ||
### kdbEnsure | ||
|
||
`kdbEnsure` is a new function in `elektra-kdb`. It can be used to ensure that a KDB instance meets certain conditions specified in a | ||
contract. In principle this a very powerful tool that may be used for a lot of things. For now it only supports a few conditions concerning | ||
plugins: | ||
|
||
- You can specify that a plugin should be mounted globally. This is can for example be used to enable the new [gopts](#gopts) plugin. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "This is can for example" -> "This can for example" |
||
- Conversely you can also define that a plugin should not be mounted globally, e.g. to disable the `spec` plugin, which is enabled by default. | ||
- Additionally you may want to enforce that a global plugin uses a certain configuration. For this case you can specify that the plugin | ||
should be remounted, i.e. unmounted and immediately mounted again. | ||
- In future non-global plugins will support the same features. But because of the different architecture involved, for now only unmounting | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to mention it. We might or might not add it. |
||
non-global plugins is supported. | ||
|
||
All changes made by `kdbEnsure` are purely temporary. They will only apply to the KDB handle passed to the function. | ||
|
||
IMPORTANT: `kdbEnsure` only works, if the `list` plugin is mounted in all appropriate global positions. | ||
|
||
Note: `kdbEnsure` right now ignores the `infos/recommends` and `infos/needs` metadata of plugins, so you have to explicitly take care of | ||
dependencies. _(Klemens Böswirth)_ | ||
|
||
### <<HIGHLIGHT2>> | ||
|
||
|
@@ -155,6 +173,15 @@ The following section lists news about the [modules](https://www.libelektra.org/ | |
|
||
- We fixed an incorrect format specifier in a call to the `syslog` function. _(René Schwaiger)_ | ||
|
||
### gOpts | ||
|
||
- The [gopts](https://www.libelektra.org/plugins/gopts) plugin simply retrieves the values of `argc`, `argv` and `envp` needed for | ||
[`elektraGetOpts`](https://www.libelektra.org/tutorials/command-line-options) and then makes the call. It is intended to be used as a | ||
global plugin, so that command-line options are automatically parsed when `kdbGet` is called. _(Klemens Böswirth)_ | ||
- The plugin works under WIN32 (via `GetCommandLineW` and `GetEnvironmentString`), MAC_OSX (`_NSGetArgc`, `_NSGetArgv`) and any system that | ||
either has a `sysctl(3)` function that accepts `KERN_PROC_ARGS` (e.g. FreeBSD) or when `procfs` is mounted and either `/proc/self` or | ||
`/proc/curproc` refers to the current process. If you need support for any other systems, feel free to add an implementation. | ||
|
||
## Libraries | ||
|
||
The text below summarizes updates to the [C (and C++)-based libraries](https://www.libelektra.org/libraries/readme) of Elektra. | ||
|
@@ -171,7 +198,7 @@ compiled against an older 0.8 version of Elektra will continue to work | |
|
||
### Core | ||
|
||
- <<TODO>> | ||
- `kdbGet` now calls global postgetstorage plugins with the parent key passed to `kdbGet`, instead of a random mountpoint. _(Klemens Böswirth)_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing I noticed (but didn't look into): At least some errors returned from global plugins are suppressed by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, we didn't even use return values until #2307. The global plugin implementation needs to be re-worked and tested properly, so that it matches the proposal. |
||
- <<TODO>> | ||
- <<TODO>> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,8 @@ class KDB | |
virtual inline int set (KeySet & returned, std::string const & keyname); | ||
virtual inline int set (KeySet & returned, Key & parentKey); | ||
|
||
inline int ensure (const KeySet & contract, Key & parentKey); | ||
|
||
private: | ||
ckdb::KDB * handle; ///< holds an kdb handle | ||
}; | ||
|
@@ -232,6 +234,33 @@ inline int KDB::set (KeySet & returned, Key & parentKey) | |
return ret; | ||
} | ||
|
||
/** | ||
* Ensures that the conditions defined in @p contract are met by this KDB. | ||
* | ||
* @see ckdb::kdbEnsure() | ||
* | ||
* @param contract The contract to ensure. | ||
* @param parentKey The parentKey to use. | ||
* | ||
* @throw KDBException if there were problems with the contract or the database | ||
* @throw ContractException if the contract couldn't be ensured | ||
*/ | ||
int KDB::ensure (const KeySet & contract, Key & parentKey) | ||
{ | ||
// have to ksDup because contract is consumed and ksDel()ed by kdbEnsure | ||
int ret = ckdb::kdbEnsure (handle, ckdb::ksDup (contract.getKeySet ()), parentKey.getKey ()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can replace ckdb::ksDup (contract.getKeySet ()) with the shorter
here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No that won't work, because that will cause a double free, because the C++ class KeySet will call |
||
if (ret == -1) | ||
{ | ||
throw KDBException (parentKey); | ||
} | ||
if (ret == 1) | ||
{ | ||
throw ContractException (parentKey); | ||
} | ||
return ret; | ||
} | ||
|
||
|
||
} // end of namespace kdb | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,10 +60,30 @@ class KDBException : public Exception | |
return m_str.c_str (); | ||
} | ||
|
||
private: | ||
protected: | ||
Key m_key; | ||
mutable std::string m_str; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be private? |
||
}; | ||
|
||
class ContractException : public KDBException | ||
{ | ||
public: | ||
explicit ContractException (Key key) : KDBException (key) | ||
{ | ||
} | ||
|
||
~ContractException () noexcept override = default; | ||
|
||
const char * what () const noexcept override | ||
{ | ||
if (!m_key) | ||
{ | ||
return "Malformed contract"; | ||
} | ||
return KDBException::what (); | ||
} | ||
}; | ||
|
||
} // namespace kdb | ||
|
||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,7 +202,4 @@ | |
|
||
|
||
|
||
|
||
|
||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conditions -> clauses (2x)