From 69eec2b602f56e5399e752beaec5cb57b8d2370a Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Wed, 12 Aug 2020 20:26:50 +0200 Subject: [PATCH] dbhub: Redownload database when checking out current commit When double clicking the currently checked out commit in the commits list in the Remote dock only open the local file if it has not been modified. If it was modified show a warning about the modifications and redownload the file if the user decides to proceed. See issue #2349. --- src/RemoteDock.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/RemoteDock.cpp b/src/RemoteDock.cpp index 95367de4..a2b1a15f 100644 --- a/src/RemoteDock.cpp +++ b/src/RemoteDock.cpp @@ -242,15 +242,25 @@ void RemoteDock::fetchDatabase(QString url_string, RemoteNetwork::RequestType re return; } + // For the user name, take the path, remove the database name and the initial slash + QString username = url.path().remove("/" + url.fileName()).mid(1); // There is a chance that we've already cloned that database. So check for that first QString exists = remoteDatabase.localExists(url, remoteModel->currentClientCertificate(), QUrlQuery(url).queryItemValue("branch").toStdString()); if(!exists.isEmpty() && request_type == RemoteNetwork::RequestTypeDatabase) { + // Check for modifications + bool modified = isLocalDatabaseModified(exists, username, url.fileName(), remoteModel->currentClientCertificate(), + QUrlQuery(url).queryItemValue("commit").toStdString()); + // Database has already been cloned! So open the local file instead of fetching the one from the - // server again. - emit openFile(exists); - return; + // server again. If the local file has been modified don't open it but try to download the last known + // commit again. + if(!modified) + { + emit openFile(exists); + return; + } } // Check if we already have a clone of this database branch and, if so, figure out its local file name. @@ -265,9 +275,6 @@ void RemoteDock::fetchDatabase(QString url_string, RemoteNetwork::RequestType re { // If there is a local clone of this dtabase and branch, figure out if the local file has been modified - // For the user name, take the path, remove the database name and the initial slash - QString username = url.path().remove("/" + url.fileName()).mid(1); - // Get the last local commit id std::string last_commit_id = remoteDatabase.localLastCommitId(remoteModel->currentClientCertificate(), url, QUrlQuery(url).queryItemValue("branch").toStdString());