summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/configuration.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2014-02-24 23:10:25 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2014-03-13 13:57:34 +0100
commita5414e56403537678d5be87acf59c37a05f55719 (patch)
treee68d95ae7867e4723e4aa69f8a9ede1e36eb0df2 /apt-pkg/contrib/configuration.cc
parentfa19cc9573aac19cfbf43364d4b5660c9ab645bc (diff)
add default and override handling for Cnf::FindVector
Automatically handle the override of list options via its parent value which can even be a comma-separated list of values. It also adds an easy way of providing a default for the list.
Diffstat (limited to 'apt-pkg/contrib/configuration.cc')
-rw-r--r--apt-pkg/contrib/configuration.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 4ef4663c0..8eddd56d4 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -21,6 +21,7 @@
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/init.h>
#include <vector>
#include <fstream>
@@ -246,12 +247,18 @@ string Configuration::FindDir(const char *Name,const char *Default) const
// Configuration::FindVector - Find a vector of values /*{{{*/
// ---------------------------------------------------------------------
/* Returns a vector of config values under the given item */
-vector<string> Configuration::FindVector(const char *Name) const
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
+vector<string> Configuration::FindVector(const char *Name) const { return FindVector(Name, ""); }
+#endif
+vector<string> Configuration::FindVector(const char *Name, std::string const &Default) const
{
vector<string> Vec;
const Item *Top = Lookup(Name);
if (Top == NULL)
- return Vec;
+ return VectorizeString(Default, ',');
+
+ if (Top->Value.empty() == false)
+ return VectorizeString(Top->Value, ',');
Item *I = Top->Child;
while(I != NULL)
@@ -259,6 +266,9 @@ vector<string> Configuration::FindVector(const char *Name) const
Vec.push_back(I->Value);
I = I->Next;
}
+ if (Vec.empty() == true)
+ return VectorizeString(Default, ',');
+
return Vec;
}
/*}}}*/