]>
Commit | Line | Data |
---|---|---|
b2e465d6 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
7db98ffc | 3 | // $Id: debindexfile.cc,v 1.5.2.3 2004/01/04 19:11:00 mdz Exp $ |
b2e465d6 AL |
4 | /* ###################################################################### |
5 | ||
6 | Debian Specific sources.list types and the three sorts of Debian | |
7 | index files. | |
8 | ||
9 | ##################################################################### */ | |
10 | /*}}}*/ | |
11 | // Include Files /*{{{*/ | |
ea542140 DK |
12 | #include <config.h> |
13 | ||
b2e465d6 AL |
14 | #include <apt-pkg/debindexfile.h> |
15 | #include <apt-pkg/debsrcrecords.h> | |
16 | #include <apt-pkg/deblistparser.h> | |
17 | #include <apt-pkg/debrecords.h> | |
b2e465d6 AL |
18 | #include <apt-pkg/configuration.h> |
19 | #include <apt-pkg/progress.h> | |
20 | #include <apt-pkg/error.h> | |
21 | #include <apt-pkg/strutl.h> | |
22 | #include <apt-pkg/acquire-item.h> | |
7db98ffc | 23 | #include <apt-pkg/debmetaindex.h> |
233b7808 | 24 | #include <apt-pkg/gpgv.h> |
453b82a3 DK |
25 | #include <apt-pkg/fileutl.h> |
26 | #include <apt-pkg/indexfile.h> | |
27 | #include <apt-pkg/mmap.h> | |
28 | #include <apt-pkg/pkgcache.h> | |
29 | #include <apt-pkg/cacheiterators.h> | |
30 | #include <apt-pkg/pkgcachegen.h> | |
31 | #include <apt-pkg/pkgrecords.h> | |
32 | #include <apt-pkg/srcrecords.h> | |
e011829d | 33 | |
453b82a3 DK |
34 | #include <stdio.h> |
35 | #include <iostream> | |
36 | #include <string> | |
b2e465d6 AL |
37 | #include <sys/stat.h> |
38 | /*}}}*/ | |
39 | ||
73688d27 DK |
40 | using std::string; |
41 | ||
b2e465d6 AL |
42 | // SourcesIndex::debSourcesIndex - Constructor /*{{{*/ |
43 | // --------------------------------------------------------------------- | |
44 | /* */ | |
7db98ffc MZ |
45 | debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trusted) : |
46 | pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section) | |
b2e465d6 AL |
47 | { |
48 | } | |
49 | /*}}}*/ | |
50 | // SourcesIndex::SourceInfo - Short 1 liner describing a source /*{{{*/ | |
51 | // --------------------------------------------------------------------- | |
52 | /* The result looks like: | |
5e02df82 | 53 | http://foo/debian/ stable/main src 1.1.1 (dsc) */ |
b2e465d6 AL |
54 | string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, |
55 | pkgSrcRecords::File const &File) const | |
56 | { | |
57 | string Res; | |
5e02df82 | 58 | Res = ::URI::NoUserPassword(URI) + ' '; |
b2e465d6 AL |
59 | if (Dist[Dist.size() - 1] == '/') |
60 | { | |
61 | if (Dist != "/") | |
62 | Res += Dist; | |
63 | } | |
64 | else | |
65 | Res += Dist + '/' + Section; | |
66 | ||
67 | Res += " "; | |
68 | Res += Record.Package(); | |
69 | Res += " "; | |
70 | Res += Record.Version(); | |
71 | if (File.Type.empty() == false) | |
72 | Res += " (" + File.Type + ")"; | |
73 | return Res; | |
74 | } | |
75 | /*}}}*/ | |
76 | // SourcesIndex::CreateSrcParser - Get a parser for the source files /*{{{*/ | |
77 | // --------------------------------------------------------------------- | |
78 | /* */ | |
79 | pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const | |
80 | { | |
94e8c9d4 | 81 | string SourcesURI = _config->FindDir("Dir::State::lists") + |
82 | URItoFileName(IndexURI("Sources")); | |
83 | string SourcesURIgzip = SourcesURI + ".gz"; | |
1aadba5a MV |
84 | |
85 | if (!FileExists(SourcesURI) && !FileExists(SourcesURIgzip)) | |
86 | return NULL; | |
87 | else if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip)) | |
94e8c9d4 | 88 | SourcesURI = SourcesURIgzip; |
89 | ||
90 | return new debSrcRecordParser(SourcesURI,this); | |
b2e465d6 AL |
91 | } |
92 | /*}}}*/ | |
93 | // SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/ | |
94 | // --------------------------------------------------------------------- | |
95 | /* */ | |
af87ab54 | 96 | string debSourcesIndex::Describe(bool Short) const |
b2e465d6 AL |
97 | { |
98 | char S[300]; | |
af87ab54 | 99 | if (Short == true) |
cc742108 | 100 | snprintf(S,sizeof(S),"%s",Info("Sources").c_str()); |
af87ab54 | 101 | else |
cc742108 | 102 | snprintf(S,sizeof(S),"%s (%s)",Info("Sources").c_str(), |
af87ab54 AL |
103 | IndexFile("Sources").c_str()); |
104 | ||
b2e465d6 AL |
105 | return S; |
106 | } | |
107 | /*}}}*/ | |
108 | // SourcesIndex::Info - One liner describing the index URI /*{{{*/ | |
109 | // --------------------------------------------------------------------- | |
110 | /* */ | |
111 | string debSourcesIndex::Info(const char *Type) const | |
112 | { | |
5e02df82 | 113 | string Info = ::URI::NoUserPassword(URI) + ' '; |
b2e465d6 AL |
114 | if (Dist[Dist.size() - 1] == '/') |
115 | { | |
116 | if (Dist != "/") | |
117 | Info += Dist; | |
118 | } | |
119 | else | |
120 | Info += Dist + '/' + Section; | |
121 | Info += " "; | |
122 | Info += Type; | |
123 | return Info; | |
124 | } | |
125 | /*}}}*/ | |
126 | // SourcesIndex::Index* - Return the URI to the index files /*{{{*/ | |
127 | // --------------------------------------------------------------------- | |
128 | /* */ | |
129 | inline string debSourcesIndex::IndexFile(const char *Type) const | |
130 | { | |
ec7a129e | 131 | string s = URItoFileName(IndexURI(Type)); |
132 | string sgzip = s + ".gz"; | |
133 | if (!FileExists(s) && FileExists(sgzip)) | |
134 | return sgzip; | |
135 | else | |
136 | return s; | |
b2e465d6 | 137 | } |
ec7a129e | 138 | |
b2e465d6 AL |
139 | string debSourcesIndex::IndexURI(const char *Type) const |
140 | { | |
141 | string Res; | |
142 | if (Dist[Dist.size() - 1] == '/') | |
143 | { | |
144 | if (Dist != "/") | |
145 | Res = URI + Dist; | |
146 | else | |
147 | Res = URI; | |
148 | } | |
149 | else | |
150 | Res = URI + "dists/" + Dist + '/' + Section + | |
151 | "/source/"; | |
152 | ||
153 | Res += Type; | |
154 | return Res; | |
155 | } | |
156 | /*}}}*/ | |
b2e465d6 AL |
157 | // SourcesIndex::Exists - Check if the index is available /*{{{*/ |
158 | // --------------------------------------------------------------------- | |
159 | /* */ | |
160 | bool debSourcesIndex::Exists() const | |
161 | { | |
162 | return FileExists(IndexFile("Sources")); | |
163 | } | |
164 | /*}}}*/ | |
165 | // SourcesIndex::Size - Return the size of the index /*{{{*/ | |
166 | // --------------------------------------------------------------------- | |
167 | /* */ | |
168 | unsigned long debSourcesIndex::Size() const | |
169 | { | |
915f0520 MP |
170 | unsigned long size = 0; |
171 | ||
172 | /* we need to ignore errors here; if the lists are absent, just return 0 */ | |
173 | _error->PushToStack(); | |
174 | ||
f0e83599 | 175 | FileFd f(IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension); |
915f0520 MP |
176 | if (!f.Failed()) |
177 | size = f.Size(); | |
178 | ||
179 | if (_error->PendingError() == true) | |
180 | size = 0; | |
181 | _error->RevertToStack(); | |
5473df3f | 182 | |
915f0520 | 183 | return size; |
b2e465d6 AL |
184 | } |
185 | /*}}}*/ | |
186 | ||
187 | // PackagesIndex::debPackagesIndex - Contructor /*{{{*/ | |
188 | // --------------------------------------------------------------------- | |
189 | /* */ | |
5dd4c8b8 DK |
190 | debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string const &Section, |
191 | bool const &Trusted, string const &Arch) : | |
192 | pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section), Architecture(Arch) | |
b2e465d6 | 193 | { |
5dd4c8b8 DK |
194 | if (Architecture == "native") |
195 | Architecture = _config->Find("APT::Architecture"); | |
b2e465d6 AL |
196 | } |
197 | /*}}}*/ | |
198 | // PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/ | |
199 | // --------------------------------------------------------------------- | |
200 | /* This is a shorter version that is designed to be < 60 chars or so */ | |
201 | string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const | |
202 | { | |
5e02df82 | 203 | string Res = ::URI::NoUserPassword(URI) + ' '; |
b2e465d6 AL |
204 | if (Dist[Dist.size() - 1] == '/') |
205 | { | |
206 | if (Dist != "/") | |
207 | Res += Dist; | |
208 | } | |
209 | else | |
210 | Res += Dist + '/' + Section; | |
211 | ||
212 | Res += " "; | |
213 | Res += Ver.ParentPkg().Name(); | |
214 | Res += " "; | |
dd13742e DK |
215 | if (Dist[Dist.size() - 1] != '/') |
216 | Res.append(Ver.Arch()).append(" "); | |
b2e465d6 AL |
217 | Res += Ver.VerStr(); |
218 | return Res; | |
219 | } | |
220 | /*}}}*/ | |
221 | // PackagesIndex::Describe - Give a descriptive path to the index /*{{{*/ | |
222 | // --------------------------------------------------------------------- | |
223 | /* This should help the user find the index in the sources.list and | |
224 | in the filesystem for problem solving */ | |
af87ab54 | 225 | string debPackagesIndex::Describe(bool Short) const |
b2e465d6 AL |
226 | { |
227 | char S[300]; | |
af87ab54 AL |
228 | if (Short == true) |
229 | snprintf(S,sizeof(S),"%s",Info("Packages").c_str()); | |
230 | else | |
231 | snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(), | |
232 | IndexFile("Packages").c_str()); | |
b2e465d6 AL |
233 | return S; |
234 | } | |
235 | /*}}}*/ | |
236 | // PackagesIndex::Info - One liner describing the index URI /*{{{*/ | |
237 | // --------------------------------------------------------------------- | |
238 | /* */ | |
239 | string debPackagesIndex::Info(const char *Type) const | |
240 | { | |
5e02df82 | 241 | string Info = ::URI::NoUserPassword(URI) + ' '; |
b2e465d6 AL |
242 | if (Dist[Dist.size() - 1] == '/') |
243 | { | |
244 | if (Dist != "/") | |
245 | Info += Dist; | |
246 | } | |
247 | else | |
248 | Info += Dist + '/' + Section; | |
249 | Info += " "; | |
dd13742e DK |
250 | if (Dist[Dist.size() - 1] != '/') |
251 | Info += Architecture + " "; | |
b2e465d6 AL |
252 | Info += Type; |
253 | return Info; | |
254 | } | |
255 | /*}}}*/ | |
256 | // PackagesIndex::Index* - Return the URI to the index files /*{{{*/ | |
257 | // --------------------------------------------------------------------- | |
258 | /* */ | |
259 | inline string debPackagesIndex::IndexFile(const char *Type) const | |
260 | { | |
ec7a129e | 261 | string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); |
262 | string sgzip = s + ".gz"; | |
263 | if (!FileExists(s) && FileExists(sgzip)) | |
264 | return sgzip; | |
265 | else | |
266 | return s; | |
b2e465d6 AL |
267 | } |
268 | string debPackagesIndex::IndexURI(const char *Type) const | |
269 | { | |
270 | string Res; | |
271 | if (Dist[Dist.size() - 1] == '/') | |
272 | { | |
273 | if (Dist != "/") | |
274 | Res = URI + Dist; | |
275 | else | |
276 | Res = URI; | |
277 | } | |
278 | else | |
279 | Res = URI + "dists/" + Dist + '/' + Section + | |
5dd4c8b8 | 280 | "/binary-" + Architecture + '/'; |
b2e465d6 AL |
281 | |
282 | Res += Type; | |
283 | return Res; | |
284 | } | |
285 | /*}}}*/ | |
b2e465d6 AL |
286 | // PackagesIndex::Exists - Check if the index is available /*{{{*/ |
287 | // --------------------------------------------------------------------- | |
288 | /* */ | |
289 | bool debPackagesIndex::Exists() const | |
290 | { | |
291 | return FileExists(IndexFile("Packages")); | |
292 | } | |
293 | /*}}}*/ | |
294 | // PackagesIndex::Size - Return the size of the index /*{{{*/ | |
295 | // --------------------------------------------------------------------- | |
296 | /* This is really only used for progress reporting. */ | |
297 | unsigned long debPackagesIndex::Size() const | |
298 | { | |
915f0520 MP |
299 | unsigned long size = 0; |
300 | ||
301 | /* we need to ignore errors here; if the lists are absent, just return 0 */ | |
302 | _error->PushToStack(); | |
303 | ||
f0e83599 | 304 | FileFd f(IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension); |
915f0520 MP |
305 | if (!f.Failed()) |
306 | size = f.Size(); | |
5473df3f | 307 | |
915f0520 MP |
308 | if (_error->PendingError() == true) |
309 | size = 0; | |
310 | _error->RevertToStack(); | |
311 | ||
312 | return size; | |
b2e465d6 AL |
313 | } |
314 | /*}}}*/ | |
315 | // PackagesIndex::Merge - Load the index file into a cache /*{{{*/ | |
316 | // --------------------------------------------------------------------- | |
317 | /* */ | |
2e5f4e45 | 318 | bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const |
b2e465d6 AL |
319 | { |
320 | string PackageFile = IndexFile("Packages"); | |
468720c5 | 321 | FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension); |
5dd4c8b8 | 322 | debListParser Parser(&Pkg, Architecture); |
3184b4cf | 323 | |
b2e465d6 AL |
324 | if (_error->PendingError() == true) |
325 | return _error->Error("Problem opening %s",PackageFile.c_str()); | |
2e5f4e45 DK |
326 | if (Prog != NULL) |
327 | Prog->SubProgress(0,Info("Packages")); | |
b2e465d6 AL |
328 | ::URI Tmp(URI); |
329 | if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false) | |
330 | return _error->Error("Problem with SelectFile %s",PackageFile.c_str()); | |
331 | ||
332 | // Store the IMS information | |
333 | pkgCache::PkgFileIterator File = Gen.GetCurFile(); | |
a9fe5928 | 334 | pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(File); |
76a763e1 DK |
335 | File->Size = Pkg.FileSize(); |
336 | File->mtime = Pkg.ModificationTime(); | |
b2e465d6 AL |
337 | |
338 | if (Gen.MergeList(Parser) == false) | |
339 | return _error->Error("Problem with MergeList %s",PackageFile.c_str()); | |
340 | ||
341 | // Check the release file | |
fe0f7911 DK |
342 | string ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("InRelease"); |
343 | bool releaseExists = false; | |
b2e465d6 | 344 | if (FileExists(ReleaseFile) == true) |
fe0f7911 DK |
345 | releaseExists = true; |
346 | else | |
347 | ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("Release"); | |
348 | ||
349 | if (releaseExists == true || FileExists(ReleaseFile) == true) | |
b2e465d6 | 350 | { |
233b7808 DK |
351 | FileFd Rel; |
352 | // Beware: The 'Release' file might be clearsigned in case the | |
353 | // signature for an 'InRelease' file couldn't be checked | |
354 | if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false) | |
355 | return false; | |
356 | ||
b2e465d6 AL |
357 | if (_error->PendingError() == true) |
358 | return false; | |
e011829d | 359 | Parser.LoadReleaseInfo(File,Rel,Section); |
b2e465d6 AL |
360 | } |
361 | ||
362 | return true; | |
363 | } | |
364 | /*}}}*/ | |
365 | // PackagesIndex::FindInCache - Find this index /*{{{*/ | |
366 | // --------------------------------------------------------------------- | |
367 | /* */ | |
368 | pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const | |
369 | { | |
370 | string FileName = IndexFile("Packages"); | |
371 | pkgCache::PkgFileIterator File = Cache.FileBegin(); | |
f7f0d6c7 | 372 | for (; File.end() == false; ++File) |
b2e465d6 | 373 | { |
f6442c77 | 374 | if (File.FileName() == NULL || FileName != File.FileName()) |
b2e465d6 AL |
375 | continue; |
376 | ||
377 | struct stat St; | |
378 | if (stat(File.FileName(),&St) != 0) | |
c8e572e3 MV |
379 | { |
380 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
381 | std::clog << "PackagesIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
b2e465d6 | 382 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 383 | } |
b2e465d6 | 384 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) |
c8e572e3 MV |
385 | { |
386 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
387 | std::clog << "PackagesIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
388 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
389 | << ") doesn't match for " << File.FileName() << std::endl; | |
b2e465d6 | 390 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 391 | } |
b2e465d6 AL |
392 | return File; |
393 | } | |
394 | ||
395 | return File; | |
396 | } | |
397 | /*}}}*/ | |
398 | ||
a52f938b OS |
399 | // TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/ |
400 | // --------------------------------------------------------------------- | |
401 | /* */ | |
45df0ad2 DK |
402 | debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section, |
403 | char const * const Translation) : | |
404 | pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section), | |
405 | Language(Translation) | |
406 | {} | |
a52f938b OS |
407 | /*}}}*/ |
408 | // TranslationIndex::Trans* - Return the URI to the translation files /*{{{*/ | |
409 | // --------------------------------------------------------------------- | |
410 | /* */ | |
411 | inline string debTranslationsIndex::IndexFile(const char *Type) const | |
412 | { | |
ec7a129e | 413 | string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); |
414 | string sgzip = s + ".gz"; | |
415 | if (!FileExists(s) && FileExists(sgzip)) | |
416 | return sgzip; | |
417 | else | |
418 | return s; | |
a52f938b OS |
419 | } |
420 | string debTranslationsIndex::IndexURI(const char *Type) const | |
421 | { | |
422 | string Res; | |
423 | if (Dist[Dist.size() - 1] == '/') | |
424 | { | |
425 | if (Dist != "/") | |
422eeaaa | 426 | Res = URI + Dist; |
a52f938b | 427 | else |
422eeaaa | 428 | Res = URI; |
a52f938b OS |
429 | } |
430 | else | |
422eeaaa | 431 | Res = URI + "dists/" + Dist + '/' + Section + |
a52f938b OS |
432 | "/i18n/Translation-"; |
433 | ||
434 | Res += Type; | |
435 | return Res; | |
436 | } | |
437 | /*}}}*/ | |
438 | // TranslationsIndex::GetIndexes - Fetch the index files /*{{{*/ | |
439 | // --------------------------------------------------------------------- | |
440 | /* */ | |
441 | bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const | |
442 | { | |
e4d30d3f MV |
443 | string const TranslationFile = string("Translation-").append(Language); |
444 | new pkgAcqIndexTrans(Owner, IndexURI(Language), | |
445 | Info(TranslationFile.c_str()), | |
446 | TranslationFile); | |
a52f938b OS |
447 | |
448 | return true; | |
449 | } | |
450 | /*}}}*/ | |
451 | // TranslationsIndex::Describe - Give a descriptive path to the index /*{{{*/ | |
452 | // --------------------------------------------------------------------- | |
453 | /* This should help the user find the index in the sources.list and | |
454 | in the filesystem for problem solving */ | |
455 | string debTranslationsIndex::Describe(bool Short) const | |
456 | { | |
457 | char S[300]; | |
458 | if (Short == true) | |
459 | snprintf(S,sizeof(S),"%s",Info(TranslationFile().c_str()).c_str()); | |
460 | else | |
461 | snprintf(S,sizeof(S),"%s (%s)",Info(TranslationFile().c_str()).c_str(), | |
45df0ad2 | 462 | IndexFile(Language).c_str()); |
a52f938b OS |
463 | return S; |
464 | } | |
465 | /*}}}*/ | |
466 | // TranslationsIndex::Info - One liner describing the index URI /*{{{*/ | |
467 | // --------------------------------------------------------------------- | |
468 | /* */ | |
469 | string debTranslationsIndex::Info(const char *Type) const | |
470 | { | |
5e02df82 | 471 | string Info = ::URI::NoUserPassword(URI) + ' '; |
a52f938b OS |
472 | if (Dist[Dist.size() - 1] == '/') |
473 | { | |
474 | if (Dist != "/") | |
475 | Info += Dist; | |
476 | } | |
477 | else | |
478 | Info += Dist + '/' + Section; | |
479 | Info += " "; | |
480 | Info += Type; | |
481 | return Info; | |
482 | } | |
483 | /*}}}*/ | |
45df0ad2 | 484 | bool debTranslationsIndex::HasPackages() const /*{{{*/ |
11680bfd | 485 | { |
45df0ad2 | 486 | return FileExists(IndexFile(Language)); |
11680bfd | 487 | } |
45df0ad2 | 488 | /*}}}*/ |
a52f938b OS |
489 | // TranslationsIndex::Exists - Check if the index is available /*{{{*/ |
490 | // --------------------------------------------------------------------- | |
491 | /* */ | |
492 | bool debTranslationsIndex::Exists() const | |
493 | { | |
45df0ad2 | 494 | return FileExists(IndexFile(Language)); |
a52f938b OS |
495 | } |
496 | /*}}}*/ | |
497 | // TranslationsIndex::Size - Return the size of the index /*{{{*/ | |
498 | // --------------------------------------------------------------------- | |
499 | /* This is really only used for progress reporting. */ | |
500 | unsigned long debTranslationsIndex::Size() const | |
501 | { | |
915f0520 MP |
502 | unsigned long size = 0; |
503 | ||
504 | /* we need to ignore errors here; if the lists are absent, just return 0 */ | |
505 | _error->PushToStack(); | |
506 | ||
f0e83599 | 507 | FileFd f(IndexFile(Language), FileFd::ReadOnly, FileFd::Extension); |
915f0520 MP |
508 | if (!f.Failed()) |
509 | size = f.Size(); | |
5473df3f | 510 | |
915f0520 MP |
511 | if (_error->PendingError() == true) |
512 | size = 0; | |
513 | _error->RevertToStack(); | |
5473df3f | 514 | |
915f0520 | 515 | return size; |
a52f938b OS |
516 | } |
517 | /*}}}*/ | |
518 | // TranslationsIndex::Merge - Load the index file into a cache /*{{{*/ | |
519 | // --------------------------------------------------------------------- | |
520 | /* */ | |
2e5f4e45 | 521 | bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const |
a52f938b OS |
522 | { |
523 | // Check the translation file, if in use | |
45df0ad2 | 524 | string TranslationFile = IndexFile(Language); |
64c2bdc9 | 525 | if (FileExists(TranslationFile)) |
a52f938b | 526 | { |
468720c5 | 527 | FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension); |
a52f938b OS |
528 | debListParser TransParser(&Trans); |
529 | if (_error->PendingError() == true) | |
530 | return false; | |
531 | ||
2e5f4e45 DK |
532 | if (Prog != NULL) |
533 | Prog->SubProgress(0, Info(TranslationFile.c_str())); | |
a52f938b OS |
534 | if (Gen.SelectFile(TranslationFile,string(),*this) == false) |
535 | return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); | |
536 | ||
537 | // Store the IMS information | |
538 | pkgCache::PkgFileIterator TransFile = Gen.GetCurFile(); | |
76a763e1 DK |
539 | TransFile->Size = Trans.FileSize(); |
540 | TransFile->mtime = Trans.ModificationTime(); | |
a52f938b OS |
541 | |
542 | if (Gen.MergeList(TransParser) == false) | |
543 | return _error->Error("Problem with MergeList %s",TranslationFile.c_str()); | |
544 | } | |
545 | ||
546 | return true; | |
547 | } | |
548 | /*}}}*/ | |
c51c6f08 OS |
549 | // TranslationsIndex::FindInCache - Find this index /*{{{*/ |
550 | // --------------------------------------------------------------------- | |
551 | /* */ | |
552 | pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const | |
553 | { | |
45df0ad2 | 554 | string FileName = IndexFile(Language); |
4d34acf1 | 555 | |
c51c6f08 | 556 | pkgCache::PkgFileIterator File = Cache.FileBegin(); |
f7f0d6c7 | 557 | for (; File.end() == false; ++File) |
f416d22e MV |
558 | { |
559 | if (FileName != File.FileName()) | |
560 | continue; | |
4d34acf1 | 561 | |
f416d22e MV |
562 | struct stat St; |
563 | if (stat(File.FileName(),&St) != 0) | |
c8e572e3 MV |
564 | { |
565 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
566 | std::clog << "TranslationIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
f416d22e | 567 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 568 | } |
f416d22e | 569 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) |
c8e572e3 MV |
570 | { |
571 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
572 | std::clog << "TranslationIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
573 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
574 | << ") doesn't match for " << File.FileName() << std::endl; | |
f416d22e | 575 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 576 | } |
f416d22e MV |
577 | return File; |
578 | } | |
c51c6f08 OS |
579 | return File; |
580 | } | |
581 | /*}}}*/ | |
b2e465d6 AL |
582 | // StatusIndex::debStatusIndex - Constructor /*{{{*/ |
583 | // --------------------------------------------------------------------- | |
584 | /* */ | |
7db98ffc | 585 | debStatusIndex::debStatusIndex(string File) : pkgIndexFile(true), File(File) |
b2e465d6 AL |
586 | { |
587 | } | |
588 | /*}}}*/ | |
589 | // StatusIndex::Size - Return the size of the index /*{{{*/ | |
590 | // --------------------------------------------------------------------- | |
591 | /* */ | |
592 | unsigned long debStatusIndex::Size() const | |
593 | { | |
594 | struct stat S; | |
595 | if (stat(File.c_str(),&S) != 0) | |
596 | return 0; | |
597 | return S.st_size; | |
598 | } | |
599 | /*}}}*/ | |
600 | // StatusIndex::Merge - Load the index file into a cache /*{{{*/ | |
601 | // --------------------------------------------------------------------- | |
602 | /* */ | |
2e5f4e45 | 603 | bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const |
b2e465d6 | 604 | { |
468720c5 | 605 | FileFd Pkg(File,FileFd::ReadOnly, FileFd::Extension); |
b2e465d6 AL |
606 | if (_error->PendingError() == true) |
607 | return false; | |
608 | debListParser Parser(&Pkg); | |
609 | if (_error->PendingError() == true) | |
610 | return false; | |
2e5f4e45 DK |
611 | |
612 | if (Prog != NULL) | |
613 | Prog->SubProgress(0,File); | |
b2e465d6 AL |
614 | if (Gen.SelectFile(File,string(),*this,pkgCache::Flag::NotSource) == false) |
615 | return _error->Error("Problem with SelectFile %s",File.c_str()); | |
616 | ||
617 | // Store the IMS information | |
618 | pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); | |
76a763e1 DK |
619 | CFile->Size = Pkg.FileSize(); |
620 | CFile->mtime = Pkg.ModificationTime(); | |
2b803d40 DK |
621 | map_ptrloc const storage = Gen.WriteUniqString("now"); |
622 | CFile->Archive = storage; | |
b2e465d6 AL |
623 | |
624 | if (Gen.MergeList(Parser) == false) | |
625 | return _error->Error("Problem with MergeList %s",File.c_str()); | |
626 | return true; | |
627 | } | |
628 | /*}}}*/ | |
629 | // StatusIndex::FindInCache - Find this index /*{{{*/ | |
630 | // --------------------------------------------------------------------- | |
631 | /* */ | |
632 | pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const | |
633 | { | |
634 | pkgCache::PkgFileIterator File = Cache.FileBegin(); | |
f7f0d6c7 | 635 | for (; File.end() == false; ++File) |
b2e465d6 AL |
636 | { |
637 | if (this->File != File.FileName()) | |
638 | continue; | |
639 | ||
640 | struct stat St; | |
641 | if (stat(File.FileName(),&St) != 0) | |
c8e572e3 MV |
642 | { |
643 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
644 | std::clog << "StatusIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
b2e465d6 | 645 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 646 | } |
b2e465d6 | 647 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) |
c8e572e3 MV |
648 | { |
649 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
650 | std::clog << "StatusIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
651 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
652 | << ") doesn't match for " << File.FileName() << std::endl; | |
b2e465d6 | 653 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 654 | } |
b2e465d6 AL |
655 | return File; |
656 | } | |
657 | return File; | |
658 | } | |
659 | /*}}}*/ | |
660 | // StatusIndex::Exists - Check if the index is available /*{{{*/ | |
661 | // --------------------------------------------------------------------- | |
662 | /* */ | |
663 | bool debStatusIndex::Exists() const | |
664 | { | |
665 | // Abort if the file does not exist. | |
666 | return true; | |
667 | } | |
668 | /*}}}*/ | |
669 | ||
b2e465d6 AL |
670 | // Index File types for Debian /*{{{*/ |
671 | class debIFTypeSrc : public pkgIndexFile::Type | |
672 | { | |
673 | public: | |
674 | ||
675 | debIFTypeSrc() {Label = "Debian Source Index";}; | |
676 | }; | |
677 | class debIFTypePkg : public pkgIndexFile::Type | |
678 | { | |
679 | public: | |
680 | ||
681 | virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const | |
682 | { | |
683 | return new debRecordParser(File.FileName(),*File.Cache()); | |
684 | }; | |
685 | debIFTypePkg() {Label = "Debian Package Index";}; | |
686 | }; | |
97234432 MV |
687 | class debIFTypeTrans : public debIFTypePkg |
688 | { | |
689 | public: | |
690 | debIFTypeTrans() {Label = "Debian Translation Index";}; | |
691 | }; | |
b2e465d6 AL |
692 | class debIFTypeStatus : public pkgIndexFile::Type |
693 | { | |
694 | public: | |
695 | ||
696 | virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const | |
697 | { | |
698 | return new debRecordParser(File.FileName(),*File.Cache()); | |
699 | }; | |
700 | debIFTypeStatus() {Label = "Debian dpkg status file";}; | |
701 | }; | |
702 | static debIFTypeSrc _apt_Src; | |
703 | static debIFTypePkg _apt_Pkg; | |
97234432 | 704 | static debIFTypeTrans _apt_Trans; |
b2e465d6 AL |
705 | static debIFTypeStatus _apt_Status; |
706 | ||
707 | const pkgIndexFile::Type *debSourcesIndex::GetType() const | |
708 | { | |
709 | return &_apt_Src; | |
710 | } | |
711 | const pkgIndexFile::Type *debPackagesIndex::GetType() const | |
712 | { | |
713 | return &_apt_Pkg; | |
714 | } | |
a52f938b OS |
715 | const pkgIndexFile::Type *debTranslationsIndex::GetType() const |
716 | { | |
97234432 | 717 | return &_apt_Trans; |
a52f938b | 718 | } |
b2e465d6 AL |
719 | const pkgIndexFile::Type *debStatusIndex::GetType() const |
720 | { | |
721 | return &_apt_Status; | |
722 | } | |
723 | ||
724 | /*}}}*/ |