aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@inria.fr>2025-12-29 13:11:25 +0100
committerTristan Riehs <tristan.riehs@inria.fr>2025-12-29 13:11:25 +0100
commite006d349171eafaed80ca6202f3ae9f0ad999ea1 (patch)
tree10280fc0341501c74e478d7c8df05a179072f403
parent8afdb2d8afced8c5ec1ee49472f731dd3eab0bda (diff)
Handle file extension when adding to database
-rw-r--r--src/main.c20
1 files 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)++;