debindexfile.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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. if (TranslationsAvailable()) {
  396. string const TranslationFile = string("Translation-").append(Language);
  397. new pkgAcqIndexTrans(Owner, IndexURI(Language),
  398. Info(TranslationFile.c_str()),
  399. TranslationFile);
  400. }
  401. return true;
  402. }
  403. /*}}}*/
  404. // TranslationsIndex::Describe - Give a descriptive path to the index /*{{{*/
  405. // ---------------------------------------------------------------------
  406. /* This should help the user find the index in the sources.list and
  407. in the filesystem for problem solving */
  408. string debTranslationsIndex::Describe(bool Short) const
  409. {
  410. char S[300];
  411. if (Short == true)
  412. snprintf(S,sizeof(S),"%s",Info(TranslationFile().c_str()).c_str());
  413. else
  414. snprintf(S,sizeof(S),"%s (%s)",Info(TranslationFile().c_str()).c_str(),
  415. IndexFile(Language).c_str());
  416. return S;
  417. }
  418. /*}}}*/
  419. // TranslationsIndex::Info - One liner describing the index URI /*{{{*/
  420. // ---------------------------------------------------------------------
  421. /* */
  422. string debTranslationsIndex::Info(const char *Type) const
  423. {
  424. string Info = ::URI::NoUserPassword(URI) + ' ';
  425. if (Dist[Dist.size() - 1] == '/')
  426. {
  427. if (Dist != "/")
  428. Info += Dist;
  429. }
  430. else
  431. Info += Dist + '/' + Section;
  432. Info += " ";
  433. Info += Type;
  434. return Info;
  435. }
  436. /*}}}*/
  437. bool debTranslationsIndex::HasPackages() const /*{{{*/
  438. {
  439. if(!TranslationsAvailable())
  440. return false;
  441. return FileExists(IndexFile(Language));
  442. }
  443. /*}}}*/
  444. // TranslationsIndex::Exists - Check if the index is available /*{{{*/
  445. // ---------------------------------------------------------------------
  446. /* */
  447. bool debTranslationsIndex::Exists() const
  448. {
  449. return FileExists(IndexFile(Language));
  450. }
  451. /*}}}*/
  452. // TranslationsIndex::Size - Return the size of the index /*{{{*/
  453. // ---------------------------------------------------------------------
  454. /* This is really only used for progress reporting. */
  455. unsigned long debTranslationsIndex::Size() const
  456. {
  457. unsigned long size = 0;
  458. /* we need to ignore errors here; if the lists are absent, just return 0 */
  459. _error->PushToStack();
  460. FileFd f = FileFd (IndexFile(Language), FileFd::ReadOnlyGzip);
  461. if (!f.Failed())
  462. size = f.Size();
  463. if (_error->PendingError() == true)
  464. size = 0;
  465. _error->RevertToStack();
  466. return size;
  467. }
  468. /*}}}*/
  469. // TranslationsIndex::Merge - Load the index file into a cache /*{{{*/
  470. // ---------------------------------------------------------------------
  471. /* */
  472. bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
  473. {
  474. // Check the translation file, if in use
  475. string TranslationFile = IndexFile(Language);
  476. if (TranslationsAvailable() && FileExists(TranslationFile))
  477. {
  478. FileFd Trans(TranslationFile,FileFd::ReadOnlyGzip);
  479. debListParser TransParser(&Trans);
  480. if (_error->PendingError() == true)
  481. return false;
  482. if (Prog != NULL)
  483. Prog->SubProgress(0, Info(TranslationFile.c_str()));
  484. if (Gen.SelectFile(TranslationFile,string(),*this) == false)
  485. return _error->Error("Problem with SelectFile %s",TranslationFile.c_str());
  486. // Store the IMS information
  487. pkgCache::PkgFileIterator TransFile = Gen.GetCurFile();
  488. struct stat TransSt;
  489. if (fstat(Trans.Fd(),&TransSt) != 0)
  490. return _error->Errno("fstat","Failed to stat");
  491. TransFile->Size = TransSt.st_size;
  492. TransFile->mtime = TransSt.st_mtime;
  493. if (Gen.MergeList(TransParser) == false)
  494. return _error->Error("Problem with MergeList %s",TranslationFile.c_str());
  495. }
  496. return true;
  497. }
  498. /*}}}*/
  499. // TranslationsIndex::FindInCache - Find this index /*{{{*/
  500. // ---------------------------------------------------------------------
  501. /* */
  502. pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const
  503. {
  504. string FileName = IndexFile(Language);
  505. pkgCache::PkgFileIterator File = Cache.FileBegin();
  506. for (; File.end() == false; File++)
  507. {
  508. if (FileName != File.FileName())
  509. continue;
  510. struct stat St;
  511. if (stat(File.FileName(),&St) != 0)
  512. {
  513. if (_config->FindB("Debug::pkgCacheGen", false))
  514. std::clog << "TranslationIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
  515. return pkgCache::PkgFileIterator(Cache);
  516. }
  517. if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
  518. {
  519. if (_config->FindB("Debug::pkgCacheGen", false))
  520. std::clog << "TranslationIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
  521. << ") or mtime (" << St.st_mtime << " <> " << File->mtime
  522. << ") doesn't match for " << File.FileName() << std::endl;
  523. return pkgCache::PkgFileIterator(Cache);
  524. }
  525. return File;
  526. }
  527. return File;
  528. }
  529. /*}}}*/
  530. // StatusIndex::debStatusIndex - Constructor /*{{{*/
  531. // ---------------------------------------------------------------------
  532. /* */
  533. debStatusIndex::debStatusIndex(string File) : pkgIndexFile(true), File(File)
  534. {
  535. }
  536. /*}}}*/
  537. // StatusIndex::Size - Return the size of the index /*{{{*/
  538. // ---------------------------------------------------------------------
  539. /* */
  540. unsigned long debStatusIndex::Size() const
  541. {
  542. struct stat S;
  543. if (stat(File.c_str(),&S) != 0)
  544. return 0;
  545. return S.st_size;
  546. }
  547. /*}}}*/
  548. // StatusIndex::Merge - Load the index file into a cache /*{{{*/
  549. // ---------------------------------------------------------------------
  550. /* */
  551. bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
  552. {
  553. FileFd Pkg(File,FileFd::ReadOnlyGzip);
  554. if (_error->PendingError() == true)
  555. return false;
  556. debListParser Parser(&Pkg);
  557. if (_error->PendingError() == true)
  558. return false;
  559. if (Prog != NULL)
  560. Prog->SubProgress(0,File);
  561. if (Gen.SelectFile(File,string(),*this,pkgCache::Flag::NotSource) == false)
  562. return _error->Error("Problem with SelectFile %s",File.c_str());
  563. // Store the IMS information
  564. pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
  565. struct stat St;
  566. if (fstat(Pkg.Fd(),&St) != 0)
  567. return _error->Errno("fstat","Failed to stat");
  568. CFile->Size = St.st_size;
  569. CFile->mtime = St.st_mtime;
  570. CFile->Archive = Gen.WriteUniqString("now");
  571. if (Gen.MergeList(Parser) == false)
  572. return _error->Error("Problem with MergeList %s",File.c_str());
  573. return true;
  574. }
  575. /*}}}*/
  576. // StatusIndex::FindInCache - Find this index /*{{{*/
  577. // ---------------------------------------------------------------------
  578. /* */
  579. pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const
  580. {
  581. pkgCache::PkgFileIterator File = Cache.FileBegin();
  582. for (; File.end() == false; File++)
  583. {
  584. if (this->File != File.FileName())
  585. continue;
  586. struct stat St;
  587. if (stat(File.FileName(),&St) != 0)
  588. {
  589. if (_config->FindB("Debug::pkgCacheGen", false))
  590. std::clog << "StatusIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
  591. return pkgCache::PkgFileIterator(Cache);
  592. }
  593. if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
  594. {
  595. if (_config->FindB("Debug::pkgCacheGen", false))
  596. std::clog << "StatusIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
  597. << ") or mtime (" << St.st_mtime << " <> " << File->mtime
  598. << ") doesn't match for " << File.FileName() << std::endl;
  599. return pkgCache::PkgFileIterator(Cache);
  600. }
  601. return File;
  602. }
  603. return File;
  604. }
  605. /*}}}*/
  606. // StatusIndex::Exists - Check if the index is available /*{{{*/
  607. // ---------------------------------------------------------------------
  608. /* */
  609. bool debStatusIndex::Exists() const
  610. {
  611. // Abort if the file does not exist.
  612. return true;
  613. }
  614. /*}}}*/
  615. // Index File types for Debian /*{{{*/
  616. class debIFTypeSrc : public pkgIndexFile::Type
  617. {
  618. public:
  619. debIFTypeSrc() {Label = "Debian Source Index";};
  620. };
  621. class debIFTypePkg : public pkgIndexFile::Type
  622. {
  623. public:
  624. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
  625. {
  626. return new debRecordParser(File.FileName(),*File.Cache());
  627. };
  628. debIFTypePkg() {Label = "Debian Package Index";};
  629. };
  630. class debIFTypeTrans : public debIFTypePkg
  631. {
  632. public:
  633. debIFTypeTrans() {Label = "Debian Translation Index";};
  634. };
  635. class debIFTypeStatus : public pkgIndexFile::Type
  636. {
  637. public:
  638. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
  639. {
  640. return new debRecordParser(File.FileName(),*File.Cache());
  641. };
  642. debIFTypeStatus() {Label = "Debian dpkg status file";};
  643. };
  644. static debIFTypeSrc _apt_Src;
  645. static debIFTypePkg _apt_Pkg;
  646. static debIFTypeTrans _apt_Trans;
  647. static debIFTypeStatus _apt_Status;
  648. const pkgIndexFile::Type *debSourcesIndex::GetType() const
  649. {
  650. return &_apt_Src;
  651. }
  652. const pkgIndexFile::Type *debPackagesIndex::GetType() const
  653. {
  654. return &_apt_Pkg;
  655. }
  656. const pkgIndexFile::Type *debTranslationsIndex::GetType() const
  657. {
  658. return &_apt_Trans;
  659. }
  660. const pkgIndexFile::Type *debStatusIndex::GetType() const
  661. {
  662. return &_apt_Status;
  663. }
  664. /*}}}*/