debindexfile.cc 22 KB

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