Skip to content

Commit

Permalink
Introducing sparse tag for salt mine repo to indicate it is not requi…
Browse files Browse the repository at this point in the history
…red to always download package information
  • Loading branch information
Matthias Koefferlein committed Oct 31, 2023
1 parent 579bee3 commit 880c8fb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/lay/lay/laySalt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "tlLog.h"
#include "tlInternational.h"
#include "tlWebDAV.h"
#include "tlEnv.h"
#if defined(HAVE_GIT2)
# include "tlGit.h"
#endif
Expand Down Expand Up @@ -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 ()
{
Expand Down
5 changes: 5 additions & 0 deletions src/lay/lay/laySalt.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ Q_OBJECT
*/
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
Expand Down
13 changes: 4 additions & 9 deletions src/lay/lay/laySaltDownloadManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 ()) {

Expand All @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/lay/lay/laySaltGrains.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace lay
{

SaltGrains::SaltGrains ()
: m_sparse (true)
{
// .. nothing yet ..
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -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 ());
Expand Down Expand Up @@ -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);

Expand Down
19 changes: 19 additions & 0 deletions src/lay/lay/laySaltGrains.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ class LAY_PUBLIC SaltGrains
*/
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
*
Expand Down Expand Up @@ -225,6 +243,7 @@ class LAY_PUBLIC SaltGrains
collections_type m_collections;
grains_type m_grains;
std::string m_url;
bool m_sparse;
};

}
Expand Down
10 changes: 1 addition & 9 deletions src/lay/lay/laySaltManagerDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 880c8fb

Please sign in to comment.