[Pkg-owncloud-commits] [owncloud-client] 61/211: Use sqlite C api.

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Oct 25 09:10:26 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit d08c2de6192e93d25c4f2df3a3dd1fe25dec2bef
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Mon Oct 13 14:14:43 2014 +0200

    Use sqlite C api.
---
 src/mirall/socketapi.cpp     | 65 +++++++++++++++++++++++++++++++++++++++++---
 src/mirall/syncjournaldb.cpp |  9 +++++-
 src/mirall/syncjournaldb.h   |  6 ++--
 3 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/src/mirall/socketapi.cpp b/src/mirall/socketapi.cpp
index a454c7a..e7bec61 100644
--- a/src/mirall/socketapi.cpp
+++ b/src/mirall/socketapi.cpp
@@ -35,6 +35,9 @@
 #include <QApplication>
 #include <QLocalSocket>
 
+#include <sqlite3.h>
+
+
 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
 #include <QStandardPaths>
 #endif
@@ -112,12 +115,66 @@ SyncFileStatus recursiveFolderStatus(Folder *folder, const QString& fileName, c_
     return result;
 }
 
-SyncJournalFileRecord dbFileRecord( Folder *folder, QString fileName )
+SyncJournalFileRecord dbFileRecord_capi( Folder *folder, QString fileName )
 {
+
+    // FIXME: Check if this stat is really needed, or is it done in the caller?
+    if( !folder ) {
+        return SyncJournalFileRecord();
+    }
+
     QFileInfo fi(fileName);
+    if( fi.isAbsolute() ) {
+        fileName.remove(0, folder->path().length());
+    }
+
+    QString dbFileName = SyncJournalDb::databaseFilePath();
+
+    sqlite3 *db = NULL;
+    sqlite3_stmt *stmt = NULL;
+    SyncJournalFileRecord rec;
+    int rc;
+    const char* query = "SELECT inode, mode, modtime, type, md5, fileid, remotePerm FROM "
+            "metadata WHERE phash=:ph";
+
+    if( sqlite3_open_v2(dbFileName.toUtf8().constData(), &db,
+                        SQLITE_OPEN_READONLY+SQLITE_OPEN_NOMUTEX, NULL) == SQLITE_OK ) {
+
+        rc = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+        if( rc != SQLITE_OK ) {
+            qDebug() << "Unable to prepare the query statement.";
+            return rec;
+        }
+        qlonglong phash = SyncJournalDb::getPHash( fileName );
+        sqlite3_bind_int64(stmt, 1, (long long signed int)phash);
+
+        // int column_count = sqlite3_column_count(stmt);
+
+        rc = sqlite3_step(stmt);
+
+        if (rc == SQLITE_ROW ) {
+            rec._path   = fileName;
+            rec._inode  = sqlite3_column_int64(stmt,0);;
+            rec._mode = sqlite3_column_int(stmt, 1);
+            rec._modtime = Utility::qDateTimeFromTime_t( strtoul((char*)sqlite3_column_text(stmt, 2), NULL, 10));
+            rec._type = sqlite3_column_int(stmt, 3);;
+            rec._etag = QByteArray((char*)sqlite3_column_text(stmt, 4));
+            rec._fileId = QByteArray((char*)sqlite3_column_text(stmt, 5));
+            rec._remotePerm = QByteArray((char*)sqlite3_column_text(stmt, 6));
+        }
+        sqlite3_finalize(stmt);
+        sqlite3_close(db);
+    }
+    return rec;
+}
+
+SyncJournalFileRecord dbFileRecord( Folder *folder, QString fileName )
+{
     if( !folder ) {
         return SyncJournalFileRecord();
     }
+
+    QFileInfo fi(fileName);
     if( fi.isAbsolute() ) {
         fileName.remove(0, folder->path().length());
     }
@@ -169,18 +226,18 @@ SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName, c_strli
 
     // Problem: for the sync dir itself we do not have a record in the sync journal
     // so the next check must not be used for the sync root folder.
-    SyncJournalFileRecord rec = dbFileRecord(folder, unixFileName );
+    SyncJournalFileRecord rec = dbFileRecord_capi(folder, unixFileName );
     if( !isSyncRootFolder && !rec.isValid() ) {
         // check the parent folder if it is shared and if it is allowed to create a file/dir within
         QDir d( fi.path() );
         QString parentPath = d.path();
-        SyncJournalFileRecord dirRec = dbFileRecord(folder, parentPath);
+        SyncJournalFileRecord dirRec = dbFileRecord_capi(folder, parentPath);
         while( !d.isRoot() && !(d.exists() && dirRec.isValid()) ) {
             d.cdUp(); // returns true if the dir exists.
 
             parentPath = d.path();
             // cut the folder path
-            dirRec = dbFileRecord(folder, parentPath);
+            dirRec = dbFileRecord_capi(folder, parentPath);
         }
         if( dirRec.isValid() ) {
             if( dirRec._type == CSYNC_FTW_TYPE_DIR ) {
diff --git a/src/mirall/syncjournaldb.cpp b/src/mirall/syncjournaldb.cpp
index 66977d7..c33c1af 100644
--- a/src/mirall/syncjournaldb.cpp
+++ b/src/mirall/syncjournaldb.cpp
@@ -30,6 +30,8 @@
 
 namespace Mirall {
 
+QString SyncJournalDb::_dbFile;
+
 SyncJournalDb::SyncJournalDb(const QString& path, QObject *parent) :
     QObject(parent), _transaction(0), _possibleUpgradeFromMirall_1_5(false)
 {
@@ -49,6 +51,11 @@ bool SyncJournalDb::exists()
     return (!_dbFile.isEmpty() && QFile::exists(_dbFile));
 }
 
+QString SyncJournalDb::databaseFilePath()
+{
+    return _dbFile;
+}
+
 void SyncJournalDb::startTransaction()
 {
     if( _transaction == 0 ) {
@@ -405,7 +412,7 @@ QStringList SyncJournalDb::tableColumns( const QString& table )
     return columns;
 }
 
-qint64 SyncJournalDb::getPHash(const QString& file) const
+qint64 SyncJournalDb::getPHash(const QString& file)
 {
     QByteArray utf8File = file.toUtf8();
     int64_t h;
diff --git a/src/mirall/syncjournaldb.h b/src/mirall/syncjournaldb.h
index 2660ec7..a4cab96 100644
--- a/src/mirall/syncjournaldb.h
+++ b/src/mirall/syncjournaldb.h
@@ -44,6 +44,9 @@ public:
     int getFileRecordCount();
     bool exists();
 
+    static QString databaseFilePath();
+    static qint64 getPHash(const QString& );
+
     void updateBlacklistEntry( const SyncJournalBlacklistRecord& item );
     void wipeBlacklistEntry(const QString& file);
     int wipeBlacklist();
@@ -106,7 +109,6 @@ public:
     bool isUpdateFrom_1_5();
 
 private:
-    qint64 getPHash(const QString& ) const;
     bool updateDatabaseStructure();
     bool sqlFail(const QString& log, const QSqlQuery &query );
     void commitInternal(const QString &context, bool startTrans = true);
@@ -116,7 +118,7 @@ private:
     bool checkConnect();
 
     QSqlDatabase _db;
-    QString _dbFile;
+    static QString _dbFile;
     QMutex _mutex; // Public functions are protected with the mutex.
     int _transaction;
     bool _possibleUpgradeFromMirall_1_5;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list