summaryrefslogtreecommitdiffstats
path: root/libdivecomputer.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-12-28 14:12:10 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-28 14:16:29 -0800
commit020154215dd4de641a18c311f2844aea91bf2e88 (patch)
tree22393490a5fdc7e822529bc11a6cb996fb1c3752 /libdivecomputer.c
parent3b136f23ee4f3ddee1c157dfee2ff84fe6fa130e (diff)
downloadsubsurface-020154215dd4de641a18c311f2844aea91bf2e88.tar.gz
Don't match existing dives by date if the dive computers are known to be different
When downloading from a dive computer, we fall back on matching the exact date of the dive if we can't tell whether we already have that exact dive computer data some other way. However, if you have multiple dive computers and they are sufficiently well synchronized, they might actually have the exact same date, despite the fact that we do want to download both dive computers. We do check the dive start to the exact second, so this sounds unlikely, but with dive computers rounding time to the next minute etc, it's not as unlikely as you'd think. Dirk hit it. So when we match against date, do check that the dive computer might actually be one we've already downloaded from. If we have full model information, we can dismiss the "match date" logic. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'libdivecomputer.c')
-rw-r--r--libdivecomputer.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c
index 4a095f48c..de6a84feb 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -296,6 +296,17 @@ static int parse_samples(device_data_t *devdata, struct divecomputer *dc, dc_par
return dc_parser_samples_foreach(parser, sample_cb, dc);
}
+static int might_be_same_dc(struct divecomputer *a, struct divecomputer *b)
+{
+ if (!a->model || !b->model)
+ return 1;
+ if (strcasecmp(a->model, b->model))
+ return 0;
+ if (!a->deviceid || !b->deviceid)
+ return 1;
+ return a->deviceid == b->deviceid;
+}
+
static int match_one_dive(struct divecomputer *a, struct dive *dive)
{
struct divecomputer *b = &dive->dc;
@@ -316,7 +327,7 @@ static int match_one_dive(struct divecomputer *a, struct dive *dive)
/* Ok, no exact dive computer match. Does the date match? */
b = &dive->dc;
do {
- if (a->when == b->when)
+ if (a->when == b->when && might_be_same_dc(a, b))
return 1;
b = b->next;
} while (b);