From 12f9ad33f43457cb8ce08e21257155d02de6b5b5 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 5 Sep 2023 00:35:49 +0200 Subject: [PATCH] Some enhancements to package manager - So not update macros while installing: avoids transient error messages - Offer to autorun macros also after package update (so far only on package new installation) --- src/lay/lay/layMacroController.cc | 50 ++++++++++++++++++++----------- src/lay/lay/layMacroController.h | 5 ++-- src/lay/lay/laySaltController.cc | 29 +++++++++++++----- src/layui/layui/layBusy.cc | 6 ++++ src/tl/tl/tlFileSystemWatcher.cc | 17 +++++++++++ src/tl/tl/tlFileSystemWatcher.h | 5 ++++ 6 files changed, 85 insertions(+), 27 deletions(-) diff --git a/src/lay/lay/layMacroController.cc b/src/lay/lay/layMacroController.cc index a4cce73de..e3f3dbb76 100644 --- a/src/lay/lay/layMacroController.cc +++ b/src/lay/lay/layMacroController.cc @@ -385,9 +385,9 @@ MacroController::sync_implicit_macros (bool ask_before_autorun) } else { // determine the paths currently in use - std::map prev_folders_by_path; + std::map prev_folders_by_path; for (std::vector::const_iterator p = m_external_paths.begin (); p != m_external_paths.end (); ++p) { - prev_folders_by_path.insert (std::make_pair (p->path, p.operator-> ())); + prev_folders_by_path.insert (std::make_pair (p->path, *p)); } // gets the external paths (tech, packages) into m_external_paths @@ -433,23 +433,39 @@ MacroController::sync_implicit_macros (bool ask_before_autorun) for (std::vector::const_iterator p = m_external_paths.begin (); p != m_external_paths.end (); ++p) { - if (prev_folders_by_path.find (p->path) != prev_folders_by_path.end ()) { - continue; - } + auto pf = prev_folders_by_path.find (p->path); + if (pf != prev_folders_by_path.end ()) { - if (tl::verbosity () >= 20) { - tl::info << "Adding macro folder " << p->path << ", category '" << p->cat << "' for '" << p->description << "'"; - } + if (pf->second.version != p->version) { - // Add the folder. Note: it may happen that a macro folder for the tech specific macros already exists in - // a non-tech context. - // In that case, the add_folder method will return 0. + if (tl::verbosity () >= 20) { + tl::info << "New version (" << p->version << " vs. " << pf->second.version << ") of macro folder " << p->path << ", category '" << p->cat << "' for '" << p->description << "'"; + } + + lym::MacroCollection *mc = lym::MacroCollection::root ().folder_by_name (p->path); + if (mc) { + new_folders.push_back (mc); + } + + } + + } else { + + if (tl::verbosity () >= 20) { + tl::info << "Adding macro folder " << p->path << ", category '" << p->cat << "' for '" << p->description << "'"; + } + + // Add the folder. Note: it may happen that a macro folder for the tech specific macros already exists in + // a non-tech context. + // In that case, the add_folder method will return 0. + + // TODO: is it wise to make this writeable? + lym::MacroCollection *mc = lym::MacroCollection::root ().add_folder (p->description, p->path, p->cat, p->readonly); + if (mc) { + mc->set_virtual_mode (p->type); + new_folders.push_back (mc); + } - // TODO: is it wise to make this writeable? - lym::MacroCollection *mc = lym::MacroCollection::root ().add_folder (p->description, p->path, p->cat, p->readonly); - if (mc) { - mc->set_virtual_mode (p->type); - new_folders.push_back (mc); } } @@ -565,7 +581,7 @@ MacroController::sync_macro_sources () if (*f != macro_categories () [c].name) { description += " - " + tl::to_string (tr ("%1 branch").arg (tl::to_qstring (*f))); } - external_paths.push_back (ExternalPathDescriptor (tl::to_string (macro_dir.path ()), description, macro_categories () [c].name, lym::MacroCollection::SaltFolder, g->is_readonly ())); + external_paths.push_back (ExternalPathDescriptor (tl::to_string (macro_dir.path ()), description, macro_categories () [c].name, lym::MacroCollection::SaltFolder, g->is_readonly (), g->version ())); } diff --git a/src/lay/lay/layMacroController.h b/src/lay/lay/layMacroController.h index e7a8c3a84..26e4674e7 100644 --- a/src/lay/lay/layMacroController.h +++ b/src/lay/lay/layMacroController.h @@ -204,8 +204,8 @@ private: */ struct ExternalPathDescriptor { - ExternalPathDescriptor (const std::string &_path, const std::string &_description, const std::string &_cat, lym::MacroCollection::FolderType _type, bool _readonly) - : path (_path), description (_description), cat (_cat), type (_type), readonly (_readonly) + ExternalPathDescriptor (const std::string &_path, const std::string &_description, const std::string &_cat, lym::MacroCollection::FolderType _type, bool _readonly, const std::string &_version = std::string ()) + : path (_path), description (_description), cat (_cat), type (_type), version (_version), readonly (_readonly) { // .. nothing yet .. } @@ -214,6 +214,7 @@ private: std::string description; std::string cat; lym::MacroCollection::FolderType type; + std::string version; bool readonly; }; diff --git a/src/lay/lay/laySaltController.cc b/src/lay/lay/laySaltController.cc index 8dc078c4f..7c99e30db 100644 --- a/src/lay/lay/laySaltController.cc +++ b/src/lay/lay/laySaltController.cc @@ -26,6 +26,7 @@ #include "layConfig.h" #include "layMainWindow.h" #include "layQtTools.h" +#include "layBusy.h" #include "tlLog.h" #include @@ -138,11 +139,12 @@ SaltController::show_editor () lay::restore_dialog_state (mp_salt_dialog, s); } - // while running the dialog, don't watch file events - that would interfere with - // the changes applied by the dialog itself. - m_file_watcher->enable (false); - mp_salt_dialog->exec (); - m_file_watcher->enable (true); + { + // while running the dialog, don't watch file events - that would interfere with + // the changes applied by the dialog itself. + lay::BusySection busy_section; // disable file watcher + mp_salt_dialog->exec (); + } mp_plugin_root->config_set (cfg_salt_manager_window_state, lay::save_dialog_state (mp_salt_dialog)); @@ -154,13 +156,13 @@ SaltController::show_editor () void SaltController::sync_file_watcher () { + lay::BusySection busy_section; // disable file watcher + if (m_file_watcher) { m_file_watcher->clear (); - m_file_watcher->enable (false); for (lay::Salt::flat_iterator g = m_salt.begin_flat (); g != m_salt.end_flat (); ++g) { m_file_watcher->add_file ((*g)->path ()); } - m_file_watcher->enable (true); } } @@ -216,7 +218,18 @@ SaltController::install_packages (const std::vector &packages, bool manager.compute_packages (m_salt, salt_mine); } - return manager.execute (0, m_salt); + bool result = false; + + { + // while running the dialog, don't watch file events - that would interfere with + // the changes applied by the dialog itself. + lay::BusySection busy_section; // disable file watcher + result = manager.execute (0, m_salt); + } + + sync_file_watcher (); + + return result; } void diff --git a/src/layui/layui/layBusy.cc b/src/layui/layui/layBusy.cc index f03c8b5c2..097151f4c 100644 --- a/src/layui/layui/layBusy.cc +++ b/src/layui/layui/layBusy.cc @@ -24,6 +24,7 @@ #include "layBusy.h" #include "tlThreads.h" +#include "tlFileSystemWatcher.h" namespace lay { @@ -61,6 +62,9 @@ BusySection::BusySection () m_previous_mode = mp_busy_mode->is_busy (); mp_busy_mode->enter_busy_mode (true); } + + // disable file system watchers during busy periods + tl::FileSystemWatcher::global_enable (false); } BusySection::~BusySection () @@ -70,6 +74,8 @@ BusySection::~BusySection () mp_busy_mode->enter_busy_mode (m_previous_mode); } mp_busy_mode = 0; + + tl::FileSystemWatcher::global_enable (true); } bool diff --git a/src/tl/tl/tlFileSystemWatcher.cc b/src/tl/tl/tlFileSystemWatcher.cc index 57a099a62..59219547d 100644 --- a/src/tl/tl/tlFileSystemWatcher.cc +++ b/src/tl/tl/tlFileSystemWatcher.cc @@ -31,6 +31,9 @@ namespace tl { +// The global enable counter (<0: disable) +static int s_global_enable = 0; + // The maximum allowed processing time in seconds const double processing_time = 0.02; @@ -47,6 +50,16 @@ FileSystemWatcher::FileSystemWatcher (QObject *parent) m_batch_size = 1000; } +void +FileSystemWatcher::global_enable (bool en) +{ + if (en) { + ++s_global_enable; + } else { + --s_global_enable; + } +} + void FileSystemWatcher::enable (bool en) { @@ -120,6 +133,10 @@ FileSystemWatcher::remove_file (const std::string &path) void FileSystemWatcher::timeout () { + if (s_global_enable < 0) { + return; + } + tl::Clock start = tl::Clock::current (); if (m_iter == m_files.end ()) { diff --git a/src/tl/tl/tlFileSystemWatcher.h b/src/tl/tl/tlFileSystemWatcher.h index 22e2a448b..f6190f208 100644 --- a/src/tl/tl/tlFileSystemWatcher.h +++ b/src/tl/tl/tlFileSystemWatcher.h @@ -57,6 +57,11 @@ public: */ FileSystemWatcher (QObject *parent = 0); + /** + * @brief Global enable/disable + */ + static void global_enable (bool en); + /** * @brief Enables or disables the file watcher */