From b3ffa2349906e40d34a2b0e9c427c7e9b36e90e8 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 10 Oct 2017 21:04:52 +0200 Subject: [PATCH] Relative paths for includes in package index files Plus: inhibt some deferred methods during processEvent (i.e. progress reporting, HTTP/HTTPS download). --- src/lay/lay/layApplication.cc | 6 +++++- src/lay/lay/layProgress.cc | 3 +++ src/lay/lay/laySaltDownloadManager.cc | 1 + src/lay/lay/laySaltGrains.cc | 26 ++++++++++++++++++++++++-- src/lay/lay/laySaltGrains.h | 1 + src/tl/tl/tlHttpStream.cc | 4 ++++ 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/lay/lay/layApplication.cc b/src/lay/lay/layApplication.cc index bc54d25e9..b6d92b2c9 100644 --- a/src/lay/lay/layApplication.cc +++ b/src/lay/lay/layApplication.cc @@ -1371,7 +1371,11 @@ Application::process_events (QEventLoop::ProcessEventsFlags flags, bool silent) #endif mp_mw->enter_busy_mode (true); - QApplication::processEvents (flags); + try { + QApplication::processEvents (flags); + } catch (...) { + // ignore exceptions + } mp_mw->enter_busy_mode (false); if (silent) { diff --git a/src/lay/lay/layProgress.cc b/src/lay/lay/layProgress.cc index 9713bbee7..3aad0b9c3 100644 --- a/src/lay/lay/layProgress.cc +++ b/src/lay/lay/layProgress.cc @@ -190,6 +190,9 @@ ProgressReporter::update_and_yield () void ProgressReporter::process_events () { + // Don't execute deferred methods during progress handling (undesired side effects) + tl::NoDeferredMethods silent; + if (m_pw_visible && lay::MainWindow::instance () && QApplication::instance ()) { QApplication::instance ()->processEvents (QEventLoop::AllEvents); } diff --git a/src/lay/lay/laySaltDownloadManager.cc b/src/lay/lay/laySaltDownloadManager.cc index 753324452..74fe412db 100644 --- a/src/lay/lay/laySaltDownloadManager.cc +++ b/src/lay/lay/laySaltDownloadManager.cc @@ -371,6 +371,7 @@ SaltDownloadManager::execute (lay::SaltManagerDialog *parent, lay::Salt &salt) dialog->setModal (true); dialog->show (); + // TODO: should not waste CPU time in processEvents loop. while (! dialog->is_confirmed ()) { QCoreApplication::processEvents (QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents, 100); if (dialog->is_cancelled () || ! dialog->isVisible ()) { diff --git a/src/lay/lay/laySaltGrains.cc b/src/lay/lay/laySaltGrains.cc index 3fcc9fe14..fa97d32e9 100644 --- a/src/lay/lay/laySaltGrains.cc +++ b/src/lay/lay/laySaltGrains.cc @@ -28,6 +28,7 @@ #include #include #include +#include namespace lay { @@ -245,6 +246,8 @@ static tl::XMLStruct s_xml_struct ("salt-mine", s_group_struct) void SaltGrains::load (const std::string &p) { + m_url = p; + tl::XMLFileSource source (p); s_xml_struct.parse (source, *this); } @@ -252,14 +255,33 @@ SaltGrains::load (const std::string &p) void SaltGrains::load (tl::InputStream &p) { + m_url.clear (); + tl::XMLStreamSource source (p); s_xml_struct.parse (source, *this); } void -SaltGrains::include (const std::string &src) +SaltGrains::include (const std::string &src_in) { - if (! src.empty ()) { + if (! src_in.empty ()) { + + std::string src = src_in; + + // base relative URL's on the parent URL + if (!m_url.empty () && src.find ("http:") != 0 && src.find ("https:") != 0 && src.find ("file:") != 0 && !src.empty() && src[0] != '/' && src[0] != '\\') { + + // replace the last component ("repository.xml") by the given path + QUrl url (tl::to_qstring (m_url)); + QStringList path_comp = url.path ().split (QString::fromUtf8 ("/")); + if (!path_comp.isEmpty ()) { + path_comp.back () = tl::to_qstring (src); + } + url.setPath (path_comp.join (QString::fromUtf8 ("/"))); + + src = tl::to_string (url.toString ()); + + } if (tl::verbosity () >= 20) { tl::log << "Including package index from " << src; diff --git a/src/lay/lay/laySaltGrains.h b/src/lay/lay/laySaltGrains.h index 0a5dceaa7..77605fcb7 100644 --- a/src/lay/lay/laySaltGrains.h +++ b/src/lay/lay/laySaltGrains.h @@ -210,6 +210,7 @@ private: std::string m_path; collections_type m_collections; grains_type m_grains; + std::string m_url; }; } diff --git a/src/tl/tl/tlHttpStream.cc b/src/tl/tl/tlHttpStream.cc index 0201ebb01..8d707d0a6 100644 --- a/src/tl/tl/tlHttpStream.cc +++ b/src/tl/tl/tlHttpStream.cc @@ -23,6 +23,7 @@ #include "tlHttpStream.h" #include "tlStaticObjects.h" +#include "tlDeferredExecution.h" #include "ui_PasswordDialog.h" @@ -185,6 +186,9 @@ InputHttpStream::issue_request (const QUrl &url) size_t InputHttpStream::read (char *b, size_t n) { + // Prevents deferred methods to be executed during the processEvents below (undesired side effects) + tl::NoDeferredMethods silent; + if (mp_reply == 0) { issue_request (QUrl (tl::to_qstring (m_url))); }