From e006d349171eafaed80ca6202f3ae9f0ad999ea1 Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Mon, 29 Dec 2025 13:11:25 +0100 Subject: Handle file extension when adding to database --- src/main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 42b4173..667a79f 100644 --- a/src/main.c +++ b/src/main.c @@ -447,10 +447,26 @@ ftag_add_one_file(sqlite3 *db, int *next_id, const char *file, uint32_t file_sum date = time_from_str(date_str); } + char extension[16]; + /* Find the position of the last dot character in file name. If found, + * everything that follows is considered as the extension. */ + int i = strlen(file) - 1; + while ((i >= 1) && (file[i] != '.')) + i--; + if ((i >= 1) && (i < strlen(file))) { + assert(strlen(file + i + 1) < 16); + strcpy(extension, file + i + 1); + } + else { + extension[0] = '\0'; + } + memset(sql, 0, sizeof(sql)); snprintf(sql, sizeof(sql)-1, - "INSERT INTO files VALUES(%d, '%s', '%s', '%s', %ld, %u)", - *next_id, canonical_name, full_name, description, date, file_sum); + "INSERT INTO files VALUES(%d, '%s', '%s', '%s', " + "%ld, %u, '%s')", + *next_id, canonical_name, full_name, description, + date, file_sum, extension); rc = sqlite3_exec(db, sql, NULL, NULL, NULL); sqlite3_check(rc, db); (*next_id)++; -- cgit v1.2.3