Skip to content

Commit 990d87a

Browse files
committed
example cases for enhancing handling of previous "assert" conditions
1 parent d61bfe6 commit 990d87a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/common/restartmanager.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ RestartManager::RestartManager(std::function<int(int, char **)> &&main)
3232
: _main(main)
3333
{
3434
Q_ASSERT(!_instance);
35-
_instance = this;
35+
if (!_instance)
36+
_instance = this;
3637
}
3738

3839
RestartManager::~RestartManager()
@@ -59,6 +60,9 @@ int RestartManager::exec(int argc, char **argv) const
5960
void RestartManager::requestRestart()
6061
{
6162
Q_ASSERT(_instance);
63+
if (!_instance)
64+
return;
65+
6266
qCInfo(lcRestart) << "Restarting application with PID" << QCoreApplication::applicationPid();
6367

6468
QString pathToLaunch = QCoreApplication::applicationFilePath();

src/gui/folder.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,9 @@ QUrl Folder::webDavUrl() const
388388
QString Folder::remotePathTrailingSlash() const
389389
{
390390
const QString remote = remotePath();
391-
if (remote == QLatin1Char('/')) {
392-
return remote;
393-
}
394-
Q_ASSERT(!remote.endsWith(QLatin1Char('/')));
395-
return remote + QLatin1Char('/');
391+
if (!remote.endsWith((QLatin1Char('/'))))
392+
return remote + QLatin1Char('/');
393+
return remote;
396394
}
397395

398396
QUrl Folder::remoteUrl() const
@@ -640,7 +638,8 @@ void Folder::slotWatchedPathsChanged(const QSet<QString> &paths, ChangeReason re
640638
bool needSync = false;
641639
for (const auto &path : paths) {
642640
Q_ASSERT(FileSystem::isChildPathOf(path, this->path()));
643-
641+
if (!FileSystem::isChildPathOf(path, this->path()))
642+
continue;
644643
const QString relativePath = path.mid(this->path().size());
645644
if (reason == ChangeReason::UnLock) {
646645
journalDb()->wipeErrorBlacklistEntry(relativePath, SyncJournalErrorBlacklistRecord::Category::LocalSoftError);
@@ -924,6 +923,9 @@ void Folder::startSync()
924923
Q_ASSERT(isReady());
925924
Q_ASSERT(_folderWatcher);
926925

926+
if (!isReady() || !_folderWatcher)
927+
return;
928+
927929
if (!OC_ENSURE(!isSyncRunning())) {
928930
qCCritical(lcFolder) << "ERROR sync is still running and new sync requested.";
929931
return;
@@ -984,6 +986,9 @@ void Folder::startSync()
984986
void Folder::setDirtyNetworkLimits()
985987
{
986988
Q_ASSERT(isReady());
989+
if (!isReady())
990+
return;
991+
987992
ConfigFile cfg;
988993
int downloadLimit = -75; // 75%
989994
int useDownLimit = cfg.useDownloadLimit();
@@ -1332,7 +1337,6 @@ bool Folder::groupInSidebar() const
13321337
if (_accountState->account()->hasDefaultSyncRoot()) {
13331338
// QFileInfo is horrible and "/foo/" is treated different to "/foo"
13341339
const QString parentDir = QFileInfo(Utility::stripTrailingSlash(path())).dir().path();
1335-
Q_ASSERT(QFileInfo(parentDir) != QFileInfo(path()));
13361340
// If parentDir == home, we would add a the home dir to the side bar.
13371341
return QFileInfo(parentDir) != QFileInfo(QDir::homePath()) && FileSystem::isChildPathOf(parentDir, _accountState->account()->defaultSyncRoot());
13381342
}
@@ -1365,6 +1369,8 @@ QString FolderDefinition::spaceId() const
13651369
// we might call the function to check for the id
13661370
// anyhow one of the conditions needs to be true
13671371
Q_ASSERT(_webDavUrl.isValid() || !_spaceId.isEmpty());
1372+
if (!_webDavUrl.isValid() || _spaceId.isEmpty())
1373+
return QString();
13681374
return _spaceId;
13691375
}
13701376
} // namespace OCC

0 commit comments

Comments
 (0)