Skip to content

Commit

Permalink
dbhub: Send last known commit id along with the database when pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
MKleusberg committed Sep 30, 2017
1 parent 8a540a2 commit fef884a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/RemoteDatabase.cpp
Expand Up @@ -444,6 +444,7 @@ void RemoteDatabase::push(const QString& filename, const QString& url, const QSt
addPart(multipart, "licence", licence); addPart(multipart, "licence", licence);
addPart(multipart, "public", isPublic ? "true" : "false"); addPart(multipart, "public", isPublic ? "true" : "false");
addPart(multipart, "branch", branch); addPart(multipart, "branch", branch);
addPart(multipart, "commit", localLastCommitId(filename));


// Set SSL configuration when trying to access a file via the HTTPS protocol // Set SSL configuration when trying to access a file via the HTTPS protocol
bool https = QUrl(url).scheme().compare("https", Qt::CaseInsensitive) == 0; bool https = QUrl(url).scheme().compare("https", Qt::CaseInsensitive) == 0;
Expand Down Expand Up @@ -699,6 +700,8 @@ QString RemoteDatabase::localCheckFile(const QString& local_file)
// This function takes the file name of a locally cloned database and checks if this file still exists. If it has been deleted in the meantime it returns // This function takes the file name of a locally cloned database and checks if this file still exists. If it has been deleted in the meantime it returns
// an empty string and deletes the file from the clone database. If the file still exists, it returns the full path to the file. // an empty string and deletes the file from the clone database. If the file still exists, it returns the full path to the file.


localAssureOpened();

// Build the full path to where the file should be // Build the full path to where the file should be
QString full_path = Settings::getValue("remote", "clonedirectory").toString() + "/" + local_file; QString full_path = Settings::getValue("remote", "clonedirectory").toString() + "/" + local_file;


Expand Down Expand Up @@ -726,6 +729,40 @@ QString RemoteDatabase::localCheckFile(const QString& local_file)
} }
} }


QString RemoteDatabase::localLastCommitId(QString filename)
{
// This function takes a file name and checks with which commit id we had checked out this file or last pushed it.

localAssureOpened();

// Query commit id for that file name
QString sql = QString("SELECT commit_id FROM local WHERE file=?");
sqlite3_stmt* stmt;
if(sqlite3_prepare_v2(m_dbLocal, sql.toUtf8(), -1, &stmt, NULL) != SQLITE_OK)
return QString();

QFileInfo f(filename); // Remove the path
filename = f.fileName();
if(sqlite3_bind_text(stmt, 1, filename.toUtf8(), filename.toUtf8().length(), SQLITE_TRANSIENT))
{
sqlite3_finalize(stmt);
return QString();
}

if(sqlite3_step(stmt) != SQLITE_ROW)
{
// If there was either an error or no record was found for this file name, stop here.
sqlite3_finalize(stmt);
return QString();
}

// Having come here we can assume that at least some local clone with the given file name
QString local_commit_id = QString::fromUtf8(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
sqlite3_finalize(stmt);

return local_commit_id;
}

void RemoteDatabase::clearAccessCache(const QString& clientCert) void RemoteDatabase::clearAccessCache(const QString& clientCert)
{ {
// When the client certificate is different from the one before, clear the access and authentication cache. // When the client certificate is different from the one before, clear the access and authentication cache.
Expand Down
1 change: 1 addition & 0 deletions src/RemoteDatabase.h
Expand Up @@ -76,6 +76,7 @@ class RemoteDatabase : public QObject
void localAdd(QString filename, QString identity, const QUrl& url); void localAdd(QString filename, QString identity, const QUrl& url);
QString localExists(const QUrl& url, QString identity); QString localExists(const QUrl& url, QString identity);
QString localCheckFile(const QString& local_file); QString localCheckFile(const QString& local_file);
QString localLastCommitId(QString filename);


// Helper functions for building multi-part HTTP requests // Helper functions for building multi-part HTTP requests
void addPart(QHttpMultiPart* multipart, const QString& name, const QString& value); void addPart(QHttpMultiPart* multipart, const QString& name, const QString& value);
Expand Down

0 comments on commit fef884a

Please sign in to comment.