Selaa lähdekoodia

Split folders configuration locations for backwards compatibility

Christian Kamm 9 vuotta sitten
vanhempi
commit
61b4da944c
6 muutettua tiedostoa jossa 81 lisäystä ja 18 poistoa
  1. 31 4
      src/gui/folder.cpp
  2. 1 1
      src/gui/folder.h
  3. 24 11
      src/gui/folderman.cpp
  4. 2 0
      src/gui/folderman.h
  5. 14 2
      src/libsync/syncjournaldb.cpp
  6. 9 0
      src/libsync/syncjournaldb.h

+ 31 - 4
src/gui/folder.cpp

@@ -46,7 +46,6 @@
 
 namespace OCC {
 
-
 Folder::Folder(const FolderDefinition& definition,
                AccountState* accountState,
                QObject* parent)
@@ -204,7 +203,7 @@ void Folder::setIgnoreHiddenFiles(bool ignore)
     _definition.ignoreHiddenFiles = ignore;
 }
 
-QString Folder::cleanPath()
+QString Folder::cleanPath() const
 {
     QString cleanedPath = QDir::cleanPath(_canonicalLocalPath);
 
@@ -585,8 +584,33 @@ void Folder::slotThreadTreeWalkResult(const SyncFileItemVector& items)
 
 void Folder::saveToSettings() const
 {
+    // Remove first to make sure we don't get duplicates
+    removeFromSettings();
+
     auto settings = _accountState->settings();
-    settings->beginGroup(QLatin1String("Folders"));
+
+    // The folder is saved to backwards-compatible "Folders"
+    // section only if it has the migrate flag set (i.e. was in
+    // there before) or if the folder is the only one for the
+    // given target path.
+    // This ensures that older clients will not read a configuration
+    // where two folders for different accounts point at the same
+    // local folders.
+    bool oneAccountOnly = true;
+    foreach (Folder* other, FolderMan::instance()->map()) {
+        if (other != this && other->cleanPath() == this->cleanPath()) {
+            oneAccountOnly = false;
+            break;
+        }
+    }
+
+    bool inFolders = _journal.mayMigrateDbLocation() || oneAccountOnly;
+
+    if (inFolders) {
+        settings->beginGroup(QLatin1String("Folders"));
+    } else {
+        settings->beginGroup(QLatin1String("Multifolders"));
+    }
     FolderDefinition::save(*settings, _definition);
 
     settings->sync();
@@ -595,9 +619,12 @@ void Folder::saveToSettings() const
 
 void Folder::removeFromSettings() const
 {
-    auto  settings = _accountState->settings();
+    auto settings = _accountState->settings();
     settings->beginGroup(QLatin1String("Folders"));
     settings->remove(FolderMan::escapeAlias(_definition.alias));
+    settings->endGroup();
+    settings->beginGroup(QLatin1String("Multifolders"));
+    settings->remove(FolderMan::escapeAlias(_definition.alias));
 }
 
 bool Folder::isFileExcludedAbsolute(const QString& fullPath) const

+ 1 - 1
src/gui/folder.h

@@ -111,7 +111,7 @@ public:
     /**
      * wrapper for QDir::cleanPath("Z:\\"), which returns "Z:\\", but we need "Z:" instead
      */
-    QString cleanPath();
+    QString cleanPath() const;
 
     /**
      * remote folder path

+ 24 - 11
src/gui/folderman.cpp

@@ -209,18 +209,16 @@ int FolderMan::setupFolders()
             continue;
         }
         settings->beginGroup(id);
+
         settings->beginGroup(QLatin1String("Folders"));
-        foreach (const auto& folderAlias, settings->childGroups()) {
-            FolderDefinition folderDefinition;
-            if (FolderDefinition::load(*settings, folderAlias, &folderDefinition)) {
-                Folder* f = addFolderInternal(std::move(folderDefinition), account.data());
-                if (f) {
-                    scheduleFolder(f);
-                    emit folderSyncStateChange(f);
-                }
-            }
-        }
-        settings->endGroup(); // Folders
+        setupFoldersHelper(*settings, account, true);
+        settings->endGroup();
+
+        // See Folder::saveToSettings for details about why this exists.
+        settings->beginGroup(QLatin1String("Multifolders"));
+        setupFoldersHelper(*settings, account, false);
+        settings->endGroup();
+
         settings->endGroup(); // <account>
     }
 
@@ -229,6 +227,21 @@ int FolderMan::setupFolders()
     return _folderMap.size();
 }
 
+void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, bool mayMigrateOldDb)
+{
+    foreach (const auto& folderAlias, settings.childGroups()) {
+        FolderDefinition folderDefinition;
+        if (FolderDefinition::load(settings, folderAlias, &folderDefinition)) {
+            Folder* f = addFolderInternal(std::move(folderDefinition), account.data());
+            if (f) {
+                f->journalDb()->setMayMigrateDbLocation(mayMigrateOldDb);
+                scheduleFolder(f);
+                emit folderSyncStateChange(f);
+            }
+        }
+    }
+}
+
 int FolderMan::setupFoldersMigration()
 {
     ConfigFile cfg;

+ 2 - 0
src/gui/folderman.h

@@ -273,6 +273,8 @@ private:
     // restarts the application (Linux only)
     void restartApplication();
 
+    void setupFoldersHelper(QSettings& settings, AccountStatePtr account, bool mayMigrateOldDb);
+
     QSet<Folder*>  _disabledFolders;
     Folder::Map    _folderMap;
     QString        _folderConfigPath;

+ 14 - 2
src/libsync/syncjournaldb.cpp

@@ -33,7 +33,9 @@
 namespace OCC {
 
 SyncJournalDb::SyncJournalDb( QObject *parent) :
-    QObject(parent), _transaction(0)
+    QObject(parent),
+    _transaction(0),
+    _mayMigrateDbLocation(false)
 {
 
 }
@@ -59,6 +61,16 @@ void SyncJournalDb::setAccountParameterForFilePath( const QString& localPath, co
     _dbFile.append(".db");
 }
 
+bool SyncJournalDb::mayMigrateDbLocation() const
+{
+    return _mayMigrateDbLocation;
+}
+
+void SyncJournalDb::setMayMigrateDbLocation(bool migrate)
+{
+    _mayMigrateDbLocation = migrate;
+}
+
 #ifndef NDEBUG
 void SyncJournalDb::setDatabaseFilePath( const QString& dbFile)
 {
@@ -154,7 +166,7 @@ bool SyncJournalDb::checkConnect()
     const QString dir = _dbFile.left( _dbFile.lastIndexOf(QChar('/')) );
     const QString oldDbName = dir + QLatin1String("/.csync_journal.db");
 
-    bool migrateOldDb = FileSystem::fileExists(oldDbName);
+    bool migrateOldDb = _mayMigrateDbLocation && FileSystem::fileExists(oldDbName);
 
     // Whenever there is an old db file, migrate it to the new db path.
     // This is done to make switching from older versions to newer versions

+ 9 - 0
src/libsync/syncjournaldb.h

@@ -64,6 +64,9 @@ public:
 #endif
     void setAccountParameterForFilePath(const QString& localPath, const QUrl &remoteUrl, const QString& remotePath );
 
+    bool mayMigrateDbLocation() const;
+    void setMayMigrateDbLocation(bool migrate);
+
     static qint64 getPHash(const QString& );
 
     void updateErrorBlacklistEntry( const SyncJournalErrorBlacklistRecord& item );
@@ -220,6 +223,12 @@ private:
      * that would write the etag and would void the purpose of avoidReadFromDbOnNextSync
      */
     QList<QString> _avoidReadFromDbOnNextSyncFilter;
+
+    /**
+     * Whether to check old journal path (csync_journal.db) and move the file
+     * to its new location, if it exists.
+     */
+    bool _mayMigrateDbLocation;
 };
 
 bool OWNCLOUDSYNC_EXPORT