From 3bfa8de2f7022370f6ab497a378be51018b49f35 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 4 Jan 2016 17:48:34 -0800 Subject: 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 --- qt-mobile/qmlmanager.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'qt-mobile') diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index aebc65f92..90293e8bf 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -267,18 +267,16 @@ void QMLManager::loadDivesWithValidCredentials() setStartPageText(tr("Cloud storage error: %1").arg(errorString)); return; } - clear_dive_file_data(); - QByteArray fileNamePrt = QFile::encodeName(url); - QString savedSHA(saved_git_id); - int error = parse_file(fileNamePrt.data()); - if (savedSHA == saved_git_id) { + if (check_git_sha(fileNamePrt.data()) == 0) { qDebug() << "local cache was current, no need to modify dive list"; appendTextToLog("Cloud sync shows local cache was current"); return; } - qDebug() << "had" << savedSHA << "got" << saved_git_id << ", so let's reload"; + clear_dive_file_data(); + DiveListModel::instance()->clear(); + int error = parse_file(fileNamePrt.data()); if (!error) { report_error("filename is now %s", fileNamePrt.data()); const char *error_string = get_error_string(); @@ -296,7 +294,6 @@ void QMLManager::loadDivesWithValidCredentials() int i; struct dive *d; - DiveListModel::instance()->clear(); for_each_dive(i, d) { DiveListModel::instance()->addDive(d); } -- cgit v1.2.3-70-g09d2