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