[Pkg-owncloud-commits] [owncloud-client] 72/211: Merge branch 'sqlite_capi' of github.com:owncloud/mirall into sqlite_capi
Sandro Knauß
hefee-guest at moszumanska.debian.org
Sat Oct 25 09:10:28 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 e7d9ec50dc65fb35dc5819301e6c867f147803d6
Merge: 09b0ba3 eb60aca
Author: Klaas Freitag <freitag at owncloud.com>
Date: Tue Oct 14 11:43:10 2014 +0200
Merge branch 'sqlite_capi' of github.com:owncloud/mirall into sqlite_capi
Conflicts:
src/mirall/socketapi.cpp
src/mirall/folder.cpp | 94 ++++++++++++++++++++++++++
src/mirall/folder.h | 16 +++--
src/mirall/folderman.cpp | 21 ++++--
src/mirall/folderwatcher.cpp | 2 +-
src/mirall/socketapi.cpp | 155 ++++++++++++++++---------------------------
src/mirall/syncengine.cpp | 14 +++-
src/mirall/syncengine.h | 7 ++
src/mirall/syncfileitem.h | 7 ++
src/mirall/syncjournaldb.cpp | 2 +-
src/mirall/utility.cpp | 12 ++++
src/mirall/utility.h | 4 ++
11 files changed, 223 insertions(+), 111 deletions(-)
diff --cc src/mirall/socketapi.cpp
index 3a9fbd8,231dc24..598665c
--- a/src/mirall/socketapi.cpp
+++ b/src/mirall/socketapi.cpp
@@@ -367,222 -527,6 +370,178 @@@ void SocketApi::command_VERSION(const Q
sendMessage(socket, QLatin1String("VERSION:" MIRALL_VERSION_STRING ":" MIRALL_SOCKET_API_VERSION));
}
-
- /**
- * @brief recursiveFolderStatus
- * @param fileName - the relative file name to examine
- * @return the resulting status
- *
- * The resulting status can only be either SYNC which means all files
- * are in sync, ERROR if an error occured, or EVAL if something needs
- * to be synced underneath this dir.
- */
- // compute the file status of a directory recursively. It returns either
- // "all in sync" or "needs update" or "error", no more details.
- SyncFileStatus SocketApi::recursiveFolderStatus(Folder *folder, const QString& fileName, c_strlist_t *excludes )
- {
- QDir dir(folder->path() + fileName);
-
- const QStringList dirEntries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot );
-
- SyncFileStatus result(SyncFileStatus::STATUS_SYNC);
-
- foreach( const QString entry, dirEntries ) {
- QString normalizedFile = QString(fileName + QLatin1Char('/') + entry).normalized(QString::NormalizationForm_C);
- QFileInfo fi(entry);
- SyncFileStatus sfs;
-
- if( fi.isDir() ) {
- sfs = recursiveFolderStatus(folder, normalizedFile, excludes );
- } else {
- QString fs( normalizedFile );
- if( fileName.isEmpty() ) {
- // toplevel, no slash etc. needed.
- fs = entry.normalized(QString::NormalizationForm_C);
- }
- sfs = fileStatus(folder, fs, excludes);
- }
-
- if( sfs.tag() == SyncFileStatus::STATUS_STAT_ERROR || sfs.tag() == SyncFileStatus::STATUS_ERROR ) {
- return SyncFileStatus::STATUS_ERROR;
- } else if( sfs.tag() == SyncFileStatus::STATUS_EVAL || sfs.tag() == SyncFileStatus::STATUS_NEW) {
- result.set(SyncFileStatus::STATUS_EVAL);
- }
- }
- return result;
- }
-
+SqliteHandle SocketApi::getSqliteHandle( Folder *folder )
+{
+ if( _dbConnections.contains(folder) ) {
+ return _dbConnections[folder];
+ }
+ SqliteHandle h;
+ h._db = NULL;
+ h._stmt = NULL;
+
+ if( !folder ) {
+ return h;
+ }
+ int rc;
+ const char* query = "SELECT inode, mode, modtime, type, md5, fileid, remotePerm FROM "
+ "metadata WHERE phash=:ph";
+ QString dbFileName = folder->journalDb()->databaseFilePath();
+
+ if( sqlite3_open_v2(dbFileName.toUtf8().constData(), &(h._db),
+ SQLITE_OPEN_READONLY+SQLITE_OPEN_NOMUTEX, NULL) == SQLITE_OK ) {
+
+ rc = sqlite3_prepare_v2(h._db, query, strlen(query), &(h._stmt), NULL);
+ if( rc != SQLITE_OK ) {
+ qDebug() << "Unable to prepare the query statement.";
+ return h; // do not insert into hash
+ }
+ _dbConnections.insert( folder, h);
+ }
+ return h;
+}
+
+SyncJournalFileRecord SocketApi::dbFileRecord_capi( Folder *folder, QString fileName )
+{
+ if( !(folder && folder->journalDb()) ) {
+ return SyncJournalFileRecord();
+ }
+
+ if( fileName.startsWith( folder->path() )) {
+ fileName.remove(0, folder->path().length());
+ }
+
+ SqliteHandle h = getSqliteHandle(folder);
+
+ sqlite3_stmt *stmt = h._stmt;
+ SyncJournalFileRecord rec;
+
+ if( h._db && h._stmt ) {
+ qlonglong phash = SyncJournalDb::getPHash( fileName );
+ sqlite3_bind_int64(stmt, 1, (long long signed int)phash);
+
+ // int column_count = sqlite3_column_count(stmt);
+
+ int 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_reset(stmt);
+ }
+ return rec;
+}
+
- SyncJournalFileRecord SocketApi::dbFileRecord( Folder *folder, QString fileName )
- {
- if( !folder ) {
- return SyncJournalFileRecord();
- }
-
- QFileInfo fi(fileName);
- if( fi.isAbsolute() ) {
- fileName.remove(0, folder->path().length());
- }
- return( folder->journalDb()->getFileRecord(fileName) );
- }
-
+/**
+ * Get status about a single file.
+ */
+SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileName, c_strlist_t *excludes )
+{
+ QString file = folder->path();
+ QString fileName = systemFileName.normalized(QString::NormalizationForm_C);
+
+ bool isSyncRootFolder = true;
+ if( fileName != QLatin1String("/") && !fileName.isEmpty() ) {
+ file = folder->path() + fileName;
+ isSyncRootFolder = false;
+ }
+
+ if( fileName.endsWith(QLatin1Char('/')) ) {
+ fileName.truncate(fileName.length()-1);
+ qDebug() << "Removed trailing slash: " << fileName;
+ }
+
+ QFileInfo fi(file);
+
+ if( !fi.exists() ) {
+ qDebug() << "OO File " << file << " is not existing";
+ return SyncFileStatus(SyncFileStatus::STATUS_STAT_ERROR);
+ }
+
+ // file is ignored?
+ if( fi.isSymLink() ) {
+ return SyncFileStatus(SyncFileStatus::STATUS_IGNORE);
+ }
- int type = CSYNC_FTW_TYPE_FILE;
++
++ csync_ftw_type_e type = CSYNC_FTW_TYPE_FILE;
+ if( fi.isDir() ) {
+ type = CSYNC_FTW_TYPE_DIR;
+ }
+
+ // '\' is ignored, so convert to unix path before passing the path in.
+ QString unixFileName = QDir::fromNativeSeparators(fileName);
+
+ CSYNC_EXCLUDE_TYPE excl = csync_excluded_no_ctx(excludes, unixFileName.toUtf8(), type);
+ if( excl != CSYNC_NOT_EXCLUDED ) {
+ return SyncFileStatus(SyncFileStatus::STATUS_IGNORE);
+ }
+
- // 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_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_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_capi(folder, parentPath);
++
++ SyncFileStatus status(SyncFileStatus::STATUS_NONE);
++ if (type == CSYNC_FTW_TYPE_DIR) {
++ if (folder->estimateState(fileName, type, &status)) {
++ qDebug() << Q_FUNC_INFO << "Folder estimated status for" << fileName << "to" << status.toSocketAPIString();
++ return status;
+ }
- if( dirRec.isValid() ) {
- if( dirRec._type == CSYNC_FTW_TYPE_DIR ) {
- if( !dirRec._remotePerm.contains("K") ) {
- return SyncFileStatus::STATUS_ERROR;
- }
++ if (fileName == "") {
++ // sync folder itself
++ if (folder->syncResult().status() == SyncResult::Undefined
++ || folder->syncResult().status() == SyncResult::NotYetStarted
++ || folder->syncResult().status() == SyncResult::SyncPrepare
++ || folder->syncResult().status() == SyncResult::SyncRunning
++ || folder->syncResult().status() == SyncResult::Paused) {
++ status.set(SyncFileStatus::STATUS_EVAL);
++ return status;
++ } else if (folder->syncResult().status() == SyncResult::Success
++ || folder->syncResult().status() == SyncResult::Problem) {
++ status.set(SyncFileStatus::STATUS_SYNC);
++ return status;
++ } else if (folder->syncResult().status() == SyncResult::Error
++ || folder->syncResult().status() == SyncResult::SetupError
++ || folder->syncResult().status() == SyncResult::SyncAbortRequested) {
++ status.set(SyncFileStatus::STATUS_ERROR);
++ return status;
++ }
++ }
++ SyncJournalFileRecord rec = dbFileRecord_capi(folder, unixFileName );
++ if (rec.isValid()) {
++ status.set(SyncFileStatus::STATUS_SYNC);
++ if (rec._remotePerm.contains("S")) {
++ status.setSharedWithMe(true);
++ }
++ } else {
++ status.set(SyncFileStatus::STATUS_EVAL);
++ }
++ } else if (type == CSYNC_FTW_TYPE_FILE) {
++ if (folder->estimateState(fileName, type, &status)) {
++ return status;
++ }
++ SyncJournalFileRecord rec = dbFileRecord_capi(folder, unixFileName );
++ if (rec.isValid()) {
++ if (rec._remotePerm.contains("S")) {
++ status.setSharedWithMe(true);
++ }
++ if( FileSystem::getModTime(fi.absoluteFilePath()) == Utility::qDateTimeToTime_t(rec._modtime) ) {
++ status.set(SyncFileStatus::STATUS_SYNC);
++ return status;
+ } else {
- if( !dirRec._remotePerm.contains("C") ) {
- return SyncFileStatus::STATUS_ERROR;
- }
++ status.set(SyncFileStatus::STATUS_EVAL);
++ return status;
+ }
+ }
- return SyncFileStatus(SyncFileStatus::STATUS_NEW);
- }
-
- SyncFileStatus status(SyncFileStatus::STATUS_NONE);
- if( type == CSYNC_FTW_TYPE_DIR ) {
- // compute recursive status of the directory
- status = recursiveFolderStatus( folder, fileName, excludes );
- } else if( FileSystem::getModTime(fi.absoluteFilePath()) != Utility::qDateTimeToTime_t(rec._modtime) ) {
- // file was locally modified.
- status.set(SyncFileStatus::STATUS_EVAL);
- } else {
- status.set(SyncFileStatus::STATUS_SYNC);
- }
-
- if (rec._remotePerm.contains("S")) {
- status.setSharedWithMe(true);
++ status.set(SyncFileStatus::STATUS_NEW);
++ return status;
+ }
+
+ return status;
+}
+
} // namespace Mirall
--
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