debindexfile.cc 22 KB

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