<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18361">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">db: Notify user if deleted DB entry didn't exist.<br><br>Currently, if using the CLI to delete a DB entry,<br>"Database entry removed" is always returned,<br>regardless of whether or not the entry actually<br>existed in the first place. This meant that users<br>were never told if entries did not exist.<br><br>The same issue occurs if trying to delete a DB key<br>using AMI.<br><br>This fixes this issue by first attempting to retrieve<br>the entry to be deleted, so we can inform the user<br>if it does not exist.<br><br>ASTERISK-30001 #close<br><br>Change-Id: Ic84e3eddcd66c7a6ed7fea91cdfd402568378b18<br>---<br>M main/db.c<br>1 file changed, 16 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/61/18361/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/db.c b/main/db.c</span><br><span>index d4479f4..54834b0 100644</span><br><span>--- a/main/db.c</span><br><span>+++ b/main/db.c</span><br><span>@@ -663,6 +663,7 @@</span><br><span> static char *handle_cli_database_del(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span> {</span><br><span> int res;</span><br><span style="color: hsl(120, 100%, 40%);">+ char buf[1];</span><br><span> </span><br><span> switch (cmd) {</span><br><span> case CLI_INIT:</span><br><span>@@ -678,9 +679,16 @@</span><br><span> </span><br><span> if (a->argc != 4)</span><br><span> return CLI_SHOWUSAGE;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* ast_db_del doesn't care if something didn't exist, so check first */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_db_get(a->argv[2], a->argv[3], buf, 1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Database entry does not exist.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> res = ast_db_del(a->argv[2], a->argv[3]);</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_cli(a->fd, "Database entry does not exist.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Database error occured.\n");</span><br><span> } else {</span><br><span> ast_cli(a->fd, "Database entry removed.\n");</span><br><span> }</span><br><span>@@ -952,6 +960,7 @@</span><br><span> const char *family = astman_get_header(m, "Family");</span><br><span> const char *key = astman_get_header(m, "Key");</span><br><span> int res;</span><br><span style="color: hsl(120, 100%, 40%);">+ char buf[1];</span><br><span> </span><br><span> if (ast_strlen_zero(family)) {</span><br><span> astman_send_error(s, m, "No family specified.");</span><br><span>@@ -963,9 +972,14 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_db_get(family, key, buf, 1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_send_error(s, m, "Database entry not found");</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> res = ast_db_del(family, key);</span><br><span> if (res)</span><br><span style="color: hsl(0, 100%, 40%);">- astman_send_error(s, m, "Database entry not found");</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_send_error(s, m, "Database error occured");</span><br><span> else</span><br><span> astman_send_ack(s, m, "Key deleted successfully");</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18361">change 18361</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/18361"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ic84e3eddcd66c7a6ed7fea91cdfd402568378b18 </div>
<div style="display:none"> Gerrit-Change-Number: 18361 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>