[Pkg-owncloud-commits] [owncloud-client] 62/332: SocketAPI: Add another API call for stat of file and folder separately.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Aug 14 21:06:38 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 4d5c74c0198c2325f44cdb0fc6dedb97aeaa63d4
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Jun 6 15:37:04 2014 +0200

    SocketAPI: Add another API call for stat of file and folder separately.
---
 src/mirall/socketapi.cpp | 149 ++++++++++++++++++++++++-----------------------
 src/mirall/socketapi.h   |   1 +
 2 files changed, 76 insertions(+), 74 deletions(-)

diff --git a/src/mirall/socketapi.cpp b/src/mirall/socketapi.cpp
index d94fee7..f1df5a2 100644
--- a/src/mirall/socketapi.cpp
+++ b/src/mirall/socketapi.cpp
@@ -138,95 +138,96 @@ void SocketApi::broadcastMessage(const QString& message)
 
 void SocketApi::command_RETRIEVE_FOLDER_STATUS(const QString& argument, QLocalSocket* socket)
 {
-    bool checkForSyncDirsOnly = false;
     qDebug() << Q_FUNC_INFO << argument;
-    //TODO: do security checks?!
+    QString statusString;
+
+    if( !socket ) {
+        qDebug() << "No valid socket object.";
+        return;
+    }
+
     Folder* folder = FolderMan::instance()->folderForPath( argument );
     // this can happen in offline mode e.g.: nothing to worry about
     if (!folder) {
         DEBUG << "folder offline or not watched:" << argument;
-        checkForSyncDirsOnly = true;
+        statusString = QLatin1String("NOP");
     }
 
     QDir dir(argument);
-    QStringList dirEntries;
-
-    if( checkForSyncDirsOnly ) {
-        dirEntries = dir.entryList(QDir::Dirs);
-    } else {
-        dirEntries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot );
-    }
-
-    foreach(const QString entry, dirEntries) {
-        QString absoluteFilePath = dir.absoluteFilePath(entry);
-        QString statusString;
-
-        if( checkForSyncDirsOnly ) {
-            Folder *f = FolderMan::instance()->folderForPath(absoluteFilePath);
-
-            if( f ) {
-                statusString = QLatin1String("SYNCDIR");
-                SyncFileStatus sfs = f->recursiveFolderStatus("");
-                if (sfs == FILE_STATUS_ERROR) {
-                    statusString.append(QLatin1String("_ERR"));
-                } else if( sfs == FILE_STATUS_EVAL ) {
-                    statusString.append(QLatin1String("_EVAL"));
-                } else if( sfs == FILE_STATUS_SYNC ) {
-                    // all cool.
-                } else {
-                    qDebug() << "Unexpected directory status!";
-                }
+    if( statusString.isEmpty() ) {
+        const QStringList fileEntries = dir.entryList( QDir::Files );
+        foreach(const QString file, fileEntries) {
+            const QString absoluteFilePath = dir.absoluteFilePath(file);
+            SyncFileStatus fileStatus = folder->fileStatus( absoluteFilePath.mid(folder->path().length()) );
+            if( fileStatus == FILE_STATUS_STAT_ERROR ) {
+                qDebug() << "XXXXXXXXXXXX FileStatus is STAT ERROR for " << absoluteFilePath;
             }
-        } else {
-            SyncFileStatus fileStatus = folder->fileStatus(absoluteFilePath.mid(folder->path().length()));
-            switch(fileStatus)
-            {
-            case FILE_STATUS_NONE:
-                statusString = QLatin1String("NONE");
-                break;
-            case FILE_STATUS_EVAL:
-                statusString = QLatin1String("EVAL");
-                break;
-            case FILE_STATUS_REMOVE:
-                statusString = QLatin1String("REMOVE");
-                break;
-            case FILE_STATUS_RENAME:
-                statusString = QLatin1String("RENAME");
+            if( fileStatus != FILE_STATUS_SYNC ) {
+                qDebug() << "SyncFileStatus for " << absoluteFilePath << " is " << fileStatus;
+                // we found something that is not in sync
+                statusString = QLatin1String("NEED_SYNC");
                 break;
-            case FILE_STATUS_NEW:
-                statusString = QLatin1String("NEW");
-                break;
-            case FILE_STATUS_CONFLICT:
-                statusString = QLatin1String("CONFLICT");
-                break;
-            case FILE_STATUS_IGNORE:
-                statusString = QLatin1String("IGNORE");
-                break;
-            case FILE_STATUS_SYNC:
-                statusString = QLatin1String("SYNC");
-                break;
-            case FILE_STATUS_STAT_ERROR:
-                statusString = QLatin1String("STAT_ERROR");
-                break;
-            case FILE_STATUS_ERROR:
-                statusString = QLatin1String("ERROR");
-                break;
-            case FILE_STATUS_UPDATED:
-                statusString = QLatin1String("UPDATED");
-                break;
-            default:
-                qWarning() << "not all SyncFileStatus items checked!";
-                Q_ASSERT(false);
-                statusString = QLatin1String("NONE");
+            }
+        }
+    }
+
+    if( statusString.isEmpty() ) { // if  it is still empty, we check the dirs recursively.
+        const QStringList dirEntries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot );
 
+        foreach(const QString entry, dirEntries) {
+            QString absoluteFilePath = dir.absoluteFilePath(entry);
+            SyncFileStatus sfs = folder->recursiveFolderStatus( absoluteFilePath.mid(folder->path().length()) );
+            if( sfs != FILE_STATUS_SYNC ) {
+                statusString = QLatin1String("NEED_SYNC");
+                break;
             }
         }
-        if( ! statusString.isEmpty() ) {
-            QString message("%1:%2:%3");
-            message = message.arg("STATUS").arg(statusString).arg(absoluteFilePath);
-            sendMessage(socket, message);
+    }
+
+    if( statusString.isEmpty() ) {
+        statusString = QLatin1String("OK");
+    }
+
+    QString message = QLatin1String("STATUS:")+statusString+QLatin1Char(':')+argument;
+    sendMessage(socket, message);
+}
+
+void SocketApi::command_RETRIEVE_FILE_STATUS(const QString& argument, QLocalSocket* socket)
+{
+    if( !socket ) {
+        qDebug() << "No valid socket object.";
+        return;
+    }
+
+    qDebug() << Q_FUNC_INFO << argument;
+
+    QString statusString;
+
+    Folder* folder = FolderMan::instance()->folderForPath( argument );
+    // this can happen in offline mode e.g.: nothing to worry about
+    if (!folder) {
+        DEBUG << "folder offline or not watched:" << argument;
+        statusString = QLatin1String("NOP");
+    }
+
+    if( statusString.isEmpty() ) {
+        SyncFileStatus fileStatus = folder->fileStatus( argument.mid(folder->path().length()) );
+        if( fileStatus == FILE_STATUS_STAT_ERROR ) {
+            qDebug() << "XXXXXXXXXXXX FileStatus is STAT ERROR for " << argument;
+        }
+        if( fileStatus != FILE_STATUS_SYNC ) {
+            qDebug() << "SyncFileStatus for " << argument << " is " << fileStatus;
+            // we found something that is not in sync
+            statusString = QLatin1String("NEED_SYNC");
         }
     }
+
+    if( statusString.isEmpty() ) {
+        statusString = QLatin1String("OK");
+    }
+
+    QString message = QLatin1String("STATUS:")+statusString+QLatin1Char(':')+argument;
+    sendMessage(socket, message);
 }
 
 } // namespace Mirall
diff --git a/src/mirall/socketapi.h b/src/mirall/socketapi.h
index 966be27..be0572e 100644
--- a/src/mirall/socketapi.h
+++ b/src/mirall/socketapi.h
@@ -44,6 +44,7 @@ private:
     void broadcastMessage(const QString& message);
 
     Q_INVOKABLE void command_RETRIEVE_FOLDER_STATUS(const QString& argument, QLocalSocket* socket);
+    Q_INVOKABLE void command_RETRIEVE_FILE_STATUS(const QString& argument, QLocalSocket* socket);
 
 private:
     QLocalServer* _localServer;

-- 
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