debindexfile.cc 21 KB

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