[Pkg-owncloud-commits] [owncloud-client] 75/164: Ensure good sync state if in-progress folder is deleted. #2896

Sandro Knauß hefee-guest at moszumanska.debian.org
Sun Mar 22 11:56:55 UTC 2015


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 e381143a8f5c6752fca621aa50dc02a8f747e43c
Author: Christian Kamm <kamm at incasoftware.de>
Date:   Fri Feb 27 10:42:59 2015 +0100

    Ensure good sync state if in-progress folder is deleted. #2896
    
    The slotFolderSyncFinished() didn't reliably trigger because
    the folder was being deleted before the syncFinished signal could
    fire.
---
 src/gui/application.cpp |  2 +-
 src/gui/folderman.cpp   | 89 ++++++++++++++++++++++---------------------------
 src/gui/folderman.h     |  9 +++--
 3 files changed, 44 insertions(+), 56 deletions(-)

diff --git a/src/gui/application.cpp b/src/gui/application.cpp
index 01d97ca..26b15c4 100644
--- a/src/gui/application.cpp
+++ b/src/gui/application.cpp
@@ -224,7 +224,7 @@ void Application::slotCleanup()
     if (account) {
         account->save();
     }
-    FolderMan::instance()->unloadAllFolders();
+    FolderMan::instance()->unloadAndDeleteAllFolders();
 
     _gui->slotShutdown();
     _gui->deleteLater();
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index f401020..89f4613 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -94,27 +94,25 @@ OCC::Folder::Map FolderMan::map()
     return _folderMap;
 }
 
-// Attention: this function deletes the folder object to which
-// the alias refers. Do NOT USE the folder pointer any more after
-// having this called.
 void FolderMan::unloadFolder( const QString& alias )
 {
-    Folder *f = folder(alias);
-    if( f ) {
-        if( _socketApi ) {
-            _socketApi->slotUnregisterPath(alias);
-        }
+    Folder* f = folder(alias);
+    if( !f ) {
+        return;
+    }
 
-        _folderChangeSignalMapper->removeMappings(f);
-        if( _folderWatchers.contains(alias)) {
-            _folderWatchers.remove(alias);
-        }
-        _folderMap.remove( alias );
-        delete f;
+    if( _socketApi ) {
+        _socketApi->slotUnregisterPath(alias);
+    }
+
+    _folderChangeSignalMapper->removeMappings(f);
+    if( _folderWatchers.contains(alias)) {
+        _folderWatchers.remove(alias);
     }
+    _folderMap.remove( alias );
 }
 
-int FolderMan::unloadAllFolders()
+int FolderMan::unloadAndDeleteAllFolders()
 {
     int cnt = 0;
 
@@ -122,7 +120,9 @@ int FolderMan::unloadAllFolders()
     Folder::MapIterator i(_folderMap);
     while (i.hasNext()) {
         i.next();
+        Folder* f = i.value();
         unloadFolder(i.key());
+        delete f;
         cnt++;
     }
     _lastSyncFolder.clear();
@@ -188,7 +188,7 @@ int FolderMan::setupFolders()
 {
   qDebug() << "* Setup folders from " << _folderConfigPath;
 
-  unloadAllFolders();
+  unloadAndDeleteAllFolders();
 
   ConfigFile cfg;
   QDir storageDir(cfg.configPath());
@@ -761,48 +761,37 @@ void FolderMan::removeAllFolderDefinitions()
 
 void FolderMan::slotRemoveFolder( const QString& alias )
 {
-    if( alias.isEmpty() ) return;
-
-    if( _currentSyncFolder == alias ) {
-        // terminate if the sync is currently underway.
-        terminateSyncProcess();
+    Folder *f = folder(alias);
+    if( !f ) {
+        qDebug() << "!! Can not remove " << alias << ", not in folderMap.";
+        return;
     }
-    removeFolder(alias);
-}
 
-// remove a folder from the map. Should be sure n
-void FolderMan::removeFolder( const QString& alias )
-{
-    Folder *f = 0;
-
-    _scheduleQueue.removeAll(alias);
+    qDebug() << "Removing " << alias;
 
-    if( _folderMap.contains( alias )) {
-        qDebug() << "Removing " << alias;
-        f = _folderMap[alias]; // do not remove from the map, that is done in unloadFolder.
-    } else {
-        qDebug() << "!! Can not remove " << alias << ", not in folderMap.";
+    const bool currentlyRunning = (_currentSyncFolder == alias);
+    if( currentlyRunning ) {
+        // let the folder delete itself when done and
+        // abort the sync now
+        connect(f, SIGNAL(syncFinished(SyncResult)), f, SLOT(deleteLater()));
+        terminateSyncProcess();
     }
 
-    if( f ) {
-        f->wipe();
-
-        // can be removed if we are able to delete the folder object.
-        f->setSyncPaused(true);
+    _scheduleQueue.removeAll(alias);
 
-        // remove the folder configuration
-        QFile file(f->configFile() );
-        if( file.exists() ) {
-            qDebug() << "Remove folder config file " << file.fileName();
-            file.remove();
-        }
+    f->wipe();
+    f->setSyncPaused(true);
 
-        unloadFolder( alias ); // now the folder object is gone.
+    // remove the folder configuration
+    QFile file(f->configFile() );
+    if( file.exists() ) {
+        qDebug() << "Remove folder config file " << file.fileName();
+        file.remove();
+    }
 
-        // FIXME: this is a temporar dirty fix against a crash happening because
-        // the csync owncloud module still has static components. Activate the
-        // delete once the module is fixed.
-        // f->deleteLater();
+    unloadFolder( alias );
+    if( !currentlyRunning ) {
+        delete f;
     }
 }
 
diff --git a/src/gui/folderman.h b/src/gui/folderman.h
index 7c3df51..7c7ae4a 100644
--- a/src/gui/folderman.h
+++ b/src/gui/folderman.h
@@ -121,10 +121,8 @@ public slots:
      */
     void terminateSyncProcess();
 
-    /* unload and delete on folder object */
-    void unloadFolder( const QString& alias );
     /* delete all folder objects */
-    int unloadAllFolders();
+    int unloadAndDeleteAllFolders();
 
     // if enabled is set to false, no new folders will start to sync.
     // the current one will finish.
@@ -150,6 +148,9 @@ private slots:
     void slotRemoveFoldersForAccount(AccountState* accountState);
 
 private:
+    /* unloads a folder object, does not delete it */
+    void unloadFolder( const QString& alias );
+
     /** Will start a sync after a bit of delay. */
     void startScheduledSyncSoon(qint64 msMinimumDelay = 0);
 
@@ -160,8 +161,6 @@ private:
 
     QString unescapeAlias( const QString& ) const;
 
-    void removeFolder( const QString& );
-
     QSet<Folder*>  _disabledFolders;
     Folder::Map    _folderMap;
     QString        _folderConfigPath;

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