]>
git.saurik.com Git - apt.git/blob - apt-pkg/indexfile.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: indexfile.cc,v 1.2.2.1 2003/12/24 23:09:17 mdz Exp $
4 /* ######################################################################
6 Index File - Abstraction for an index of archive/souce file.
8 ##################################################################### */
10 // Include Files /*{{{*/
13 #include <apt-pkg/configuration.h>
14 #include <apt-pkg/indexfile.h>
15 #include <apt-pkg/error.h>
16 #include <apt-pkg/fileutl.h>
17 #include <apt-pkg/aptconfiguration.h>
18 #include <apt-pkg/pkgcache.h>
19 #include <apt-pkg/cacheiterators.h>
20 #include <apt-pkg/srcrecords.h>
21 #include <apt-pkg/macros.h>
29 // Global list of Item supported
30 static pkgIndexFile::Type
*ItmList
[10];
31 pkgIndexFile::Type
**pkgIndexFile::Type::GlobalList
= ItmList
;
32 unsigned long pkgIndexFile::Type::GlobalListLen
= 0;
34 // Type::Type - Constructor /*{{{*/
35 // ---------------------------------------------------------------------
37 pkgIndexFile::Type::Type()
39 ItmList
[GlobalListLen
] = this;
44 // Type::GetType - Locate the type by name /*{{{*/
45 // ---------------------------------------------------------------------
47 pkgIndexFile::Type
*pkgIndexFile::Type::GetType(const char *Type
)
49 for (unsigned I
= 0; I
!= GlobalListLen
; I
++)
50 if (strcmp(GlobalList
[I
]->Label
,Type
) == 0)
55 pkgIndexFile::pkgIndexFile(bool Trusted
) : /*{{{*/
56 d(NULL
), Trusted(Trusted
)
60 // IndexFile::ArchiveInfo - Stub /*{{{*/
61 std::string
pkgIndexFile::ArchiveInfo(pkgCache::VerIterator
/*Ver*/) const
66 // IndexFile::FindInCache - Stub /*{{{*/
67 pkgCache::PkgFileIterator
pkgIndexFile::FindInCache(pkgCache
&Cache
) const
69 return pkgCache::PkgFileIterator(Cache
);
72 // IndexFile::SourceIndex - Stub /*{{{*/
73 std::string
pkgIndexFile::SourceInfo(pkgSrcRecords::Parser
const &/*Record*/,
74 pkgSrcRecords::File
const &/*File*/) const
79 // IndexFile::TranslationsAvailable - Check if will use Translation /*{{{*/
80 // ---------------------------------------------------------------------
82 bool pkgIndexFile::TranslationsAvailable() {
83 return (APT::Configuration::getLanguages().empty() != true);
86 // IndexFile::CheckLanguageCode - Check the Language Code /*{{{*/
87 // ---------------------------------------------------------------------
88 /* No intern need for this method anymore as the check for correctness
89 is already done in getLanguages(). Note also that this check is
90 rather bad (doesn't take three character like ast into account).
91 TODO: Remove method with next API break */
92 APT_DEPRECATED
bool pkgIndexFile::CheckLanguageCode(const char *Lang
)
94 if (strlen(Lang
) == 2 || (strlen(Lang
) == 5 && Lang
[2] == '_'))
97 if (strcmp(Lang
,"C") != 0)
98 _error
->Warning("Wrong language code %s", Lang
);
103 // IndexFile::LanguageCode - Return the Language Code /*{{{*/
104 // ---------------------------------------------------------------------
105 /* As we have now possibly more than one LanguageCode this method is
106 supersided by a) private classmembers or b) getLanguages().
107 TODO: Remove method with next API break */
108 APT_DEPRECATED
std::string
pkgIndexFile::LanguageCode() {
109 if (TranslationsAvailable() == false)
111 return APT::Configuration::getLanguages()[0];
115 // IndexTarget - Constructor /*{{{*/
116 IndexTarget::IndexTarget(std::string
const &MetaKey
, std::string
const &ShortDesc
,
117 std::string
const &LongDesc
, std::string
const &URI
, bool const IsOptional
,
118 bool const KeepCompressed
, std::map
<std::string
, std::string
> const &Options
) :
119 URI(URI
), Description(LongDesc
), ShortDesc(ShortDesc
), MetaKey(MetaKey
),
120 IsOptional(IsOptional
), KeepCompressed(KeepCompressed
), Options(Options
)
124 std::string
IndexTarget::Option(OptionKeys
const EnumKey
) const /*{{{*/
129 #define APT_CASE(X) case X: Key = #X; break
134 APT_CASE(ARCHITECTURE
);
138 APT_CASE(CREATED_BY
);
140 case FILENAME
: return _config
->FindDir("Dir::State::lists") + URItoFileName(URI
);
141 case EXISTING_FILENAME
:
142 std::string
const filename
= Option(FILENAME
);
143 std::vector
<std::string
> const types
= APT::Configuration::getCompressionTypes();
144 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
148 std::string
const file
= (*t
== "uncompressed") ? filename
: (filename
+ "." + *t
);
149 if (FileExists(file
))
154 std::map
<std::string
,std::string
>::const_iterator
const M
= Options
.find(Key
);
155 if (M
== Options
.end())
160 std::string
IndexTarget::Format(std::string format
) const /*{{{*/
162 for (std::map
<std::string
, std::string
>::const_iterator O
= Options
.begin(); O
!= Options
.end(); ++O
)
164 format
= SubstVar(format
, std::string("$(") + O
->first
+ ")", O
->second
);
166 format
= SubstVar(format
, "$(METAKEY)", MetaKey
);
167 format
= SubstVar(format
, "$(SHORTDESC)", ShortDesc
);
168 format
= SubstVar(format
, "$(DESCRIPTION)", Description
);
169 format
= SubstVar(format
, "$(URI)", URI
);
170 format
= SubstVar(format
, "$(FILENAME)", Option(IndexTarget::FILENAME
));
175 pkgIndexTargetFile::pkgIndexTargetFile(IndexTarget
const &Target
, bool const Trusted
) :/*{{{*/
176 pkgIndexFile(Trusted
), d(NULL
), Target(Target
)
180 std::string
pkgIndexTargetFile::ArchiveURI(std::string File
) const/*{{{*/
182 return Target
.Option(IndexTarget::REPO_URI
) + File
;
185 std::string
pkgIndexTargetFile::Describe(bool Short
) const /*{{{*/
188 return Target
.Description
;
189 return Target
.Description
+ " (" + IndexFileName() + ")";
192 std::string
pkgIndexTargetFile::IndexFileName() const /*{{{*/
194 std::string
const s
= Target
.Option(IndexTarget::FILENAME
);
198 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
199 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
201 std::string p
= s
+ '.' + *t
;
208 unsigned long pkgIndexTargetFile::Size() const /*{{{*/
210 unsigned long size
= 0;
212 /* we need to ignore errors here; if the lists are absent, just return 0 */
213 _error
->PushToStack();
215 FileFd
f(IndexFileName(), FileFd::ReadOnly
, FileFd::Extension
);
219 if (_error
->PendingError() == true)
221 _error
->RevertToStack();
226 bool pkgIndexTargetFile::Exists() const /*{{{*/
228 return FileExists(IndexFileName());
232 APT_CONST
pkgIndexFile::~pkgIndexFile() {}
233 APT_CONST
pkgIndexTargetFile::~pkgIndexTargetFile() {}