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