]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Migrate legacy user defined exclude file.
authorCamila <hello@camila.codes>
Wed, 30 Aug 2023 16:34:35 +0000 (18:34 +0200)
committerCamila <hello@camila.codes>
Fri, 1 Sep 2023 13:09:29 +0000 (15:09 +0200)
- Refactor ConfigFile::setupDefaultExcludeFilePaths.
- Refactor ConfigFile::excludeFile.
- Fix code style.

Signed-off-by: Camila <hello@camila.codes>
src/gui/folderman.cpp
src/gui/userinfo.cpp
src/libsync/configfile.cpp
src/libsync/configfile.h

index b69c1cfd426b06a1f4aa8296e9b3844a5bd4fe5e..7000392b3f5ec4e4c6295e1e764743b4bf1572b7 100644 (file)
@@ -184,7 +184,7 @@ int FolderMan::setupFolders()
 
     qCInfo(lcFolderMan) << "Setup folders from settings file";
 
-    //    this is done in Application::configVersionMigration
+    // this is done in Application::configVersionMigration
     QStringList skipSettingsKeys;
     backwardMigrationSettingsKeys(&skipSettingsKeys, &skipSettingsKeys);
     const auto accounts = AccountManager::instance()->accounts();
@@ -353,10 +353,10 @@ int FolderMan::setupFoldersMigration()
     qCInfo(lcFolderMan) << "Setup folders from " << configPath << "(migration)";
 
     QDir dir(configPath);
-    //We need to include hidden files just in case the alias starts with '.'    
+    // We need to include hidden files just in case the alias starts with '.'
     dir.setFilter(QDir::Files | QDir::Hidden);
-    //Exclude previous backed up configs e.g. oc.cfg.backup_20230831_133749_4.0.0
-    //only need the current config in use by the legacy application
+    // Exclude previous backed up configs e.g. oc.cfg.backup_20230831_133749_4.0.0
+    // only need the current config in use by the legacy application
     const auto dirFiles = dir.entryList({"*.cfg"});
 
     // Normally there should be only one account when migrating. TODO: Should assume only one legacy config file
