mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
3b136f23ee
commit
020154215d
1 changed files with 12 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue