Dive sites: don't delete unused dive sites on save

Unused dive sites were deleted on save. This clashed with the undo
system in the following scenario:

1) Delete single-use dive site.
2) Save (dive site deleted)
3) Undo (reference to freed dive site)

Therefore, as a quick-fix, keep the referenced dive site around.
Note that this also means that empty dive sites must not be
deleted, as it might refer to a dive in the undo system. Instead
only clear references to empty dive sites in the global dive
table. Factor this functionality out, as it was common to the
XML and git savers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-01-01 11:45:26 +02:00 committed by Dirk Hohndel
parent da52440963
commit 4d06ddd723
4 changed files with 24 additions and 16 deletions

View file

@ -346,6 +346,23 @@ struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp
return create_dive_site(name, divetime);
}
void purge_empty_dive_sites()
{
int i, j;
struct dive *d;
struct dive_site *ds;
for (i = 0; i < dive_site_table.nr; i++) {
ds = get_dive_site(i);
if (!dive_site_is_empty(ds))
continue;
for_each_dive(j, d) {
if (d->dive_site == ds)
d->dive_site = NULL;
}
}
}
static int compare_sites(const void *_a, const void *_b)
{
const struct dive_site *a = (const struct dive_site *)*(void **)_a;