diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-03-03 18:39:12 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | 31291b1c56bf418732cf6ef52550aada492eff9b (patch) | |
tree | 4ff9e70839ced99fab1d13b7a38d43ece8171f4f /core/divesite.c | |
parent | ac1602f5125caae322e3e819a7c622b0be9feca1 (diff) | |
download | subsurface-31291b1c56bf418732cf6ef52550aada492eff9b.tar.gz |
Dive site: set UUID only on save or load
Since the UUID will be overwritten on save and is only used on save
and load, set it only on save or load. For other created dive sites,
leave the UUID field uninitialized.
This means that the UUID will change between saves. Let's see how
the git saver handles that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divesite.c')
-rw-r--r-- | core/divesite.c | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/core/divesite.c b/core/divesite.c index 884ac9a7d..a71780faf 100644 --- a/core/divesite.c +++ b/core/divesite.c @@ -143,7 +143,7 @@ struct dive_site *alloc_dive_site() return ds; } -/* we never allow a second dive site with the same uuid */ +/* when parsing, dive sites are identified by uuid */ struct dive_site *alloc_or_get_dive_site(uint32_t uuid, struct dive_site_table *ds_table) { struct dive_site *ds; @@ -229,44 +229,27 @@ void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table) free_dive_site(ds); } -static uint32_t create_divesite_uuid(const char *name, timestamp_t divetime) -{ - if (name == NULL) - name =""; - union { - unsigned char hash[20]; - uint32_t i; - } u; - SHA_CTX ctx; - SHA1_Init(&ctx); - SHA1_Update(&ctx, &divetime, sizeof(timestamp_t)); - SHA1_Update(&ctx, name, strlen(name)); - SHA1_Final(u.hash, &ctx); - // now return the first 32 of the 160 bit hash - return u.i; -} - /* allocate a new site and add it to the table */ -struct dive_site *create_dive_site(const char *name, timestamp_t divetime, struct dive_site_table *ds_table) +struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table) { - uint32_t uuid = create_divesite_uuid(name, divetime); - struct dive_site *ds = alloc_or_get_dive_site(uuid, ds_table); + struct dive_site *ds = alloc_dive_site(); ds->name = copy_string(name); + add_dive_site_to_table(ds, ds_table); return ds; } /* same as before, but with GPS data */ -struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, timestamp_t divetime, struct dive_site_table *ds_table) +struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, struct dive_site_table *ds_table) { - uint32_t uuid = create_divesite_uuid(name, divetime); - struct dive_site *ds = alloc_or_get_dive_site(uuid, ds_table); + struct dive_site *ds = alloc_dive_site(); ds->name = copy_string(name); ds->location = *loc; + add_dive_site_to_table(ds, ds_table); return ds; } -/* a uuid is always present - but if all the other fields are empty, the dive site is pointless */ +/* if all fields are empty, the dive site is pointless */ bool dive_site_is_empty(struct dive_site *ds) { return !ds || @@ -286,7 +269,6 @@ void copy_dive_site(struct dive_site *orig, struct dive_site *copy) copy->name = copy_string(orig->name); copy->notes = copy_string(orig->notes); copy->description = copy_string(orig->description); - copy->uuid = orig->uuid; copy_taxonomy(&orig->taxonomy, ©->taxonomy); } @@ -370,7 +352,7 @@ void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int mark_divelist_changed(true); } -struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime, struct dive_site_table *ds_table) +struct dive_site *find_or_create_dive_site_with_name(const char *name, struct dive_site_table *ds_table) { int i; struct dive_site *ds; @@ -380,7 +362,7 @@ struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp } if (ds) return ds; - return create_dive_site(name, divetime, ds_table); + return create_dive_site(name, ds_table); } void purge_empty_dive_sites(struct dive_site_table *ds_table) |