-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mount cli integration in C #4851
Mount cli integration in C #4851
Conversation
early stage, lots of open TODOs, work in progress
work in progress, not compiling
from the new kdb command (work in progress!) based on parts of the branch "kdb_cli_rewrite" from @hannes99
and add new `kdb mountpoint list` command
and some refactoring
re-implement C++-based code for mounting in C
and include elektra-meta as target link lib for src/libs/elektra
needed for handling of plugins during mounting only draft code, still needs: doc, tests, refactoring
add code for checking conflicts of plugins
for KeySets for infos and symbols (allocation)
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.
I know this isn't done yet, but I had a quick look anyway.
It seems this is basically a 1:1 translation of the C++ code. That's a good start, but there are some things that need to be done differently now that we have backend plugins. I also noticed a few things that could be simplified.
} | ||
|
||
/* STEP 2: Check for wrong namespace (proc) */ | ||
if (keyGetNamespace (mountPoint) == KEY_NS_PROC) |
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.
Mounting into proc:/
is in theory allowed by libelektra-kdb
.
|
||
/* STEP 3: Check for name match */ | ||
const char * mpName = keyName (mountPoint); | ||
if (keyGetNameSize (mountPoint) == 2 && *mpName == '/') |
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.
Seems rather complicated... Why not just do a cascading lookup and report the found key in the error?
Key * found = ksLookupByName (alreadyUsedMountpoints, mpName, 0);
if (found != NULL) {
fprintf (stderr, "Mountpoint '%s' not possible, because mountpoint '%s' already exists.\n", mpName, keyName (found));
}
This should work for all cases of mpName
ksDel (alreadyUsedMountpoints); | ||
ksDel (backendInfos); | ||
|
||
/* TODO: STEP 4: Check if mounted below system:/elektra */ |
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.
/* TODO: STEP 4: Check if mounted below system:/elektra */ | |
/* TODO: STEP 4: Check if mounted below /elektra in any namespace */ |
/* Remove namespace */ | ||
for (int i = 0; i < keyGetNameSize (elektraCheck); ++i) | ||
{ | ||
if (*(mpName + i) == ':') | ||
{ | ||
keySetName (elektraCheck, mpName + i + 1); | ||
} | ||
} |
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.
Pretty sure the keyIsBelow*
functions handle cascading keys too. Otherwise, please use:
/* Remove namespace */ | |
for (int i = 0; i < keyGetNameSize (elektraCheck); ++i) | |
{ | |
if (*(mpName + i) == ':') | |
{ | |
keySetName (elektraCheck, mpName + i + 1); | |
} | |
} | |
/* Remove namespace */ | |
keySetNamespace (elektraCheck, KEY_NS_CASCADING); |
size_t lenLookup = keyGetNameSize (cur); /* includes \0 */ | ||
if (lenLookup > 1) | ||
{ | ||
lenLookup += strlen ("/definition/path"); |
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.
That key is specific to the backend
plugin. We need a more general solution...
* | ||
* @return true if the provided str is a valid plugin-name, false otherwise | ||
*/ | ||
bool validatePluginName (const char * str) |
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.
AFAIK the name of plugins isn't actually validated anywhere else. The mount code should accept anything that is allowed by libelektra-kdb
and elektraPlugin*
.
elektraKeyToBoolean (tmp, &optForce); | ||
if ((tmp = GET_OPTION_KEY (options, "quiet"))) | ||
elektraKeyToBoolean (tmp, &optQuiet); | ||
if ((tmp = GET_OPTION_KEY (options, "interactive"))) |
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.
AFAIK we planned to remove the interactive mode, since nobody is using it anyway
if (!optQuiet && *argPath == '/' && keyMpNs != KEY_NS_SYSTEM && keyMpNs != KEY_NS_SPEC && keyMpNs != KEY_NS_CASCADING) | ||
{ | ||
printf("Note that absolute paths are still relative to their namespace (see `kdb plugin-info resolver`).\n"); | ||
printf("Only system+spec mountpoints are actually absolute.\n"); |
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.
That still depends on the backend plugin and for backend
on resolver plugin. It's just that the default resolver
does it this way
printf("Note that absolute paths are still relative to their namespace (see `kdb plugin-info resolver`).\n"); | ||
printf("Only system+spec mountpoints are actually absolute.\n"); | ||
printf("Use `kdb file %s` to determine where the file(s) are.\n", argMountpoint); | ||
printf("Use `-q` or use `kdb set %s/quiet 1` to suppress infos.\n", CLI_BASE_KEY); |
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.
printf("Use `-q` or use `kdb set %s/quiet 1` to suppress infos.\n", CLI_BASE_KEY); | |
printf("Use `-q` or use `kdb set %s/quiet 1` to suppress all infos like this.\n", CLI_BASE_KEY); |
As this PR gets merged into After the rebasing is done, I'll open a new PR with the changes since this PR. |
Implements code for listing mountpoints and mounting new files (includes plugin-resolution and -handling for mounting) in C.
Most of the C++-based code is now implemented in C, but there is still some work left, including testing, and refactoring.
I'll write a posting in this PR and add the label
needs review
as soon asThank you!
Basics
(added as entry in
doc/news/_preparation_next_release.md
whichcontains
_(my name)_
)Please always add something to the release notes.
(first line should have
module: short statement
syntax)close #X
, are in the commit messages.doc/news/_preparation_next_release.md
scripts/dev/reformat-all
Checklist
(not in the PR description)
Review
Labels