@@ -565,10 +565,10 @@ void FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Accoun
             if (const auto folder = addFolderInternal(folderDefinition, accountState, std::make_unique<VfsOff>())) {
                 auto ok = true;
                 if (const auto legacyBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
-                                                                                      &ok);ok && !legacyBlacklist.isEmpty()) {
+                                                                                      &ok); ok && !legacyBlacklist.isEmpty()) {
                     qCInfo(lcFolderMan) << "Legacy selective sync list found:" << legacyBlacklist;
-                    for(const auto &legacyFolder : legacyBlacklist) {
-                      folder->migrateBlackListPath(legacyFolder);
+                    for (const auto &legacyFolder : legacyBlacklist) {
+                        folder->migrateBlackListPath(legacyFolder);
                     }
                 } else {
                     qCInfo(lcFolderMan) << "There was a problem retriving the database selective sync for " << folder;
@@ -576,7 +576,7 @@ void FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Accoun
 
                 const auto settingLegacyBlacklist = settings.value(QLatin1String("blackList")).toStringList();
                 if (!settingLegacyBlacklist.empty()) {
-                    //migrate settings
+                    // migrate settings
                     folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, settingLegacyBlacklist);
                     settings.remove(QLatin1String("blackList"));
                     // FIXME: If you remove this codepath, you need to provide another way to do
index 15106b119030e8bb39f75c149830d924ad0b41a5..6835cc6285b32e86f89f87d13cc590de2e6a64e6 100644 (file)
@@ -110,10 +110,10 @@ void UserInfo::slotUpdateLastInfo(const QJsonDocument &json)
 
     AccountPtr account = _accountState->account();
 
-    if (const auto newUserId = objData.value("id").toString();!newUserId.isEmpty()) {
+    if (const auto newUserId = objData.value("id").toString(); !newUserId.isEmpty()) {
         if (QString::compare(account->davUser(), newUserId, Qt::CaseInsensitive) != 0) {
             // TODO: the error message should be in the UI
-            qInfo() << "Authed with the wrong user! Please login with the account:" << account->prettyName();
+            qInfo() << "Authenticated with the wrong user! Please login with the account:" << account->prettyName();
             if (const auto cred = account->credentials()) {
                 account->credentials()->askFromUser();
             }
index 60e3912f4bd57874e3273a9dbacfd0b72036a7fd..60cb2cc71aebafe1cafb637e5bf903b843a927ad 100644 (file)
@@ -368,32 +368,27 @@ QString ConfigFile::configPath() const
     return Utility::trailingSlashPath(_confDir);
 }
 
-static const QLatin1String exclFile("sync-exclude.lst");
+static const QLatin1String syncExclFile("sync-exclude.lst");
+static const QLatin1String exclFile("exclude.lst");
 
 QString ConfigFile::excludeFile(Scope scope) const
 {
-    // prefer sync-exclude.lst, but if it does not exist, check for
-    // exclude.lst for compatibility reasons in the user writeable
-    // directories.
-    QFileInfo fi;
+    if (scope == SystemScope) {
+        return ConfigFile::excludeFileFromSystem();
+    }
 
-    switch (scope) {
-    case UserScope:
-        fi.setFile(configPath(), exclFile);
+    const auto excludeFilePath = scope == LegacyScope ? discoveredLegacyConfigPath() : configPath();
 
-        if (!fi.isReadable()) {
-            fi.setFile(configPath(), QLatin1String("exclude.lst"));
-        }
-        if (!fi.isReadable()) {
-            fi.setFile(configPath(), exclFile);
-        }
-        return fi.absoluteFilePath();
-    case SystemScope:
-        return ConfigFile::excludeFileFromSystem();
+    // prefer sync-exclude.lst, but if it does not exist, check for exclude.lst
+    QFileInfo exclFileInfo(excludeFilePath, syncExclFile);
+    if (!exclFileInfo.isReadable()) {
+        exclFileInfo.setFile(excludeFilePath, exclFile);
+    }
+    if (!exclFileInfo.isReadable()) {
+        exclFileInfo.setFile(excludeFilePath, syncExclFile);
     }
 
-    ASSERT(false);
-    return QString();
+    return exclFileInfo.absoluteFilePath();
 }
 
 QString ConfigFile::excludeFileFromSystem()
@@ -1162,23 +1157,29 @@ std::unique_ptr<QSettings> ConfigFile::settingsWithGroup(const QString &group, Q
 void ConfigFile::setupDefaultExcludeFilePaths(ExcludedFiles &excludedFiles)
 {
     ConfigFile cfg;
-    QString systemList = cfg.excludeFile(ConfigFile::SystemScope);
-    QString userList = cfg.excludeFile(ConfigFile::UserScope);
+    const auto systemList = cfg.excludeFile(ConfigFile::SystemScope);
+    const auto userList = cfg.excludeFile(ConfigFile::UserScope);
+    const auto legacyList = cfg.excludeFile(ConfigFile::LegacyScope);
 
     if (!QFile::exists(userList)) {
         qCInfo(lcConfigFile) << "User defined ignore list does not exist:" << userList;
-        if (!QFile::copy(systemList, userList)) {
-            qCInfo(lcConfigFile) << "Could not copy over default list to:" << userList;
+
+        if (QFile::exists(legacyList) && QFile::copy(legacyList, userList)) {
+            qCInfo(lcConfigFile) << "Migrating legacy list" << legacyList << "to user list" << userList;
+
+        } else if (QFile::copy(systemList, userList)) {
+            qCInfo(lcConfigFile) << "Migrating system list" << legacyList << "to user list" << userList;
         }
     }
 
     if (!QFile::exists(userList)) {
         qCInfo(lcConfigFile) << "Adding system ignore list to csync:" << systemList;
         excludedFiles.addExcludeFilePath(systemList);
-    } else {
-        qCInfo(lcConfigFile) << "Adding user defined ignore list to csync:" << userList;
-        excludedFiles.addExcludeFilePath(userList);
+        return;
     }
+
+    qCInfo(lcConfigFile) << "Adding user defined ignore list to csync:" << userList;
+    excludedFiles.addExcludeFilePath(userList);
 }
 
 QString ConfigFile::discoveredLegacyConfigPath()
index 6906c21b7600a97d33cb1e390e986a65ffb37758..21e58412afcc5a9e6d58e2e92adcc6b2165824d7 100644 (file)
@@ -41,7 +41,7 @@ public:
     ConfigFile();
 
     enum Scope { UserScope,
-        SystemScope };
+        SystemScope, LegacyScope };
 
     [[nodiscard]] QString configPath() const;
     [[nodiscard]] QString configFile() const;