summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-06-11 16:40:45 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-06-11 16:49:29 +0200
commit8881b11eacd735148d087c8c0f53827cb537b582 (patch)
treeb8b0706b1afeaf9d4022cd845025014fbabcbffb /apt-pkg
parent001c76fe204e17916a6c8b351ff30b67d32cb779 (diff)
implement 'apt-get files' to access index targets
Downloading additional files is only half the job. We still need a way to allow external tools to know where the files are they requested for download given that we don't want them to choose their own location. 'apt-get files' is our answer to this showing by default in a deb822 format information about each IndexTarget with the potential to filter the records based on lines and an option to change the output format. The command serves also as an example on how to get to this information via libapt.
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/deb/debmetaindex.cc17
-rw-r--r--apt-pkg/indexfile.cc18
-rw-r--r--apt-pkg/indexfile.h3
3 files changed, 32 insertions, 6 deletions
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index c05e7cdae..8e4c2be2d 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -136,11 +136,14 @@ void foreachTarget(std::string const URI, std::string const Dist,
std::map<std::string, std::string> Options;
Options.insert(std::make_pair("SITE", Site));
Options.insert(std::make_pair("RELEASE", Release));
- Options.insert(std::make_pair("COMPONENT", (*I)->Section));
- Options.insert(std::make_pair("LANGUAGE", *l));
+ if (MetaKey.find("$(COMPONENT)") != std::string::npos)
+ Options.insert(std::make_pair("COMPONENT", (*I)->Section));
+ if (MetaKey.find("$(LANGUAGE)") != std::string::npos)
+ Options.insert(std::make_pair("LANGUAGE", *l));
Options.insert(std::make_pair("ARCHITECTURE", "source"));
Options.insert(std::make_pair("BASE_URI", baseURI));
Options.insert(std::make_pair("REPO_URI", URI));
+ Options.insert(std::make_pair("TARGET_OF", "deb-src"));
Options.insert(std::make_pair("CREATED_BY", *T));
Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options);
@@ -183,11 +186,15 @@ void foreachTarget(std::string const URI, std::string const Dist,
std::map<std::string, std::string> Options;
Options.insert(std::make_pair("SITE", Site));
Options.insert(std::make_pair("RELEASE", Release));
- Options.insert(std::make_pair("COMPONENT", (*I)->Section));
- Options.insert(std::make_pair("LANGUAGE", *l));
- Options.insert(std::make_pair("ARCHITECTURE", a->first));
+ if (MetaKey.find("$(COMPONENT)") != std::string::npos)
+ Options.insert(std::make_pair("COMPONENT", (*I)->Section));
+ if (MetaKey.find("$(LANGUAGE)") != std::string::npos)
+ Options.insert(std::make_pair("LANGUAGE", *l));
+ if (MetaKey.find("$(ARCHITECTURE)") != std::string::npos)
+ Options.insert(std::make_pair("ARCHITECTURE", a->first));
Options.insert(std::make_pair("BASE_URI", baseURI));
Options.insert(std::make_pair("REPO_URI", URI));
+ Options.insert(std::make_pair("TARGET_OF", "deb"));
Options.insert(std::make_pair("CREATED_BY", *T));
Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options);
diff --git a/apt-pkg/indexfile.cc b/apt-pkg/indexfile.cc
index 72d35ddcc..33fb48e35 100644
--- a/apt-pkg/indexfile.cc
+++ b/apt-pkg/indexfile.cc
@@ -133,8 +133,10 @@ std::string IndexTarget::Option(OptionKeys const EnumKey) const /*{{{*/
APT_CASE(ARCHITECTURE);
APT_CASE(BASE_URI);
APT_CASE(REPO_URI);
+ APT_CASE(TARGET_OF);
APT_CASE(CREATED_BY);
#undef APT_CASE
+ case FILENAME: return _config->FindDir("Dir::State::lists") + URItoFileName(URI);
}
std::map<std::string,std::string>::const_iterator const M = Options.find(Key);
if (M == Options.end())
@@ -142,6 +144,20 @@ std::string IndexTarget::Option(OptionKeys const EnumKey) const /*{{{*/
return M->second;
}
/*}}}*/
+std::string IndexTarget::Format(std::string format) const /*{{{*/
+{
+ for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O)
+ {
+ format = SubstVar(format, std::string("$(") + O->first + ")", O->second);
+ }
+ format = SubstVar(format, "$(METAKEY)", MetaKey);
+ format = SubstVar(format, "$(SHORTDESC)", ShortDesc);
+ format = SubstVar(format, "$(DESCRIPTION)", Description);
+ format = SubstVar(format, "$(URI)", URI);
+ format = SubstVar(format, "$(FILENAME)", Option(IndexTarget::FILENAME));
+ return format;
+}
+ /*}}}*/
pkgIndexTargetFile::pkgIndexTargetFile(IndexTarget const &Target, bool const Trusted) :/*{{{*/
pkgIndexFile(Trusted), Target(Target)
@@ -162,7 +178,7 @@ std::string pkgIndexTargetFile::Describe(bool Short) const /*{{{*/
/*}}}*/
std::string pkgIndexTargetFile::IndexFileName() const /*{{{*/
{
- std::string const s =_config->FindDir("Dir::State::lists") + URItoFileName(Target.URI);
+ std::string const s = Target.Option(IndexTarget::FILENAME);
if (FileExists(s))
return s;
diff --git a/apt-pkg/indexfile.h b/apt-pkg/indexfile.h
index c38cf0bf0..220c415ac 100644
--- a/apt-pkg/indexfile.h
+++ b/apt-pkg/indexfile.h
@@ -79,8 +79,11 @@ class IndexTarget /*{{{*/
BASE_URI,
REPO_URI,
CREATED_BY,
+ TARGET_OF,
+ FILENAME,
};
std::string Option(OptionKeys const Key) const;
+ std::string Format(std::string format) const;
};
/*}}}*/