.TH "doc_decisions_0_drafts_readonly_keynames_md" 3elektra "Fri Aug 4 2023" "Version 0.11.0" "Elektra" \" -*- nroff -*-
.ad l
.nh
.SH NAME
doc_decisions_0_drafts_readonly_keynames_md \- Readonly Keynames 
 
.SH "Problem"
.PP
It might be a good idea to prevent changes to the keyname after creation\&. Currently, the name of a key is automatically made read-only, when it is currently part of or at some point in the past was part of at least one \fCKeySet\fP\&. There are discussions about making key names writable again, when the key is removed from all \fCKeySet\fPs\&.
.PP
There may also be situations where changing the name of a key after its creation is required\&. In some situations, it may be wise to reuse a key instead of deleting it and creating a new one\&.
.SH "Constraints"
.PP
.IP "1." 4
\fCkeyAddName\fP et al\&. still have to work up to a certain point 2\&. 3\&.
.PP
.SH "Assumptions"
.PP
1\&. 2\&. 3\&.
.SH "Considered Alternatives"
.PP
.SS "Separate API for keynames"
Use the proposed \fCElektraBuffer\fP struct to create a separate API for keynames independent of the \fCKey\fP API\&.
.SS "Read-only keynames"
The key name should be permanently read-only after creation\&.
.PP
TBD: How would we dynamically create keynames with this approach?
.SS "Re-entrant lock for the key name"
Since we assume a single threaded context, this can be implemented as a simple counter\&.
.PP
.PP
.nf
struct _Key {
    // [\&.\&.\&.] other stuff
   uint16_t nameLock; // if zero, name is writable, otherwise name is readonly
};

void keyLockName (Key * k) {
    k->nameLock++;
}

void keyUnlockName (Key * k) {
    if (k->nameLock == 0) return;
    k->nameLock--;
}

void ksAppendKey (KeySet * ks, Key * k) {
    keyLockName (k);
    // [\&.\&.\&.]
}

void ksRemove (KeySet * ks, elektraCursor cursor) {
    keyUnlockName (ks->array[cursor]);
    // [\&.\&.\&.]
}
.fi
.PP
.SS "Alternative C"
.SH "Decision"
.PP
.SH "Rationale"
.PP
.SH "Implications"
.PP
.IP "\(bu" 2

.IP "\(bu" 2

.IP "\(bu" 2

.PP
.SH "Related Decisions"
.PP
.IP "\(bu" 2
[](\fBdoc_decisions_0_drafts__README_md\fP)
.IP "\(bu" 2
[](\fBdoc_decisions_0_drafts__README_md\fP)
.IP "\(bu" 2
[](\fBdoc_decisions_0_drafts__README_md\fP)
.PP
.SH "Notes"
.PP
.IP "\(bu" 2
\fCIssue 2202\fP talks about how unexpected it is that keys will be readonly once in a keyset, but they don't get unlocked when removing them from a keyset\&. 
.PP

