Cloud storage: fix potential crash when avoiding reloading dive list

If we loaded the dive list from cache and then try to figure out if the remote
repository had anything different, we were being super stupid if the SHA was
identical... we had already cleared the dive list by the time we decided that
we didn't need to load things. Granted, the model was still populated (oops),
but the backend data structure was cleared and accesses to it (e.g., when
drawing the profile) would cause things to crash.

The helper function duplicates some code, but trying to not duplicate the code
made things even harder to read.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-01-04 17:48:34 -08:00
parent 72ce77a5ee
commit 3bfa8de2f7
3 changed files with 32 additions and 7 deletions

View file

@ -432,6 +432,33 @@ static int parse_file_buffer(const char *filename, struct memblock *mem)
return parse_xml_buffer(filename, mem->buffer, mem->size, &dive_table, NULL);
}
int check_git_sha(const char *filename)
{
struct git_repository *git;
const char *branch = NULL;
git = is_git_repository(filename, &branch, NULL, false);
if (prefs.cloud_git_url &&
strstr(filename, prefs.cloud_git_url)
&& git == dummy_git_repository)
/* opening the cloud storage repository failed for some reason,
* so we don't know if there is additional data in the remote */
return 1;
/* if this is a git repository, do we already have this exact state loaded ?
* get the SHA and compare with what we currently have */
if (git && git != dummy_git_repository) {
const char *sha = get_sha(git, branch);
if (!same_string(sha, "") &&
same_string(sha, saved_git_id) &&
!unsaved_changes()) {
fprintf(stderr, "already have loaded SHA %s - don't load again\n", sha);
return 0;
}
}
return 1;
}
int parse_file(const char *filename)
{
struct git_repository *git;