@@ -165,6 +165,9 @@ int FolderMan::setupFolders()
165
165
{
166
166
unloadAndDeleteAllFolders ();
167
167
168
+ QStringList skipSettingsKeys;
169
+ backwardMigrationSettingsKeys (&skipSettingsKeys, &skipSettingsKeys);
170
+
168
171
auto settings = ConfigFile::settingsWithGroup (QLatin1String (" Accounts" ));
169
172
const auto accountsWithSettings = settings->childGroups ();
170
173
if (accountsWithSettings.isEmpty ()) {
@@ -184,19 +187,24 @@ int FolderMan::setupFolders()
184
187
}
185
188
settings->beginGroup (id);
186
189
187
- settings->beginGroup (QLatin1String (" Folders" ));
188
- setupFoldersHelper (*settings, account, true );
189
- settings->endGroup ();
190
+ // The "backwardsCompatible" flag here is related to migrating old
191
+ // database locations
192
+ auto process = [&](const QString &groupName, bool backwardsCompatible = false ) {
193
+ settings->beginGroup (groupName);
194
+ if (skipSettingsKeys.contains (settings->group ())) {
195
+ // Should not happen: bad container keys should have been deleted
196
+ qCWarning (lcFolderMan) << " Folder structure" << groupName << " is too new, ignoring" ;
197
+ } else {
198
+ setupFoldersHelper (*settings, account, backwardsCompatible, skipSettingsKeys);
199
+ }
200
+ settings->endGroup ();
201
+ };
190
202
191
- // See Folder::saveToSettings for details about why this exists.
192
- settings->beginGroup (QLatin1String (" Multifolders" ));
193
- setupFoldersHelper (*settings, account, false );
194
- settings->endGroup ();
203
+ process (QStringLiteral (" Folders" ), true );
195
204
196
- // See Folder::saveToSettings for details about why this exists.
197
- settings->beginGroup (QLatin1String (" FoldersWithPlaceholders" ));
198
- setupFoldersHelper (*settings, account, false );
199
- settings->endGroup ();
205
+ // See Folder::saveToSettings for details about why these exists.
206
+ process (QStringLiteral (" Multifolders" ));
207
+ process (QStringLiteral (" FoldersWithPlaceholders" ));
200
208
201
209
settings->endGroup (); // <account>
202
210
}
@@ -206,9 +214,19 @@ int FolderMan::setupFolders()
206
214
return _folderMap.size ();
207
215
}
208
216
209
- void FolderMan::setupFoldersHelper (QSettings &settings, AccountStatePtr account, bool backwardsCompatible)
217
+ void FolderMan::setupFoldersHelper (QSettings &settings, AccountStatePtr account, bool backwardsCompatible, const QStringList &ignoreKeys )
210
218
{
211
219
foreach (const auto &folderAlias, settings.childGroups ()) {
220
+ // Skip folders with too-new version
221
+ settings.beginGroup (folderAlias);
222
+ if (ignoreKeys.contains (settings.group ())) {
223
+ qCInfo (lcFolderMan) << " Folder" << folderAlias << " is too new, ignoring" ;
224
+ _additionalBlockedFolderAliases.insert (folderAlias);
225
+ settings.endGroup ();
226
+ continue ;
227
+ }
228
+ settings.endGroup ();
229
+
212
230
FolderDefinition folderDefinition;
213
231
if (FolderDefinition::load (settings, folderAlias, &folderDefinition)) {
214
232
auto defaultJournalPath = folderDefinition.defaultJournalPath (account->account ());
@@ -274,9 +292,8 @@ int FolderMan::setupFoldersMigration()
274
292
return _folderMap.size ();
275
293
}
276
294
277
- QStringList FolderMan::backwardMigrationKeys ( )
295
+ void FolderMan::backwardMigrationSettingsKeys (QStringList *deleteKeys, QStringList *ignoreKeys )
278
296
{
279
- QStringList badKeys;
280
297
auto settings = ConfigFile::settingsWithGroup (QLatin1String (" Accounts" ));
281
298
282
299
auto processSubgroup = [&](const QString &name) {
@@ -287,12 +304,12 @@ QStringList FolderMan::backwardMigrationKeys()
287
304
settings->beginGroup (folderAlias);
288
305
const int folderVersion = settings->value (QLatin1String (versionC), 1 ).toInt ();
289
306
if (folderVersion > FolderDefinition::maxSettingsVersion ()) {
290
- badKeys. append (settings->group ());
307
+ ignoreKeys-> append (settings->group ());
291
308
}
292
309
settings->endGroup ();
293
310
}
294
311
} else {
295
- badKeys. append (settings->group ());
312
+ deleteKeys-> append (settings->group ());
296
313
}
297
314
settings->endGroup ();
298
315
};
@@ -304,7 +321,6 @@ QStringList FolderMan::backwardMigrationKeys()
304
321
processSubgroup (" FoldersWithPlaceholders" );
305
322
settings->endGroup ();
306
323
}
307
- return badKeys;
308
324
}
309
325
310
326
bool FolderMan::ensureJournalGone (const QString &journalDbFile)
@@ -946,7 +962,9 @@ Folder *FolderMan::addFolderInternal(FolderDefinition folderDefinition,
946
962
{
947
963
auto alias = folderDefinition.alias ;
948
964
int count = 0 ;
949
- while (folderDefinition.alias .isEmpty () || _folderMap.contains (folderDefinition.alias )) {
965
+ while (folderDefinition.alias .isEmpty ()
966
+ || _folderMap.contains (folderDefinition.alias )
967
+ || _additionalBlockedFolderAliases.contains (folderDefinition.alias )) {
950
968
// There is already a folder configured with this name and folder names need to be unique
951
969
folderDefinition.alias = alias + QString::number (++count);
952
970
}
0 commit comments