cdrom.cc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. */
  3. #ifdef __GNUG__
  4. #pragma implementation "apt-pkg/cdrom.h"
  5. #endif
  6. #include<apt-pkg/init.h>
  7. #include<apt-pkg/error.h>
  8. #include<apt-pkg/cdromutl.h>
  9. #include<apt-pkg/strutl.h>
  10. #include<apt-pkg/cdrom.h>
  11. #include<sstream>
  12. #include<fstream>
  13. #include<config.h>
  14. #include<apti18n.h>
  15. #include <sys/stat.h>
  16. #include <fcntl.h>
  17. #include <dirent.h>
  18. #include <unistd.h>
  19. #include <stdio.h>
  20. #include "indexcopy.h"
  21. using namespace std;
  22. // FindPackages - Find the package files on the CDROM /*{{{*/
  23. // ---------------------------------------------------------------------
  24. /* We look over the cdrom for package files. This is a recursive
  25. search that short circuits when it his a package file in the dir.
  26. This speeds it up greatly as the majority of the size is in the
  27. binary-* sub dirs. */
  28. bool pkgCdrom::FindPackages(string CD,vector<string> &List,
  29. vector<string> &SList, vector<string> &SigList,
  30. string &InfoDir, pkgCdromStatus *log,
  31. unsigned int Depth)
  32. {
  33. static ino_t Inodes[9];
  34. // if we have a look we "pulse" now
  35. if(log)
  36. log->Update();
  37. if (Depth >= 7)
  38. return true;
  39. if (CD[CD.length()-1] != '/')
  40. CD += '/';
  41. if (chdir(CD.c_str()) != 0)
  42. return _error->Errno("chdir","Unable to change to %s",CD.c_str());
  43. // Look for a .disk subdirectory
  44. struct stat Buf;
  45. if (stat(".disk",&Buf) == 0)
  46. {
  47. if (InfoDir.empty() == true)
  48. InfoDir = CD + ".disk/";
  49. }
  50. // Don't look into directories that have been marked to ingore.
  51. if (stat(".aptignr",&Buf) == 0)
  52. return true;
  53. /* Check _first_ for a signature file as apt-cdrom assumes that all files
  54. under a Packages/Source file are in control of that file and stops
  55. the scanning
  56. */
  57. if (stat("Release.gpg",&Buf) == 0)
  58. {
  59. SigList.push_back(CD);
  60. }
  61. /* Aha! We found some package files. We assume that everything under
  62. this dir is controlled by those package files so we don't look down
  63. anymore */
  64. if (stat("Packages",&Buf) == 0 || stat("Packages.gz",&Buf) == 0)
  65. {
  66. List.push_back(CD);
  67. // Continue down if thorough is given
  68. if (_config->FindB("APT::CDROM::Thorough",false) == false)
  69. return true;
  70. }
  71. if (stat("Sources.gz",&Buf) == 0 || stat("Sources",&Buf) == 0)
  72. {
  73. SList.push_back(CD);
  74. // Continue down if thorough is given
  75. if (_config->FindB("APT::CDROM::Thorough",false) == false)
  76. return true;
  77. }
  78. DIR *D = opendir(".");
  79. if (D == 0)
  80. return _error->Errno("opendir","Unable to read %s",CD.c_str());
  81. // Run over the directory
  82. for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D))
  83. {
  84. // Skip some files..
  85. if (strcmp(Dir->d_name,".") == 0 ||
  86. strcmp(Dir->d_name,"..") == 0 ||
  87. //strcmp(Dir->d_name,"source") == 0 ||
  88. strcmp(Dir->d_name,".disk") == 0 ||
  89. strcmp(Dir->d_name,"experimental") == 0 ||
  90. strcmp(Dir->d_name,"binary-all") == 0 ||
  91. strcmp(Dir->d_name,"debian-installer") == 0)
  92. continue;
  93. // See if the name is a sub directory
  94. struct stat Buf;
  95. if (stat(Dir->d_name,&Buf) != 0)
  96. continue;
  97. if (S_ISDIR(Buf.st_mode) == 0)
  98. continue;
  99. unsigned int I;
  100. for (I = 0; I != Depth; I++)
  101. if (Inodes[I] == Buf.st_ino)
  102. break;
  103. if (I != Depth)
  104. continue;
  105. // Store the inodes weve seen
  106. Inodes[Depth] = Buf.st_ino;
  107. // Descend
  108. if (FindPackages(CD + Dir->d_name,List,SList,SigList,InfoDir,log,Depth+1) == false)
  109. break;
  110. if (chdir(CD.c_str()) != 0)
  111. return _error->Errno("chdir","Unable to change to %s",CD.c_str());
  112. };
  113. closedir(D);
  114. return !_error->PendingError();
  115. }
  116. // Score - We compute a 'score' for a path /*{{{*/
  117. // ---------------------------------------------------------------------
  118. /* Paths are scored based on how close they come to what I consider
  119. normal. That is ones that have 'dist' 'stable' 'testing' will score
  120. higher than ones without. */
  121. int pkgCdrom::Score(string Path)
  122. {
  123. int Res = 0;
  124. if (Path.find("stable/") != string::npos)
  125. Res += 29;
  126. if (Path.find("/binary-") != string::npos)
  127. Res += 20;
  128. if (Path.find("testing/") != string::npos)
  129. Res += 28;
  130. if (Path.find("unstable/") != string::npos)
  131. Res += 27;
  132. if (Path.find("/dists/") != string::npos)
  133. Res += 40;
  134. if (Path.find("/main/") != string::npos)
  135. Res += 20;
  136. if (Path.find("/contrib/") != string::npos)
  137. Res += 20;
  138. if (Path.find("/non-free/") != string::npos)
  139. Res += 20;
  140. if (Path.find("/non-US/") != string::npos)
  141. Res += 20;
  142. if (Path.find("/source/") != string::npos)
  143. Res += 10;
  144. if (Path.find("/debian/") != string::npos)
  145. Res -= 10;
  146. return Res;
  147. }
  148. /*}}}*/
  149. // DropBinaryArch - Dump dirs with a string like /binary-<foo>/ /*{{{*/
  150. // ---------------------------------------------------------------------
  151. /* Here we drop everything that is not this machines arch */
  152. bool pkgCdrom::DropBinaryArch(vector<string> &List)
  153. {
  154. char S[300];
  155. snprintf(S,sizeof(S),"/binary-%s/",
  156. _config->Find("Apt::Architecture").c_str());
  157. for (unsigned int I = 0; I < List.size(); I++)
  158. {
  159. const char *Str = List[I].c_str();
  160. const char *Res;
  161. if ((Res = strstr(Str,"/binary-")) == 0)
  162. continue;
  163. // Weird, remove it.
  164. if (strlen(Res) < strlen(S))
  165. {
  166. List.erase(List.begin() + I);
  167. I--;
  168. continue;
  169. }
  170. // See if it is our arch
  171. if (stringcmp(Res,Res + strlen(S),S) == 0)
  172. continue;
  173. // Erase it
  174. List.erase(List.begin() + I);
  175. I--;
  176. }
  177. return true;
  178. }
  179. // DropRepeats - Drop repeated files resulting from symlinks /*{{{*/
  180. // ---------------------------------------------------------------------
  181. /* Here we go and stat every file that we found and strip dup inodes. */
  182. bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
  183. {
  184. // Get a list of all the inodes
  185. ino_t *Inodes = new ino_t[List.size()];
  186. for (unsigned int I = 0; I != List.size(); I++)
  187. {
  188. struct stat Buf;
  189. if (stat((List[I] + Name).c_str(),&Buf) != 0 &&
  190. stat((List[I] + Name + ".gz").c_str(),&Buf) != 0)
  191. _error->Errno("stat","Failed to stat %s%s",List[I].c_str(),
  192. Name);
  193. Inodes[I] = Buf.st_ino;
  194. }
  195. if (_error->PendingError() == true)
  196. return false;
  197. // Look for dups
  198. for (unsigned int I = 0; I != List.size(); I++)
  199. {
  200. for (unsigned int J = I+1; J < List.size(); J++)
  201. {
  202. // No match
  203. if (Inodes[J] != Inodes[I])
  204. continue;
  205. // We score the two paths.. and erase one
  206. int ScoreA = Score(List[I]);
  207. int ScoreB = Score(List[J]);
  208. if (ScoreA < ScoreB)
  209. {
  210. List[I] = string();
  211. break;
  212. }
  213. List[J] = string();
  214. }
  215. }
  216. // Wipe erased entries
  217. for (unsigned int I = 0; I < List.size();)
  218. {
  219. if (List[I].empty() == false)
  220. I++;
  221. else
  222. List.erase(List.begin()+I);
  223. }
  224. return true;
  225. }
  226. /*}}}*/
  227. // ReduceSourceList - Takes the path list and reduces it /*{{{*/
  228. // ---------------------------------------------------------------------
  229. /* This takes the list of source list expressed entires and collects
  230. similar ones to form a single entry for each dist */
  231. void pkgCdrom::ReduceSourcelist(string CD,vector<string> &List)
  232. {
  233. sort(List.begin(),List.end());
  234. // Collect similar entries
  235. for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
  236. {
  237. // Find a space..
  238. string::size_type Space = (*I).find(' ');
  239. if (Space == string::npos)
  240. continue;
  241. string::size_type SSpace = (*I).find(' ',Space + 1);
  242. if (SSpace == string::npos)
  243. continue;
  244. string Word1 = string(*I,Space,SSpace-Space);
  245. string Prefix = string(*I,0,Space);
  246. for (vector<string>::iterator J = List.begin(); J != I; J++)
  247. {
  248. // Find a space..
  249. string::size_type Space2 = (*J).find(' ');
  250. if (Space2 == string::npos)
  251. continue;
  252. string::size_type SSpace2 = (*J).find(' ',Space2 + 1);
  253. if (SSpace2 == string::npos)
  254. continue;
  255. if (string(*J,0,Space2) != Prefix)
  256. continue;
  257. if (string(*J,Space2,SSpace2-Space2) != Word1)
  258. continue;
  259. *J += string(*I,SSpace);
  260. *I = string();
  261. }
  262. }
  263. // Wipe erased entries
  264. for (unsigned int I = 0; I < List.size();)
  265. {
  266. if (List[I].empty() == false)
  267. I++;
  268. else
  269. List.erase(List.begin()+I);
  270. }
  271. }
  272. /*}}}*/
  273. // WriteDatabase - Write the CDROM Database file /*{{{*/
  274. // ---------------------------------------------------------------------
  275. /* We rewrite the configuration class associated with the cdrom database. */
  276. bool pkgCdrom::WriteDatabase(Configuration &Cnf)
  277. {
  278. string DFile = _config->FindFile("Dir::State::cdroms");
  279. string NewFile = DFile + ".new";
  280. unlink(NewFile.c_str());
  281. ofstream Out(NewFile.c_str());
  282. if (!Out)
  283. return _error->Errno("ofstream::ofstream",
  284. "Failed to open %s.new",DFile.c_str());
  285. /* Write out all of the configuration directives by walking the
  286. configuration tree */
  287. const Configuration::Item *Top = Cnf.Tree(0);
  288. for (; Top != 0;)
  289. {
  290. // Print the config entry
  291. if (Top->Value.empty() == false)
  292. Out << Top->FullTag() + " \"" << Top->Value << "\";" << endl;
  293. if (Top->Child != 0)
  294. {
  295. Top = Top->Child;
  296. continue;
  297. }
  298. while (Top != 0 && Top->Next == 0)
  299. Top = Top->Parent;
  300. if (Top != 0)
  301. Top = Top->Next;
  302. }
  303. Out.close();
  304. rename(DFile.c_str(),string(DFile + '~').c_str());
  305. if (rename(NewFile.c_str(),DFile.c_str()) != 0)
  306. return _error->Errno("rename","Failed to rename %s.new to %s",
  307. DFile.c_str(),DFile.c_str());
  308. return true;
  309. }
  310. /*}}}*/
  311. // WriteSourceList - Write an updated sourcelist /*{{{*/
  312. // ---------------------------------------------------------------------
  313. /* This reads the old source list and copies it into the new one. It
  314. appends the new CDROM entires just after the first block of comments.
  315. This places them first in the file. It also removes any old entries
  316. that were the same. */
  317. bool pkgCdrom::WriteSourceList(string Name,vector<string> &List,bool Source)
  318. {
  319. if (List.size() == 0)
  320. return true;
  321. string File = _config->FindFile("Dir::Etc::sourcelist");
  322. // Open the stream for reading
  323. ifstream F((FileExists(File)?File.c_str():"/dev/null"),
  324. ios::in );
  325. if (!F != 0)
  326. return _error->Errno("ifstream::ifstream","Opening %s",File.c_str());
  327. string NewFile = File + ".new";
  328. unlink(NewFile.c_str());
  329. ofstream Out(NewFile.c_str());
  330. if (!Out)
  331. return _error->Errno("ofstream::ofstream",
  332. "Failed to open %s.new",File.c_str());
  333. // Create a short uri without the path
  334. string ShortURI = "cdrom:[" + Name + "]/";
  335. string ShortURI2 = "cdrom:" + Name + "/"; // For Compatibility
  336. string Type;
  337. if (Source == true)
  338. Type = "deb-src";
  339. else
  340. Type = "deb";
  341. char Buffer[300];
  342. int CurLine = 0;
  343. bool First = true;
  344. while (F.eof() == false)
  345. {
  346. F.getline(Buffer,sizeof(Buffer));
  347. CurLine++;
  348. _strtabexpand(Buffer,sizeof(Buffer));
  349. _strstrip(Buffer);
  350. // Comment or blank
  351. if (Buffer[0] == '#' || Buffer[0] == 0)
  352. {
  353. Out << Buffer << endl;
  354. continue;
  355. }
  356. if (First == true)
  357. {
  358. for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
  359. {
  360. string::size_type Space = (*I).find(' ');
  361. if (Space == string::npos)
  362. return _error->Error("Internal error");
  363. Out << Type << " cdrom:[" << Name << "]/" << string(*I,0,Space) <<
  364. " " << string(*I,Space+1) << endl;
  365. }
  366. }
  367. First = false;
  368. // Grok it
  369. string cType;
  370. string URI;
  371. const char *C = Buffer;
  372. if (ParseQuoteWord(C,cType) == false ||
  373. ParseQuoteWord(C,URI) == false)
  374. {
  375. Out << Buffer << endl;
  376. continue;
  377. }
  378. // Emit lines like this one
  379. if (cType != Type || (string(URI,0,ShortURI.length()) != ShortURI &&
  380. string(URI,0,ShortURI.length()) != ShortURI2))
  381. {
  382. Out << Buffer << endl;
  383. continue;
  384. }
  385. }
  386. // Just in case the file was empty
  387. if (First == true)
  388. {
  389. for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
  390. {
  391. string::size_type Space = (*I).find(' ');
  392. if (Space == string::npos)
  393. return _error->Error("Internal error");
  394. Out << "deb cdrom:[" << Name << "]/" << string(*I,0,Space) <<
  395. " " << string(*I,Space+1) << endl;
  396. }
  397. }
  398. Out.close();
  399. rename(File.c_str(),string(File + '~').c_str());
  400. if (rename(NewFile.c_str(),File.c_str()) != 0)
  401. return _error->Errno("rename","Failed to rename %s.new to %s",
  402. File.c_str(),File.c_str());
  403. return true;
  404. }
  405. bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log)
  406. {
  407. stringstream msg;
  408. // Startup
  409. string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
  410. if (CDROM[0] == '.')
  411. CDROM= SafeGetCWD() + '/' + CDROM;
  412. if(log) {
  413. msg.str("");
  414. ioprintf(msg, _("Using CD-ROM mount point %s\nMounting CD-ROM\n"),
  415. CDROM.c_str());
  416. log->Update(msg.str());
  417. }
  418. if (MountCdrom(CDROM) == false)
  419. return _error->Error("Failed to mount the cdrom.");
  420. // Hash the CD to get an ID
  421. if(log)
  422. log->Update(_("Identifying.. "));
  423. if (IdentCdrom(CDROM,ident) == false)
  424. {
  425. ident = "";
  426. return false;
  427. }
  428. msg.str("");
  429. ioprintf(msg, "[%s]\n",ident.c_str());
  430. log->Update(msg.str());
  431. // Read the database
  432. Configuration Database;
  433. string DFile = _config->FindFile("Dir::State::cdroms");
  434. if (FileExists(DFile) == true)
  435. {
  436. if (ReadConfigFile(Database,DFile) == false)
  437. return _error->Error("Unable to read the cdrom database %s",
  438. DFile.c_str());
  439. }
  440. if(log) {
  441. msg.str("");
  442. ioprintf(msg, _("Stored Label: %s \n"),
  443. Database.Find("CD::"+ident).c_str());
  444. log->Update(msg.str());
  445. }
  446. return true;
  447. }
  448. bool pkgCdrom::Add(pkgCdromStatus *log)
  449. {
  450. stringstream msg;
  451. // Startup
  452. string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
  453. if (CDROM[0] == '.')
  454. CDROM= SafeGetCWD() + '/' + CDROM;
  455. if(log) {
  456. log->SetTotal(STEP_LAST);
  457. msg.str("");
  458. ioprintf(msg, _("Using CD-ROM mount point %s\n"), CDROM.c_str());
  459. log->Update(msg.str(), STEP_PREPARE);
  460. }
  461. // Read the database
  462. Configuration Database;
  463. string DFile = _config->FindFile("Dir::State::cdroms");
  464. if (FileExists(DFile) == true)
  465. {
  466. if (ReadConfigFile(Database,DFile) == false)
  467. return _error->Error("Unable to read the cdrom database %s",
  468. DFile.c_str());
  469. }
  470. // Unmount the CD and get the user to put in the one they want
  471. if (_config->FindB("APT::CDROM::NoMount",false) == false)
  472. {
  473. if(log)
  474. log->Update(_("Unmounting CD-ROM\n"), STEP_UNMOUNT);
  475. UnmountCdrom(CDROM);
  476. if(log) {
  477. log->Update(_("Waiting for disc...\n"), STEP_WAIT);
  478. if(!log->ChangeCdrom()) {
  479. // user aborted
  480. return false;
  481. }
  482. }
  483. // Mount the new CDROM
  484. log->Update(_("Mounting CD-ROM...\n"), STEP_MOUNT);
  485. if (MountCdrom(CDROM) == false)
  486. return _error->Error("Failed to mount the cdrom.");
  487. }
  488. // Hash the CD to get an ID
  489. if(log)
  490. log->Update(_("Identifying.. "), STEP_IDENT);
  491. string ID;
  492. if (IdentCdrom(CDROM,ID) == false)
  493. {
  494. log->Update("\n");
  495. return false;
  496. }
  497. if(log)
  498. log->Update("["+ID+"]\n");
  499. if(log)
  500. log->Update(_("Scanning Disc for index files..\n"),STEP_SCAN);
  501. // Get the CD structure
  502. vector<string> List;
  503. vector<string> SourceList;
  504. vector<string> SigList;
  505. string StartDir = SafeGetCWD();
  506. string InfoDir;
  507. if (FindPackages(CDROM,List,SourceList, SigList,InfoDir,log) == false)
  508. {
  509. log->Update("\n");
  510. return false;
  511. }
  512. chdir(StartDir.c_str());
  513. if (_config->FindB("Debug::aptcdrom",false) == true)
  514. {
  515. cout << "I found (binary):" << endl;
  516. for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
  517. cout << *I << endl;
  518. cout << "I found (source):" << endl;
  519. for (vector<string>::iterator I = SourceList.begin(); I != SourceList.end(); I++)
  520. cout << *I << endl;
  521. cout << "I found (Signatures):" << endl;
  522. for (vector<string>::iterator I = SigList.begin(); I != SigList.end(); I++)
  523. cout << *I << endl;
  524. }
  525. //log->Update(_("Cleaning package lists..."), STEP_CLEAN);
  526. // Fix up the list
  527. DropBinaryArch(List);
  528. DropRepeats(List,"Packages");
  529. DropRepeats(SourceList,"Sources");
  530. DropRepeats(SigList,"Release.gpg");
  531. if(log) {
  532. msg.str("");
  533. ioprintf(msg, _("Found %i package indexes, %i source indexes and "
  534. "%i signatures\n"),
  535. List.size(), SourceList.size(), SigList.size());
  536. log->Update(msg.str(), STEP_SCAN);
  537. }
  538. if (List.size() == 0 && SourceList.size() == 0)
  539. return _error->Error("Unable to locate any package files, perhaps this is not a Debian Disc");
  540. // Check if the CD is in the database
  541. string Name;
  542. if (Database.Exists("CD::" + ID) == false ||
  543. _config->FindB("APT::CDROM::Rename",false) == true)
  544. {
  545. // Try to use the CDs label if at all possible
  546. if (InfoDir.empty() == false &&
  547. FileExists(InfoDir + "/info") == true)
  548. {
  549. ifstream F(string(InfoDir + "/info").c_str());
  550. if (!F == 0)
  551. getline(F,Name);
  552. if (Name.empty() == false)
  553. {
  554. // Escape special characters
  555. string::iterator J = Name.begin();
  556. for (; J != Name.end(); J++)
  557. if (*J == '"' || *J == ']' || *J == '[')
  558. *J = '_';
  559. if(log) {
  560. msg.str("");
  561. ioprintf(msg, "Found label '%s'\n", Name.c_str());
  562. log->Update(msg.str());
  563. }
  564. Database.Set("CD::" + ID + "::Label",Name);
  565. }
  566. }
  567. if (_config->FindB("APT::CDROM::Rename",false) == true ||
  568. Name.empty() == true)
  569. {
  570. if(!log)
  571. return _error->Error("No disc name found and no way to ask for it");
  572. while(true) {
  573. if(!log->AskCdromName(Name)) {
  574. // user canceld
  575. return false;
  576. }
  577. cout << "Name: '" << Name << "'" << endl;
  578. if (Name.empty() == false &&
  579. Name.find('"') == string::npos &&
  580. Name.find('[') == string::npos &&
  581. Name.find(']') == string::npos)
  582. break;
  583. log->Update(_("That is not a valid name, try again.\n"));
  584. }
  585. }
  586. }
  587. else
  588. Name = Database.Find("CD::" + ID);
  589. // Escape special characters
  590. string::iterator J = Name.begin();
  591. for (; J != Name.end(); J++)
  592. if (*J == '"' || *J == ']' || *J == '[')
  593. *J = '_';
  594. Database.Set("CD::" + ID,Name);
  595. if(log) {
  596. msg.str("");
  597. ioprintf(msg, _("This Disc is called: \n'%s'\n"), Name.c_str());
  598. log->Update(msg.str());
  599. }
  600. log->Update(_("Copying package lists..."), STEP_COPY);
  601. // take care of the signatures and copy them if they are ok
  602. // (we do this before PackageCopy as it modifies "List" and "SourceList")
  603. SigVerify SignVerify;
  604. SignVerify.CopyAndVerify(CDROM, Name, SigList, List, SourceList);
  605. // Copy the package files to the state directory
  606. PackageCopy Copy;
  607. SourceCopy SrcCopy;
  608. if (Copy.CopyPackages(CDROM,Name,List, log) == false ||
  609. SrcCopy.CopyPackages(CDROM,Name,SourceList, log) == false)
  610. return false;
  611. // reduce the List so that it takes less space in sources.list
  612. ReduceSourcelist(CDROM,List);
  613. ReduceSourcelist(CDROM,SourceList);
  614. // Write the database and sourcelist
  615. if (_config->FindB("APT::cdrom::NoAct",false) == false)
  616. {
  617. if (WriteDatabase(Database) == false)
  618. return false;
  619. if(log) {
  620. log->Update(_("Writing new source list\n"), STEP_WRITE);
  621. }
  622. if (WriteSourceList(Name,List,false) == false ||
  623. WriteSourceList(Name,SourceList,true) == false)
  624. return false;
  625. }
  626. // Print the sourcelist entries
  627. if(log)
  628. log->Update(_("Source List entries for this Disc are:\n"));
  629. for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
  630. {
  631. string::size_type Space = (*I).find(' ');
  632. if (Space == string::npos)
  633. return _error->Error("Internal error");
  634. if(log) {
  635. msg.str("");
  636. msg << "deb cdrom:[" << Name << "]/" << string(*I,0,Space) <<
  637. " " << string(*I,Space+1) << endl;
  638. log->Update(msg.str());
  639. }
  640. }
  641. for (vector<string>::iterator I = SourceList.begin(); I != SourceList.end(); I++)
  642. {
  643. string::size_type Space = (*I).find(' ');
  644. if (Space == string::npos)
  645. return _error->Error("Internal error");
  646. if(log) {
  647. msg.str("");
  648. msg << "deb-src cdrom:[" << Name << "]/" << string(*I,0,Space) <<
  649. " " << string(*I,Space+1) << endl;
  650. log->Update(msg.str());
  651. }
  652. }
  653. // Unmount and finish
  654. if (_config->FindB("APT::CDROM::NoMount",false) == false) {
  655. log->Update(_("Unmounting CD-ROM..."), STEP_LAST);
  656. UnmountCdrom(CDROM);
  657. }
  658. return true;
  659. }