debindexfile.cc 21 KB

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