Skip to content

Commit 9a4952a

Browse files
committed
dbhub: Redownload database if local copy has been deleted
See issue #1111.
1 parent ccccef9 commit 9a4952a

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

‎src/RemoteDatabase.cpp‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,32 @@ QString RemoteDatabase::localExists(const QUrl& url, QString identity)
634634
// is newer, or the local commit id is newer.
635635
if(local_commit_id == url_commit_id)
636636
{
637-
// Both commit ids are the same. That's the perfect match, so just return the path to the local file
638-
return Settings::getValue("remote", "clonedirectory").toString() + "/" + local_file;
637+
// Both commit ids are the same. That's the perfect match, so we can build the full path to where the file should be
638+
QString full_path = Settings::getValue("remote", "clonedirectory").toString() + "/" + local_file;
639+
640+
// Check if the database still exists. If so return its path, if not return an empty string to redownload it
641+
if(QFile::exists(full_path))
642+
{
643+
return full_path;
644+
} else {
645+
// Remove the apparently invalid entry from the local clones database to avoid future lookups and confusions. The file column
646+
// should be unique for the entire table because the files are all in the same directory and their names need to be unique because
647+
// of this.
648+
QString sql = QString("DELETE FROM local WHERE file=?");
649+
sqlite3_stmt* stmt;
650+
if(sqlite3_prepare_v2(m_dbLocal, sql.toUtf8(), -1, &stmt, 0) != SQLITE_OK)
651+
return QString();
652+
if(sqlite3_bind_text(stmt, 1, local_file.toUtf8(), local_file.toUtf8().length(), SQLITE_TRANSIENT))
653+
{
654+
sqlite3_finalize(stmt);
655+
return QString();
656+
}
657+
sqlite3_step(stmt);
658+
sqlite3_finalize(stmt);
659+
660+
// Return empty string to indicate a redownload request
661+
return QString();
662+
}
639663
} else {
640664
// In all the other cases just treat the remote database as a completely new database for now.
641665

0 commit comments

Comments
 (0)