aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@inria.fr>2026-07-12 08:13:00 +0200
committerTristan Riehs <tristan.riehs@inria.fr>2026-07-12 08:13:00 +0200
commit0037bc1acf7439f078aeaa3cd48d8a54454f78fc (patch)
tree13474eb19cc23b26dd022858689c97e0bec2b13b
parentccf00ee32c88f7bf03deabe22ee6f60ae51701b8 (diff)
Rework entry existence check
Make the callback more generic to use it several times.
-rw-r--r--src/main.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index 22adee8..b39d9c2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -963,17 +963,19 @@ static void ftag_sync(int argc, char **argv)
parse_args(argc - 1, argv + 1, sync_commands, sync_command_count);
}
-/* Check that the tag we are trying to create does not exist yet. If this
- * callback is ever called, then it already exist, this is a fatal error. */
-static int ftag_tag_check(void *, int, char **cols, char **)
+/* Check whether the entry we are querying exists or not. _SHALL_EXIST is a
+ * boolean indicating whether it is supposed to exist or not. If this callback
+ * is ever called, then the entry exists. */
+static int
+ftag_tag_shall_exist_callback(void *_shall_exist, int, char **cols, char **)
{
+ int shall_exist = (intptr_t)_shall_exist;
assert(cols[0]);
- assert(cols[1]);
- fprintf(stderr,
- "ftag tag add: error: tag \"%s\" already exists, "
- "its description is:\n%s\n",
- cols[0], cols[1]);
- return 1;
+ if (!shall_exist) {
+ fprintf(stderr,
+ "ftag: error: entry \"%s\" already exists", cols[0]);
+ }
+ return !shall_exist;
}
static void ftag_tag_add(int argc, char **argv)
@@ -994,7 +996,8 @@ static void ftag_tag_add(int argc, char **argv)
strbuild(sql, "SELECT name, description FROM tags WHERE name = '%s';",
new_tag_name);
- rc = sqlite3_exec(db, sql, ftag_tag_check, NULL, NULL);
+ rc = sqlite3_exec(db, sql,
+ ftag_tag_shall_exist_callback, (intptr_t)0, NULL);
sqlite3_check(rc, db);
int next_id = table_next_id(db, "tags");