@@ -211,6 +211,9 @@ std::optional<qsizetype> FolderMan::setupFoldersFromConfig()
211
211
settings.endGroup (); // Finished processing this account.
212
212
}
213
213
214
+ // why not
215
+ settings.sync ();
216
+
214
217
Q_EMIT folderListChanged ();
215
218
216
219
return _folders.size ();
@@ -221,8 +224,8 @@ bool FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account)
221
224
const auto &childGroups = settings.childGroups ();
222
225
for (const auto &folderAlias : childGroups) {
223
226
settings.beginGroup (folderAlias);
224
- FolderDefinition folderDefinition = FolderDefinition::load (settings, folderAlias.toUtf8 ());
225
227
228
+ FolderDefinition folderDefinition = FolderDefinition::load (settings, folderAlias.toUtf8 ());
226
229
// this should NEVER happen
227
230
Q_ASSERT (!folderDefinition.id ().isEmpty ());
228
231
@@ -231,47 +234,21 @@ bool FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account)
231
234
// also note this migration should probably be done elsewhere but for now...baby steps.
232
235
bool migrated = migrateFolderDefinition (folderDefinition, account);
233
236
234
- // ensure we don't add multiple legacy folders with the same id
235
- // Lisa todo: is this really possible? I have very strong doubts.
236
- // Setting a val on a given key in QSettings will overwrite previous val so I see no chance of
237
- // having dupes in the config.
238
- Folder *folderAlreadyExists = folder (folderDefinition.id ());
239
- if (folderAlreadyExists) {
240
- // I can't imagine how this could happen, die if it does
241
- Q_ASSERT (false );
242
- continue ;
243
- }
244
-
245
- // Lisa todo: I think this only happens when loading from config - make sure
237
+ // this can only happen when loading from config
238
+ // does not belong in general addFolder routine
246
239
if (SyncJournalDb::dbIsTooNewForClient (folderDefinition.absoluteJournalPath ())) {
247
240
return false ;
248
241
}
249
242
250
- auto vfs = VfsPluginManager::instance ().createVfsFromPlugin (folderDefinition.virtualFilesMode ());
251
- if (!vfs) {
252
- qCWarning (lcFolderMan) << " Could not load plugin for mode" << folderDefinition.virtualFilesMode ();
253
- continue ;
254
- }
243
+ Folder *folder = addFolder (account, folderDefinition);
255
244
256
- // ehhh - the move for the folder def is more to show change of "ownership" than anything else. it's not an expensive copy
257
- Folder *folder = new Folder (std::move (folderDefinition), account, std::move (vfs));
258
-
259
- qCInfo (lcFolderMan) << " Adding folder to Folder Map on load folders from config " << folder << folder->path ();
260
- _folders.push_back (folder);
261
- if (folder->syncPaused ()) {
262
- _disabledFolders.insert (folder);
263
- }
264
245
265
246
// save possible changes from the migration - a bit of ick here is that the folder may be saving changes
266
- // to the folder def during its internal setup, too.
247
+ // to the folder def during its internal setup, too, but this save should catch everything .
267
248
if (migrated) {
268
249
FolderDefinition::save (settings, folder->definition ());
269
250
}
270
251
271
- if (!folder->hasSetupError ()) {
272
- connectFolder (folder);
273
- Q_EMIT folderSyncStateChange (folder);
274
- }
275
252
settings.endGroup ();
276
253
}
277
254
@@ -359,15 +336,13 @@ bool FolderMan::ensureJournalGone(const QString &journalDbFile)
359
336
360
337
bool FolderMan::ensureFilesystemSupported (const FolderDefinition &folderDefinition)
361
338
{
362
- #ifndef Q_OS_MAC
363
- return true ;
364
- #endif
365
-
366
- QString filesystemType = FileSystem::fileSystemForPath (folderDefinition.localPath ());
367
- if (filesystemType != QStringLiteral (" apfs" )) {
368
- QMessageBox::warning (nullptr , tr (" Unsupported filesystem" ), tr (" On macOS, only the Apple File System is supported." ), QMessageBox::Ok);
339
+ if (Utility::isMac ()) {
340
+ QString filesystemType = FileSystem::fileSystemForPath (folderDefinition.localPath ());
341
+ if (filesystemType != QStringLiteral (" apfs" )) {
342
+ QMessageBox::warning (nullptr , tr (" Unsupported filesystem" ), tr (" On macOS, only the Apple File System is supported." ), QMessageBox::Ok);
369
343
370
- return false ;
344
+ return false ;
345
+ }
371
346
}
372
347
373
348
return true ;
@@ -557,30 +532,24 @@ void FolderMan::slotFolderSyncFinished(const SyncResult &)
557
532
<< f->accountState ()->account ()->displayNameWithHost () << " ] with remote [" << f->remoteUrl ().toDisplayString () << " ]" ;
558
533
}
559
534
560
- Folder * FolderMan::addFolder ( const AccountStatePtr &accountState, const FolderDefinition &folderDefinition)
535
+ bool FolderMan::validateFolderDefinition ( const FolderDefinition &folderDefinition)
561
536
{
562
- // Lisa todo: should we not check to see if the folder is already in _folders at this point?
563
- // this is a diff from the handling of folders from config
564
- // I don't think we ever want to have folders with dup id's but either way we should
565
- // be consistent about it.
566
-
537
+ if (folderDefinition.id ().isEmpty () || folderDefinition.journalPath ().isEmpty () || !ensureFilesystemSupported (folderDefinition))
538
+ return false ;
539
+ return true ;
540
+ }
567
541
568
- // Choose a db filename
569
- auto definition = folderDefinition;
570
- if (definition.journalPath ().isEmpty ()) {
571
- definition.setJournalPath (SyncJournalDb::makeDbName (folderDefinition.localPath ()));
572
- }
573
542
574
- // Lisa todo: why are we doing this check when adding a folder?
575
- // should it not happen on removing the sync?
576
- // should the journal be removed even when loading from config? I don't think so but we
577
- // want to eventually use just a single impl for "addFolder" and this is a potentially
578
- // misplaced handling of the issue
579
- if (!ensureJournalGone (definition.absoluteJournalPath ())) {
580
- return nullptr ;
543
+ Folder *FolderMan::addFolder (const AccountStatePtr &accountState, const FolderDefinition &folderDefinition)
544
+ {
545
+ if (Folder *f = folder (folderDefinition.id ())) {
546
+ Q_ASSERT_X (false , " addFolder" , " Trying to addFolder but id is already found in the folder list" );
547
+ qCWarning (lcFolderMan) << " Trying to add folder" << folderDefinition.localPath () << " but it already exists in folder list" ;
548
+ return f; // or return nullptr - talk to Erik
581
549
}
582
550
583
- if (!ensureFilesystemSupported (definition)) {
551
+ if (!validateFolderDefinition (folderDefinition)) {
552
+ qCWarning (lcFolderMan) << " Folder Defnition validation failed for folder" << folderDefinition.localPath ();
584
553
return nullptr ;
585
554
}
586
555
@@ -601,15 +570,7 @@ Folder *FolderMan::addFolder(const AccountStatePtr &accountState, const FolderDe
601
570
602
571
if (!folder->hasSetupError ()) {
603
572
connectFolder (folder);
604
- }
605
-
606
- if (folder) {
607
- folder->saveToSettings ();
608
- // should we really emit sync change here or only if there are not setup errors?
609
573
Q_EMIT folderSyncStateChange (folder);
610
- // Lisa todo: this should be a smaller "folderAdded" signal. folderListChanged triggers rebuilding
611
- // the whole item model for the gui - instead it should just add the new folder item to the model
612
- Q_EMIT folderListChanged ();
613
574
}
614
575
615
576
return folder;
@@ -1046,10 +1007,20 @@ bool FolderMan::checkVfsAvailability(const QString &path, Vfs::Mode mode) const
1046
1007
Folder *FolderMan::addFolderFromWizard (const AccountStatePtr &accountStatePtr, FolderDefinition &&folderDefinition, bool useVfs)
1047
1008
{
1048
1009
if (!FolderMan::prepareFolder (folderDefinition.localPath ())) {
1049
- return {} ;
1010
+ return nullptr ;
1050
1011
}
1051
1012
1052
1013
folderDefinition.setIgnoreHiddenFiles (ignoreHiddenFiles ());
1014
+ folderDefinition.setJournalPath (SyncJournalDb::makeDbName (folderDefinition.localPath ()));
1015
+
1016
+ // Lisa todo: why are we doing this check when adding a folder?
1017
+ // should it not happen on removing the sync? Yes it should
1018
+ // should the journal be removed even when loading from config? Not usually, but maybe if there was a migration?
1019
+ // sticky part is old clients may not remove the old journal so we at least need a check, but ELSEWHERE
1020
+ //
1021
+ if (!ensureJournalGone (folderDefinition.absoluteJournalPath ())) {
1022
+ return nullptr ;
1023
+ }
1053
1024
1054
1025
if (useVfs) {
1055
1026
folderDefinition.setVirtualFilesMode (VfsPluginManager::instance ().bestAvailableVfsMode ());
@@ -1067,6 +1038,13 @@ Folder *FolderMan::addFolderFromWizard(const AccountStatePtr &accountStatePtr, F
1067
1038
} else {
1068
1039
qCWarning (lcFolderMan) << " Failed to create local sync folder!" ;
1069
1040
}
1041
+
1042
+ // find best location with updates
1043
+ newFolder->saveToSettings ();
1044
+
1045
+ // should be moved to true originating caller
1046
+ Q_EMIT folderListChanged ();
1047
+
1070
1048
return newFolder;
1071
1049
}
1072
1050
0 commit comments