From 02c770d9971f3c1ff1bd7ce88a2a1f6388572583 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 30 Oct 2021 11:02:24 -0700 Subject: [PATCH] core: use fingerprint table and on disk fingerprints In order to not break existing behavior, we still store fingerprints on disk, but we first check the data in the in-memory table, and we remember the fingerprint data in the fingerprint table as well (which is then saved as part of the dive log data). Signed-off-by: Dirk Hohndel --- core/libdivecomputer.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 3c1024678..bcb88440a 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -967,10 +967,20 @@ static void lookup_fingerprint(dc_device_t *device, device_data_t *devdata) { char *cachename; struct memblock mem; + const unsigned char *raw_data; if (devdata->force_download) return; + /* first try our in memory data - raw_data is owned by the table, the dc_device_set_fingerprint function copies the data */ + int fsize = get_fingerprint_data(&fingerprint_table, calculate_string_hash(devdata->model), devdata->devinfo.serial, &raw_data); + if (fsize) { + if (verbose) + dev_info(devdata, "... found fingerprint in dive table"); + dc_device_set_fingerprint(device, raw_data, fsize); + return; + } + /* now check if we have a fingerprint on disk */ cachename = fingerprint_file(devdata); if (verbose) dev_info(devdata, "Looking for fingerprint in '%s'", cachename); @@ -1447,8 +1457,15 @@ const char *do_libdivecomputer_import(device_data_t *data) * we got a dive header, and because we will use the * dive id to verify that we actually have the dive * it refers to before we use the fingerprint data. + * + * For now we save the fingerprint both to the local file system + * and to the global fingerprint table (to be then saved out with + * the dive log data). */ save_fingerprint(data); + if (data->fingerprint && data->fdiveid) + create_fingerprint_node(&fingerprint_table, calculate_string_hash(data->model), data->devinfo.serial, + data->fingerprint, data->fsize, data->fdeviceid, data->fdiveid); free(data->fingerprint); data->fingerprint = NULL;