From dab015742a3acc690d02305414927846898d0610 Mon Sep 17 00:00:00 2001 From: Automatic Release Builder Date: Wed, 30 Sep 2020 14:38:35 +0100 Subject: [PATCH] Catalogs: fix enabling/disabling Relates to bug Michael found in the launcher: https://sourceforge.net/p/flightgear/codetickets/2380/ --- simgear/package/Catalog.cxx | 16 ++++++++++------ simgear/package/Root.cxx | 13 ++++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/simgear/package/Catalog.cxx b/simgear/package/Catalog.cxx index 0c1296a8..7cb8bc7d 100644 --- a/simgear/package/Catalog.cxx +++ b/simgear/package/Catalog.cxx @@ -595,13 +595,17 @@ void Catalog::setUserEnabled(bool b) m_userEnabled = b; SGPath disableMarkerFile = installRoot() / "_disabled_"; - if (m_userEnabled) { - sg_ofstream of(disableMarkerFile); - of << "1\n"; // touch the file + + if (m_userEnabled == false) { + sg_ofstream of(disableMarkerFile, std::ios::trunc | std::ios::out); + of << "1" << std::flush; // touch the file + of.close(); } else { - bool ok = disableMarkerFile.remove(); - if (!ok) { - SG_LOG(SG_GENERAL, SG_ALERT, "Failed to remove catalog-disable marker file:" << disableMarkerFile); + if (disableMarkerFile.exists()) { + const bool ok = disableMarkerFile.remove(); + if (!ok) { + SG_LOG(SG_IO, SG_WARN, "Failed to remove catalog-disable marker file:" << disableMarkerFile); + } } } diff --git a/simgear/package/Root.cxx b/simgear/package/Root.cxx index e0fedfcf..193199c3 100755 --- a/simgear/package/Root.cxx +++ b/simgear/package/Root.cxx @@ -690,14 +690,17 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason) d->refreshing.erase(aCat); } - if ((aReason == Delegate::STATUS_REFRESHED) && (catIt == d->catalogs.end())) { + if (aCat->isUserEnabled() && + (aReason == Delegate::STATUS_REFRESHED) && + (catIt == d->catalogs.end())) + { assert(!aCat->id().empty()); d->catalogs.insert(catIt, CatalogDict::value_type(aCat->id(), aCat)); - // catalog might have been previously disabled, let's remove in that case + // catalog might have been previously disabled, let's remove in that case auto j = std::find(d->disabledCatalogs.begin(), - d->disabledCatalogs.end(), - aCat); + d->disabledCatalogs.end(), + aCat); if (j != d->disabledCatalogs.end()) { SG_LOG(SG_GENERAL, SG_INFO, "re-enabling disabled catalog:" << aCat->id()); d->disabledCatalogs.erase(j); @@ -705,7 +708,7 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason) } if (!aCat->isEnabled()) { - // catalog has errors, disable it + // catalog has errors or was disabled by user, disable it auto j = std::find(d->disabledCatalogs.begin(), d->disabledCatalogs.end(), aCat);