Skip to content

Commit 549008f

Browse files
committed
first stab at consolidating all code paths to use addFolder
1 parent ce44a84 commit 549008f

File tree

6 files changed

+60
-75
lines changed

6 files changed

+60
-75
lines changed

src/gui/folder.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -864,12 +864,11 @@ void Folder::wipeForRemoval()
864864

865865
bool Folder::reloadExcludes()
866866
{
867-
// Lisa todo: why is this returning true of there is no engine?! There is no doc regarding
868-
// what the return value means, but as far as I can tell the engine reloadExludes returns
869-
// true *if the excludes were successfully reloaded*. If the engine is missing the excludes
870-
// can't be reloaded so return here should be false?
867+
// reloadExludes returns true *if the excludes were successfully reloaded*.
868+
// If the engine is missing the excludes
869+
// can't be reloaded so return here should be false? Erik agrees - caller never checks the value anyway
871870
if (!_engine) {
872-
return true;
871+
return false;
873872
}
874873
return _engine->reloadExcludes();
875874
}
@@ -909,6 +908,7 @@ void Folder::startSync()
909908
}
910909
// Lisa todo: why is this called every time a sync starts? the data seems to come from hard vals or the config.
911910
// How can it change between syncs?
911+
// This is part of what Erik wants to ditch - having user settable bandwidth limits is fairly nuts
912912
setDirtyNetworkLimits();
913913

914914
// get the latest touched files
@@ -939,6 +939,10 @@ void Folder::startSync()
939939
// ENGINE, not the def. the value should not be stored in the folder def but in the general area of the config.
940940
// if we ever graduate to allowing the user to set this value *per folder* we can refactor it, but the overhead
941941
// of saving this val for every folder in the config is just silly when it's defacto a global setting.
942+
// Erik has no objections
943+
// generally when we change settings we pause syncs, update whatever values,
944+
// then reschedule the newly paused syncs with top prio and start sync - see handling for changing vfs mode
945+
// consider allowing the engine to run a "update routine" where it pauses and restarts itself.
942946
_engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles());
943947
QMetaObject::invokeMethod(_engine.data(), &SyncEngine::startSync, Qt::QueuedConnection);
944948

src/gui/folderman.cpp

+45-67
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ std::optional<qsizetype> FolderMan::setupFoldersFromConfig()
211211
settings.endGroup(); // Finished processing this account.
212212
}
213213

214+
// why not
215+
settings.sync();
216+
214217
Q_EMIT folderListChanged();
215218

216219
return _folders.size();
@@ -221,8 +224,8 @@ bool FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account)
221224
const auto &childGroups = settings.childGroups();
222225
for (const auto &folderAlias : childGroups) {
223226
settings.beginGroup(folderAlias);
224-
FolderDefinition folderDefinition = FolderDefinition::load(settings, folderAlias.toUtf8());
225227

228+
FolderDefinition folderDefinition = FolderDefinition::load(settings, folderAlias.toUtf8());
226229
// this should NEVER happen
227230
Q_ASSERT(!folderDefinition.id().isEmpty());
228231

@@ -231,47 +234,21 @@ bool FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account)
231234
// also note this migration should probably be done elsewhere but for now...baby steps.
232235
bool migrated = migrateFolderDefinition(folderDefinition, account);
233236

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
246239
if (SyncJournalDb::dbIsTooNewForClient(folderDefinition.absoluteJournalPath())) {
247240
return false;
248241
}
249242

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);
255244

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

265246
// 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.
267248
if (migrated) {
268249
FolderDefinition::save(settings, folder->definition());
269250
}
270251

271-
if (!folder->hasSetupError()) {
272-
connectFolder(folder);
273-
Q_EMIT folderSyncStateChange(folder);
274-
}
275252
settings.endGroup();
276253
}
277254

@@ -359,15 +336,13 @@ bool FolderMan::ensureJournalGone(const QString &journalDbFile)
359336

360337
bool FolderMan::ensureFilesystemSupported(const FolderDefinition &folderDefinition)
361338
{
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);
369343

370-
return false;
344+
return false;
345+
}
371346
}
372347

373348
return true;
@@ -557,30 +532,24 @@ void FolderMan::slotFolderSyncFinished(const SyncResult &)
557532
<< f->accountState()->account()->displayNameWithHost() << "] with remote [" << f->remoteUrl().toDisplayString() << "]";
558533
}
559534

