From 880c8fbb05499964525c7c42912dd6f5bf6810ba Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 31 Oct 2023 23:31:22 +0100 Subject: [PATCH] Introducing sparse tag for salt mine repo to indicate it is not required to always download package information --- src/lay/lay/laySalt.cc | 8 ++++++++ src/lay/lay/laySalt.h | 5 +++++ src/lay/lay/laySaltDownloadManager.cc | 13 ++++--------- src/lay/lay/laySaltGrains.cc | 11 +++++++++++ src/lay/lay/laySaltGrains.h | 19 +++++++++++++++++++ src/lay/lay/laySaltManagerDialog.cc | 10 +--------- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/lay/lay/laySalt.cc b/src/lay/lay/laySalt.cc index 2abf3c519..81267fa97 100644 --- a/src/lay/lay/laySalt.cc +++ b/src/lay/lay/laySalt.cc @@ -28,6 +28,7 @@ #include "tlLog.h" #include "tlInternational.h" #include "tlWebDAV.h" +#include "tlEnv.h" #if defined(HAVE_GIT2) # include "tlGit.h" #endif @@ -69,6 +70,13 @@ Salt::root () return m_root; } +bool +Salt::download_package_information () const +{ + // $KLAYOUT_ALWAYS_DOWNLOAD_PACKAGE_INFO + return tl::app_flag ("always-download-package-info") || m_root.sparse (); +} + Salt::flat_iterator Salt::begin_flat () { diff --git a/src/lay/lay/laySalt.h b/src/lay/lay/laySalt.h index 7970862a3..71c5a69d0 100644 --- a/src/lay/lay/laySalt.h +++ b/src/lay/lay/laySalt.h @@ -199,6 +199,11 @@ public: */ SaltGrains &root (); + /** + * @brief Gets a value indicating whether the collection wants package information to be downloaded always + */ + bool download_package_information () const; + signals: /** * @brief A signal triggered before one of the collections changed diff --git a/src/lay/lay/laySaltDownloadManager.cc b/src/lay/lay/laySaltDownloadManager.cc index ea0202810..559b59333 100644 --- a/src/lay/lay/laySaltDownloadManager.cc +++ b/src/lay/lay/laySaltDownloadManager.cc @@ -39,14 +39,6 @@ namespace lay // ---------------------------------------------------------------------------------- -static bool download_package_information () -{ - // $KLAYOUT_ALWAYS_DOWNLOAD_PACKAGE_INFO - return tl::app_flag ("always-download-package-info"); -} - -// ---------------------------------------------------------------------------------- - ConfirmationDialog::ConfirmationDialog (QWidget *parent) : QDialog (parent), m_confirmed (false), m_cancelled (false), m_aborted (false), m_file (50000, true) { @@ -327,6 +319,9 @@ SaltDownloadManager::fetch_missing (const lay::Salt &salt, const lay::Salt &salt // Downloading is required if: // - A package download is requested without a name (package can't be looked up in the package index) // - Or a name is given, but not found in the package index + // + // Downloading can be bypassed if the package index (salt mine) specifies "sparse=false". + // In that case, the package index will have all information about the package. if (! p->name.empty ()) { @@ -349,7 +344,7 @@ SaltDownloadManager::fetch_missing (const lay::Salt &salt, const lay::Salt &salt } - if (! p->downloaded && download_package_information ()) { + if (! p->downloaded && salt_mine.download_package_information ()) { // If requested, download package information to complete information from index or dependencies if (tl::verbosity() >= 10) { diff --git a/src/lay/lay/laySaltGrains.cc b/src/lay/lay/laySaltGrains.cc index bacb19d5f..846d8052c 100644 --- a/src/lay/lay/laySaltGrains.cc +++ b/src/lay/lay/laySaltGrains.cc @@ -34,6 +34,7 @@ namespace lay { SaltGrains::SaltGrains () + : m_sparse (true) { // .. nothing yet .. } @@ -54,6 +55,12 @@ SaltGrains::set_name (const std::string &n) m_name = n; } +void +SaltGrains::set_sparse (const bool &f) +{ + m_sparse = f; +} + void SaltGrains::set_title (const std::string &t) { @@ -302,6 +309,7 @@ SaltGrains::consolidate () static tl::XMLElementList s_group_struct = tl::make_member (&SaltGrains::name, &SaltGrains::set_name, "name") + + tl::make_member (&SaltGrains::sparse, &SaltGrains::set_sparse, "sparse") + tl::make_member (&SaltGrains::include, "include") + tl::make_element (&SaltGrains::begin_collections, &SaltGrains::end_collections, &SaltGrains::add_collection, "group", &s_group_struct) + tl::make_element (&SaltGrains::begin_grains, &SaltGrains::end_grains, &SaltGrains::add_grain, "salt-grain", SaltGrain::xml_elements ()); @@ -354,6 +362,9 @@ SaltGrains::include (const std::string &src_in) lay::SaltGrains g; g.load (src); + if (g.sparse ()) { + m_sparse = true; + } m_collections.splice (m_collections.end (), g.m_collections); m_grains.splice (m_grains.end (), g.m_grains); diff --git a/src/lay/lay/laySaltGrains.h b/src/lay/lay/laySaltGrains.h index a277e7863..c43e5fbaf 100644 --- a/src/lay/lay/laySaltGrains.h +++ b/src/lay/lay/laySaltGrains.h @@ -78,6 +78,24 @@ public: */ void set_name (const std::string &p); + /** + * @brief Gets a value indicating that the information in the grain collection is sparse + * + * If this flag is set to true (the default), the information in the collection needs + * to be completed by pulling the original definition of the grain for the grain's URL. + * If the flag is false, the information is complete and reflects the grain's original + * definition. + */ + const bool &sparse () const + { + return m_sparse; + } + + /** + * @brief Sets a value indicating that the information in the grain collection is sparse + */ + void set_sparse (const bool &f); + /** * @brief Gets the title of the grain collection * @@ -225,6 +243,7 @@ private: collections_type m_collections; grains_type m_grains; std::string m_url; + bool m_sparse; }; } diff --git a/src/lay/lay/laySaltManagerDialog.cc b/src/lay/lay/laySaltManagerDialog.cc index d78aa5ebe..4e86323bd 100644 --- a/src/lay/lay/laySaltManagerDialog.cc +++ b/src/lay/lay/laySaltManagerDialog.cc @@ -52,14 +52,6 @@ namespace lay // -------------------------------------------------------------------------------------- -static bool download_package_information () -{ - // $KLAYOUT_ALWAYS_DOWNLOAD_PACKAGE_INFO - return tl::app_flag ("always-download-package-info"); -} - -// -------------------------------------------------------------------------------------- - /** * @brief A tiny dialog to select a template and a name for the grain */ @@ -1238,7 +1230,7 @@ SaltManagerDialog::get_remote_grain_info (lay::SaltGrain *g, SaltGrainDetailsTex mp_downloaded_target = details; m_salt_mine_grain.reset (new lay::SaltGrain (*g)); - if (download_package_information ()) { + if (m_salt_mine.download_package_information () && m_salt_mine.grain_by_name (g->name ())) { // Download actual grain definition file try {