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