From fc1f18f6c56fbf70fad196454bc79b14045bb04c Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Thu, 30 Jan 2020 01:29:46 -0500 Subject: [PATCH] feat(core,registry): unmount HTTP server prefix on docset removal --- src/libs/core/httpserver.cpp | 13 +++++++++++++ src/libs/core/httpserver.h | 1 + src/libs/registry/docsetregistry.cpp | 1 + 3 files changed, 15 insertions(+) diff --git a/src/libs/core/httpserver.cpp b/src/libs/core/httpserver.cpp index 63dcf32..698a334 100644 --- a/src/libs/core/httpserver.cpp +++ b/src/libs/core/httpserver.cpp @@ -90,6 +90,19 @@ QUrl HttpServer::mount(const QString &prefix, const QString &path) return mountUrl; } +bool HttpServer::unmount(const QString &prefix) +{ + const QString pfx = sanitizePrefix(prefix); + const bool ok = m_server->remove_mount_point(pfx.toUtf8()); + if (!ok) { + qCWarning(log, "Failed to unmount '%s' to '%s'.", qPrintable(prefix), qPrintable(pfx)); + } + + qCDebug(log, "Unmounted prefix '%s' ('%s').", qPrintable(prefix), qPrintable(pfx)); + + return ok; +} + QString HttpServer::sanitizePrefix(const QString &prefix) { QString pfx = (prefix.startsWith(QLatin1String("/")) ? prefix.right(1) : prefix).toLower(); diff --git a/src/libs/core/httpserver.h b/src/libs/core/httpserver.h index 5ff0b44..112b634 100644 --- a/src/libs/core/httpserver.h +++ b/src/libs/core/httpserver.h @@ -47,6 +47,7 @@ public: QUrl baseUrl() const; QUrl mount(const QString &prefix, const QString &path); + bool unmount(const QString &prefix); private: static QString sanitizePrefix(const QString &prefix); diff --git a/src/libs/registry/docsetregistry.cpp b/src/libs/registry/docsetregistry.cpp index 3cc562e..0aa5ad3 100644 --- a/src/libs/registry/docsetregistry.cpp +++ b/src/libs/registry/docsetregistry.cpp @@ -166,6 +166,7 @@ void DocsetRegistry::loadDocset(const QString &path) void DocsetRegistry::unloadDocset(const QString &name) { emit docsetAboutToBeUnloaded(name); + Core::Application::instance()->httpServer()->unmount(name); delete m_docsets.take(name); emit docsetUnloaded(name); }