Don't save unused, auto-create dive sites

Normally the auto-created sites that are used when downloading GPS data
from the webservice that aren't associated with a dive will immediately
discarded. But if such a site is used for a dive but then the user changes
their mind and uses another site for that dive (for example because they
had a previous dive at that spot and decided they liked that one better
after all), then the dive site can stick around as an orphan.

Having orphan dive site may make sense for named dive sites that for some
reason are no longer used but may be used again in the future, but having
an auto-named orphaned dive site in the data file seems silly. So let's
remove them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-09-28 22:30:20 -04:00
parent 55cc0ee9c1
commit 7ad1485c39
2 changed files with 29 additions and 2 deletions

View file

@ -892,9 +892,23 @@ static void save_divesites(git_repository *repo, struct dir *tree)
if (d->dive_site_uuid == ds->uuid)
d->dive_site_uuid = 0;
}
delete_dive_site(get_dive_site(i)->uuid);
delete_dive_site(ds->uuid);
i--; // since we just deleted that one
continue;
} else if (ds->name &&
(strncmp(ds->name, "Auto-created dive", 17) == 0 ||
strncmp(ds->name, "New Dive", 8) == 0)) {
fprintf(stderr, "found an auto divesite %s\n", ds->name);
// these are the two default names for sites from
// the web service; if the site isn't used in any
// dive (really? you didn't rename it?), delete it
if (!is_dive_site_used(ds->uuid, false)) {
if (verbose)
fprintf(stderr, "Deleted unused auto-created dive site %s\n", ds->name);
delete_dive_site(ds->uuid);
i--; // since we just deleted that one
continue;
}
}
struct membuffer site_file_name = { 0 };
put_format(&site_file_name, "Site-%08x", ds->uuid);

View file

@ -523,9 +523,22 @@ void save_dives_buffer(struct membuffer *b, const bool select_only)
if (d->dive_site_uuid == ds->uuid)
d->dive_site_uuid = 0;
}
delete_dive_site(get_dive_site(i)->uuid);
delete_dive_site(ds->uuid);
i--; // since we just deleted that one
continue;
} else if (ds->name &&
(strncmp(ds->name, "Auto-created dive", 17) == 0 ||
strncmp(ds->name, "New Dive", 8) == 0)) {
// these are the two default names for sites from
// the web service; if the site isn't used in any
// dive (really? you didn't rename it?), delete it
if (!is_dive_site_used(ds->uuid, false)) {
if (verbose)
fprintf(stderr, "Deleted unused auto-created dive site %s\n", ds->name);
delete_dive_site(ds->uuid);
i--; // since we just deleted that one
continue;
}
}
if (select_only && !is_dive_site_used(ds->uuid, true))
continue;