]> git.saurik.com Git - apt.git/blame_incremental - apt-pkg/metaindex.cc
Introduce tolower_ascii_unsafe() and use it for hashing
[apt.git] / apt-pkg / metaindex.cc
... / ...
CommitLineData
1// Include Files /*{{{*/
2#include <apt-pkg/pkgcachegen.h>
3#include <apt-pkg/indexfile.h>
4#include <apt-pkg/metaindex.h>
5
6#include <apt-pkg/debmetaindex.h>
7
8#include <string>
9#include <vector>
10 /*}}}*/
11
12std::string metaIndex::Describe() const
13{
14 return "Release";
15}
16
17pkgCache::RlsFileIterator metaIndex::FindInCache(pkgCache &Cache, bool const) const
18{
19 return pkgCache::RlsFileIterator(Cache);
20}
21
22bool metaIndex::Merge(pkgCacheGenerator &Gen,OpProgress *) const
23{
24 return Gen.SelectReleaseFile("", "");
25}
26
27metaIndex::metaIndex(std::string const &URI, std::string const &Dist,
28 char const * const Type)
29: d(NULL), Indexes(NULL), Type(Type), URI(URI), Dist(Dist), Trusted(TRI_UNSET),
30 Date(0), ValidUntil(0), SupportsAcquireByHash(false), LoadedSuccessfully(TRI_UNSET)
31{
32 /* nothing */
33}
34
35metaIndex::~metaIndex()
36{
37 if (Indexes != 0)
38 {
39 for (std::vector<pkgIndexFile *>::iterator I = (*Indexes).begin();
40 I != (*Indexes).end(); ++I)
41 delete *I;
42 delete Indexes;
43 }
44 for (auto const &E: Entries)
45 delete E.second;
46}
47
48// one line Getters for public fields /*{{{*/
49APT_PURE std::string metaIndex::GetURI() const { return URI; }
50APT_PURE std::string metaIndex::GetDist() const { return Dist; }
51APT_PURE const char* metaIndex::GetType() const { return Type; }
52APT_PURE metaIndex::TriState metaIndex::GetTrusted() const { return Trusted; }
53APT_PURE std::string metaIndex::GetSignedBy() const { return SignedBy; }
54APT_PURE std::string metaIndex::GetCodename() const { return Codename; }
55APT_PURE std::string metaIndex::GetSuite() const { return Suite; }
56APT_PURE bool metaIndex::GetSupportsAcquireByHash() const { return SupportsAcquireByHash; }
57APT_PURE time_t metaIndex::GetValidUntil() const { return ValidUntil; }
58APT_PURE time_t metaIndex::GetDate() const { return this->Date; }
59APT_PURE metaIndex::TriState metaIndex::GetLoadedSuccessfully() const { return LoadedSuccessfully; }
60APT_PURE std::string metaIndex::GetExpectedDist() const { return Dist; }
61 /*}}}*/
62bool metaIndex::CheckDist(string const &MaybeDist) const /*{{{*/
63{
64 if (MaybeDist.empty() || this->Codename == MaybeDist || this->Suite == MaybeDist)
65 return true;
66
67 std::string Transformed = MaybeDist;
68 if (Transformed == "../project/experimental")
69 Transformed = "experimental";
70
71 auto const pos = Transformed.rfind('/');
72 if (pos != string::npos)
73 Transformed = Transformed.substr(0, pos);
74
75 if (Transformed == ".")
76 Transformed.clear();
77
78 return Transformed.empty() || this->Codename == Transformed || this->Suite == Transformed;
79}
80 /*}}}*/
81APT_PURE metaIndex::checkSum *metaIndex::Lookup(string const &MetaKey) const /*{{{*/
82{
83 std::map<std::string, metaIndex::checkSum* >::const_iterator sum = Entries.find(MetaKey);
84 if (sum == Entries.end())
85 return NULL;
86 return sum->second;
87}
88 /*}}}*/
89APT_PURE bool metaIndex::Exists(string const &MetaKey) const /*{{{*/
90{
91 return Entries.find(MetaKey) != Entries.end();
92}
93 /*}}}*/
94std::vector<std::string> metaIndex::MetaKeys() const /*{{{*/
95{
96 std::vector<std::string> keys;
97 std::map<string,checkSum *>::const_iterator I = Entries.begin();
98 while(I != Entries.end()) {
99 keys.push_back((*I).first);
100 ++I;
101 }
102 return keys;
103}
104 /*}}}*/
105void metaIndex::swapLoad(metaIndex * const OldMetaIndex) /*{{{*/
106{
107 std::swap(Entries, OldMetaIndex->Entries);
108 std::swap(Date, OldMetaIndex->Date);
109 std::swap(ValidUntil, OldMetaIndex->ValidUntil);
110 std::swap(SupportsAcquireByHash, OldMetaIndex->SupportsAcquireByHash);
111 std::swap(LoadedSuccessfully, OldMetaIndex->LoadedSuccessfully);
112}
113 /*}}}*/
114
115bool metaIndex::IsArchitectureSupported(std::string const &arch) const /*{{{*/
116{
117 debReleaseIndex const * const deb = dynamic_cast<debReleaseIndex const *>(this);
118 if (deb != NULL)
119 return deb->IsArchitectureSupported(arch);
120 return true;
121}
122 /*}}}*/
123bool metaIndex::IsArchitectureAllSupportedFor(IndexTarget const &target) const/*{{{*/
124{
125 debReleaseIndex const * const deb = dynamic_cast<debReleaseIndex const *>(this);
126 if (deb != NULL)
127 return deb->IsArchitectureAllSupportedFor(target);
128 return true;
129}
130 /*}}}*/