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>
This commit is contained in:
Linus Torvalds 2012-12-28 14:12:10 -08:00 committed by Dirk Hohndel
parent 3b136f23ee
commit 020154215d

View file

@ -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); 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) static int match_one_dive(struct divecomputer *a, struct dive *dive)
{ {
struct divecomputer *b = &dive->dc; 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? */ /* Ok, no exact dive computer match. Does the date match? */
b = &dive->dc; b = &dive->dc;
do { do {
if (a->when == b->when) if (a->when == b->when && might_be_same_dc(a, b))
return 1; return 1;
b = b->next; b = b->next;
} while (b); } while (b);