560-
Folder *FolderMan::addFolder(const AccountStatePtr &accountState, const FolderDefinition &folderDefinition)
535+
bool FolderMan::validateFolderDefinition(const FolderDefinition &folderDefinition)
561536
{
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+
}
567541

568-
// Choose a db filename
569-
auto definition = folderDefinition;
570-
if (definition.journalPath().isEmpty()) {
571-
definition.setJournalPath(SyncJournalDb::makeDbName(folderDefinition.localPath()));
572-
}
573542

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
581549
}
582550

583-
if (!ensureFilesystemSupported(definition)) {
551+
if (!validateFolderDefinition(folderDefinition)) {
552+
qCWarning(lcFolderMan) << "Folder Defnition validation failed for folder" << folderDefinition.localPath();
584553
return nullptr;
585554
}
586555

@@ -601,15 +570,7 @@ Folder *FolderMan::addFolder(const AccountStatePtr &accountState, const FolderDe
601570

602571
if (!folder->hasSetupError()) {
603572
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?
609573
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();
613574
}
614575

615576
return folder;
@@ -1046,10 +1007,20 @@ bool FolderMan::checkVfsAvailability(const QString &path, Vfs::Mode mode) const
10461007
Folder *FolderMan::addFolderFromWizard(const AccountStatePtr &accountStatePtr, FolderDefinition &&folderDefinition, bool useVfs)
10471008
{
10481009
if (!FolderMan::prepareFolder(folderDefinition.localPath())) {
1049-
return {};
1010+
return nullptr;
10501011
}
10511012

10521013
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+
}
10531024

10541025
if (useVfs) {
10551026
folderDefinition.setVirtualFilesMode(VfsPluginManager::instance().bestAvailableVfsMode());
@@ -1067,6 +1038,13 @@ Folder *FolderMan::addFolderFromWizard(const AccountStatePtr &accountStatePtr, F
10671038
} else {
10681039
qCWarning(lcFolderMan) << "Failed to create local sync folder!";
10691040
}
1041+
1042+
// find best location with updates
1043+
newFolder->saveToSettings();
1044+
1045+
// should be moved to true originating caller
1046+
Q_EMIT folderListChanged();
1047+
10701048
return newFolder;
10711049
}
10721050

src/gui/folderman.h

+3
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ private Q_SLOTS:
351351
/// \returns false when a downgrade of the database is detected, true otherwise.
352352
bool setupFoldersHelper(QSettings &settings, AccountStatePtr account);
353353

354+
// tests folder def for minimum reqs
355+
bool validateFolderDefinition(const FolderDefinition &folderDefinition);
356+
354357
/// \returns true of the FolderDefinition was migrated, false if it was unchanged
355358
bool migrateFolderDefinition(FolderDefinition &folderDef, AccountStatePtr account);
356359

src/libsync/syncengine.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
#include "common/syncjournalfilerecord.h"
2222
#include "common/vfs.h"
2323
#include "configfile.h"
24-
#include "creds/abstractcredentials.h"
2524
#include "csync_exclude.h"
2625
#include "discovery.h"
2726
#include "discoveryphase.h"
28-
#include "filesystem.h"
2927
#include "owncloudpropagator.h"
30-
#include "propagatedownload.h"
3128
#include "propagateremotedelete.h"
3229

3330
#include <chrono>

test/testspacesmigration/testspacesmigration.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class TestSpacesMigration : public QObject
2727
Q_ASSERT(localPath.startsWith(QLatin1Char('/')));
2828
d.setLocalPath(_tmp.path() + localPath);
2929
d.setTargetPath(remotePath);
30+
d.setJournalPath(SyncJournalDb::makeDbName(d.localPath()));
3031
return TestUtils::folderMan()->addFolder(accountState, d);
3132
}
3233

test/testutils/testutils.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ namespace TestUtils {
3939
return {OCC::AccountManager::instance()->addAccount(acc).get(), &TestUtilsPrivate::accountStateDeleter};
4040
}
4141

42+
// We have more than one of these?
4243
FolderDefinition createDummyFolderDefinition(const AccountPtr &account, const QString &path)
4344
{
4445
// TODO: legacy
4546
auto d = OCC::FolderDefinition::createNewFolderDefinition(account->davUrl(), {});
4647
d.setLocalPath(path);
4748
d.setTargetPath(path);
49+
d.setJournalPath(SyncJournalDb::makeDbName(d.localPath()));
4850
return d;
4951
}
5052

0 commit comments

Comments
 (0)