acquire-worker.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire-worker.cc,v 1.34 2001/05/22 04:42:54 jgg Exp $
  4. /* ######################################################################
  5. Acquire Worker
  6. The worker process can startup either as a Configuration prober
  7. or as a queue runner. As a configuration prober it only reads the
  8. configuration message and
  9. ##################################################################### */
  10. /*}}}*/
  11. // Include Files /*{{{*/
  12. #include <config.h>
  13. #include <apt-pkg/acquire.h>
  14. #include <apt-pkg/acquire-worker.h>
  15. #include <apt-pkg/acquire-item.h>
  16. #include <apt-pkg/configuration.h>
  17. #include <apt-pkg/error.h>
  18. #include <apt-pkg/fileutl.h>
  19. #include <apt-pkg/strutl.h>
  20. #include <apt-pkg/hashes.h>
  21. #include <string>
  22. #include <vector>
  23. #include <iostream>
  24. #include <sstream>
  25. #include <sys/stat.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include <signal.h>
  29. #include <stdio.h>
  30. #include <errno.h>
  31. #include <sys/types.h>
  32. #include <pwd.h>
  33. #include <grp.h>
  34. #include <apti18n.h>
  35. /*}}}*/
  36. using namespace std;
  37. static void ChangeOwnerAndPermissionOfFile(char const * const requester, char const * const file, char const * const user, char const * const group, mode_t const mode) /*{{{*/
  38. {
  39. if (getuid() == 0 && strlen(user) != 0 && strlen(group) != 0) // if we aren't root, we can't chown, so don't try it
  40. {
  41. // ensure the file is owned by root and has good permissions
  42. struct passwd const * const pw = getpwnam(user);
  43. struct group const * const gr = getgrnam(group);
  44. if (pw != NULL && gr != NULL && chown(file, pw->pw_uid, gr->gr_gid) != 0)
  45. _error->WarningE(requester, "chown to %s:%s of file %s failed", user, group, file);
  46. }
  47. if (chmod(file, mode) != 0)
  48. _error->WarningE(requester, "chmod 0%o of file %s failed", mode, file);
  49. }
  50. /*}}}*/
  51. // Worker::Worker - Constructor for Queue startup /*{{{*/
  52. // ---------------------------------------------------------------------
  53. /* */
  54. pkgAcquire::Worker::Worker(Queue *Q,MethodConfig *Cnf,
  55. pkgAcquireStatus *Log) : Log(Log)
  56. {
  57. OwnerQ = Q;
  58. Config = Cnf;
  59. Access = Cnf->Access;
  60. CurrentItem = 0;
  61. TotalSize = 0;
  62. CurrentSize = 0;
  63. Construct();
  64. }
  65. /*}}}*/
  66. // Worker::Worker - Constructor for method config startup /*{{{*/
  67. // ---------------------------------------------------------------------
  68. /* */
  69. pkgAcquire::Worker::Worker(MethodConfig *Cnf)
  70. {
  71. OwnerQ = 0;
  72. Config = Cnf;
  73. Access = Cnf->Access;
  74. CurrentItem = 0;
  75. TotalSize = 0;
  76. CurrentSize = 0;
  77. Construct();
  78. }
  79. /*}}}*/
  80. // Worker::Construct - Constructor helper /*{{{*/
  81. // ---------------------------------------------------------------------
  82. /* */
  83. void pkgAcquire::Worker::Construct()
  84. {
  85. NextQueue = 0;
  86. NextAcquire = 0;
  87. Process = -1;
  88. InFd = -1;
  89. OutFd = -1;
  90. OutReady = false;
  91. InReady = false;
  92. Debug = _config->FindB("Debug::pkgAcquire::Worker",false);
  93. }
  94. /*}}}*/
  95. // Worker::~Worker - Destructor /*{{{*/
  96. // ---------------------------------------------------------------------
  97. /* */
  98. pkgAcquire::Worker::~Worker()
  99. {
  100. close(InFd);
  101. close(OutFd);
  102. if (Process > 0)
  103. {
  104. /* Closing of stdin is the signal to exit and die when the process
  105. indicates it needs cleanup */
  106. if (Config->NeedsCleanup == false)
  107. kill(Process,SIGINT);
  108. ExecWait(Process,Access.c_str(),true);
  109. }
  110. }
  111. /*}}}*/
  112. // Worker::Start - Start the worker process /*{{{*/
  113. // ---------------------------------------------------------------------
  114. /* This forks the method and inits the communication channel */
  115. bool pkgAcquire::Worker::Start()
  116. {
  117. // Get the method path
  118. string Method = _config->FindDir("Dir::Bin::Methods") + Access;
  119. if (FileExists(Method) == false)
  120. {
  121. _error->Error(_("The method driver %s could not be found."),Method.c_str());
  122. if (Access == "https")
  123. _error->Notice(_("Is the package %s installed?"), "apt-transport-https");
  124. return false;
  125. }
  126. if (Debug == true)
  127. clog << "Starting method '" << Method << '\'' << endl;
  128. // Create the pipes
  129. int Pipes[4] = {-1,-1,-1,-1};
  130. if (pipe(Pipes) != 0 || pipe(Pipes+2) != 0)
  131. {
  132. _error->Errno("pipe","Failed to create IPC pipe to subprocess");
  133. for (int I = 0; I != 4; I++)
  134. close(Pipes[I]);
  135. return false;
  136. }
  137. for (int I = 0; I != 4; I++)
  138. SetCloseExec(Pipes[I],true);
  139. // Fork off the process
  140. Process = ExecFork();
  141. if (Process == 0)
  142. {
  143. // Setup the FDs
  144. dup2(Pipes[1],STDOUT_FILENO);
  145. dup2(Pipes[2],STDIN_FILENO);
  146. SetCloseExec(STDOUT_FILENO,false);
  147. SetCloseExec(STDIN_FILENO,false);
  148. SetCloseExec(STDERR_FILENO,false);
  149. const char *Args[2];
  150. Args[0] = Method.c_str();
  151. Args[1] = 0;
  152. execv(Args[0],(char **)Args);
  153. cerr << "Failed to exec method " << Args[0] << endl;
  154. _exit(100);
  155. }
  156. // Fix up our FDs
  157. InFd = Pipes[0];
  158. OutFd = Pipes[3];
  159. SetNonBlock(Pipes[0],true);
  160. SetNonBlock(Pipes[3],true);
  161. close(Pipes[1]);
  162. close(Pipes[2]);
  163. OutReady = false;
  164. InReady = true;
  165. // Read the configuration data
  166. if (WaitFd(InFd) == false ||
  167. ReadMessages() == false)
  168. return _error->Error(_("Method %s did not start correctly"),Method.c_str());
  169. RunMessages();
  170. if (OwnerQ != 0)
  171. SendConfiguration();
  172. return true;
  173. }
  174. /*}}}*/
  175. // Worker::ReadMessages - Read all pending messages into the list /*{{{*/
  176. // ---------------------------------------------------------------------
  177. /* */
  178. bool pkgAcquire::Worker::ReadMessages()
  179. {
  180. if (::ReadMessages(InFd,MessageQueue) == false)
  181. return MethodFailure();
  182. return true;
  183. }
  184. /*}}}*/
  185. // Worker::RunMessage - Empty the message queue /*{{{*/
  186. // ---------------------------------------------------------------------
  187. /* This takes the messages from the message queue and runs them through
  188. the parsers in order. */
  189. bool pkgAcquire::Worker::RunMessages()
  190. {
  191. while (MessageQueue.empty() == false)
  192. {
  193. string Message = MessageQueue.front();
  194. MessageQueue.erase(MessageQueue.begin());
  195. if (Debug == true)
  196. clog << " <- " << Access << ':' << QuoteString(Message,"\n") << endl;
  197. // Fetch the message number
  198. char *End;
  199. int Number = strtol(Message.c_str(),&End,10);
  200. if (End == Message.c_str())
  201. return _error->Error("Invalid message from method %s: %s",Access.c_str(),Message.c_str());
  202. string URI = LookupTag(Message,"URI");
  203. pkgAcquire::Queue::QItem *Itm = 0;
  204. if (URI.empty() == false)
  205. Itm = OwnerQ->FindItem(URI,this);
  206. // update used mirror
  207. string UsedMirror = LookupTag(Message,"UsedMirror", "");
  208. if (!UsedMirror.empty() &&
  209. Itm &&
  210. Itm->Description.find(" ") != string::npos)
  211. {
  212. Itm->Description.replace(0, Itm->Description.find(" "), UsedMirror);
  213. // FIXME: will we need this as well?
  214. //Itm->ShortDesc = UsedMirror;
  215. }
  216. // Determine the message number and dispatch
  217. switch (Number)
  218. {
  219. // 100 Capabilities
  220. case 100:
  221. if (Capabilities(Message) == false)
  222. return _error->Error("Unable to process Capabilities message from %s",Access.c_str());
  223. break;
  224. // 101 Log
  225. case 101:
  226. if (Debug == true)
  227. clog << " <- (log) " << LookupTag(Message,"Message") << endl;
  228. break;
  229. // 102 Status
  230. case 102:
  231. Status = LookupTag(Message,"Message");
  232. break;
  233. // 103 Redirect
  234. case 103:
  235. {
  236. if (Itm == 0)
  237. {
  238. _error->Error("Method gave invalid 103 Redirect message");
  239. break;
  240. }
  241. string NewURI = LookupTag(Message,"New-URI",URI.c_str());
  242. Itm->URI = NewURI;
  243. ItemDone();
  244. pkgAcquire::Item *Owner = Itm->Owner;
  245. pkgAcquire::ItemDesc Desc = *Itm;
  246. // Change the status so that it can be dequeued
  247. Owner->Status = pkgAcquire::Item::StatIdle;
  248. // Mark the item as done (taking care of all queues)
  249. // and then put it in the main queue again
  250. OwnerQ->ItemDone(Itm);
  251. OwnerQ->Owner->Enqueue(Desc);
  252. if (Log != 0)
  253. Log->Done(Desc);
  254. break;
  255. }
  256. // 200 URI Start
  257. case 200:
  258. {
  259. if (Itm == 0)
  260. {
  261. _error->Error("Method gave invalid 200 URI Start message");
  262. break;
  263. }
  264. CurrentItem = Itm;
  265. CurrentSize = 0;
  266. TotalSize = strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10);
  267. ResumePoint = strtoull(LookupTag(Message,"Resume-Point","0").c_str(), NULL, 10);
  268. Itm->Owner->Start(Message,strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10));
  269. // Display update before completion
  270. if (Log != 0 && Log->MorePulses == true)
  271. Log->Pulse(Itm->Owner->GetOwner());
  272. if (Log != 0)
  273. Log->Fetch(*Itm);
  274. break;
  275. }
  276. // 201 URI Done
  277. case 201:
  278. {
  279. if (Itm == 0)
  280. {
  281. _error->Error("Method gave invalid 201 URI Done message");
  282. break;
  283. }
  284. pkgAcquire::Item *Owner = Itm->Owner;
  285. pkgAcquire::ItemDesc Desc = *Itm;
  286. if (RealFileExists(Owner->DestFile))
  287. ChangeOwnerAndPermissionOfFile("201::URIDone", Owner->DestFile.c_str(), "root", "root", 0644);
  288. // Display update before completion
  289. if (Log != 0 && Log->MorePulses == true)
  290. Log->Pulse(Owner->GetOwner());
  291. OwnerQ->ItemDone(Itm);
  292. unsigned long long const ServerSize = strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10);
  293. bool isHit = StringToBool(LookupTag(Message,"IMS-Hit"),false) ||
  294. StringToBool(LookupTag(Message,"Alt-IMS-Hit"),false);
  295. // Using the https method the server might return 200, but the
  296. // If-Modified-Since condition is not satsified, libcurl will
  297. // discard the download. In this case, however, TotalSize will be
  298. // set to the actual size of the file, while ServerSize will be set
  299. // to 0. Therefore, if the item is marked as a hit and the
  300. // downloaded size (ServerSize) is 0, we ignore TotalSize.
  301. if (TotalSize != 0 && (!isHit || ServerSize != 0) && ServerSize != TotalSize)
  302. _error->Warning("Size of file %s is not what the server reported %s %llu",
  303. Owner->DestFile.c_str(), LookupTag(Message,"Size","0").c_str(),TotalSize);
  304. // see if there is a hash to verify
  305. HashStringList ReceivedHashes;
  306. HashStringList expectedHashes = Owner->HashSums();
  307. for (HashStringList::const_iterator hs = expectedHashes.begin(); hs != expectedHashes.end(); ++hs)
  308. {
  309. std::string const tagname = hs->HashType() + "-Hash";
  310. std::string const hashsum = LookupTag(Message, tagname.c_str());
  311. if (hashsum.empty() == false)
  312. ReceivedHashes.push_back(HashString(hs->HashType(), hashsum));
  313. }
  314. if(_config->FindB("Debug::pkgAcquire::Auth", false) == true)
  315. {
  316. std::clog << "201 URI Done: " << Owner->DescURI() << endl
  317. << "ReceivedHash:" << endl;
  318. for (HashStringList::const_iterator hs = ReceivedHashes.begin(); hs != ReceivedHashes.end(); ++hs)
  319. std::clog << "\t- " << hs->toStr() << std::endl;
  320. std::clog << "ExpectedHash:" << endl;
  321. for (HashStringList::const_iterator hs = expectedHashes.begin(); hs != expectedHashes.end(); ++hs)
  322. std::clog << "\t- " << hs->toStr() << std::endl;
  323. std::clog << endl;
  324. }
  325. Owner->Done(Message, ServerSize, ReceivedHashes, Config);
  326. ItemDone();
  327. // Log that we are done
  328. if (Log != 0)
  329. {
  330. if (isHit)
  331. {
  332. /* Hide 'hits' for local only sources - we also manage to
  333. hide gets */
  334. if (Config->LocalOnly == false)
  335. Log->IMSHit(Desc);
  336. }
  337. else
  338. Log->Done(Desc);
  339. }
  340. break;
  341. }
  342. // 400 URI Failure
  343. case 400:
  344. {
  345. if (Itm == 0)
  346. {
  347. std::string const msg = LookupTag(Message,"Message");
  348. _error->Error("Method gave invalid 400 URI Failure message: %s", msg.c_str());
  349. break;
  350. }
  351. // Display update before completion
  352. if (Log != 0 && Log->MorePulses == true)
  353. Log->Pulse(Itm->Owner->GetOwner());
  354. pkgAcquire::Item *Owner = Itm->Owner;
  355. pkgAcquire::ItemDesc Desc = *Itm;
  356. if (RealFileExists(Owner->DestFile))
  357. ChangeOwnerAndPermissionOfFile("400::URIFailure", Owner->DestFile.c_str(), "root", "root", 0644);
  358. OwnerQ->ItemDone(Itm);
  359. // set some status
  360. if(LookupTag(Message,"FailReason") == "Timeout" ||
  361. LookupTag(Message,"FailReason") == "TmpResolveFailure" ||
  362. LookupTag(Message,"FailReason") == "ResolveFailure" ||
  363. LookupTag(Message,"FailReason") == "ConnectionRefused")
  364. Owner->Status = pkgAcquire::Item::StatTransientNetworkError;
  365. Owner->Failed(Message,Config);
  366. ItemDone();
  367. if (Log != 0)
  368. Log->Fail(Desc);
  369. break;
  370. }
  371. // 401 General Failure
  372. case 401:
  373. _error->Error("Method %s General failure: %s",Access.c_str(),LookupTag(Message,"Message").c_str());
  374. break;
  375. // 403 Media Change
  376. case 403:
  377. MediaChange(Message);
  378. break;
  379. }
  380. }
  381. return true;
  382. }
  383. /*}}}*/
  384. // Worker::Capabilities - 100 Capabilities handler /*{{{*/
  385. // ---------------------------------------------------------------------
  386. /* This parses the capabilities message and dumps it into the configuration
  387. structure. */
  388. bool pkgAcquire::Worker::Capabilities(string Message)
  389. {
  390. if (Config == 0)
  391. return true;
  392. Config->Version = LookupTag(Message,"Version");
  393. Config->SingleInstance = StringToBool(LookupTag(Message,"Single-Instance"),false);
  394. Config->Pipeline = StringToBool(LookupTag(Message,"Pipeline"),false);
  395. Config->SendConfig = StringToBool(LookupTag(Message,"Send-Config"),false);
  396. Config->LocalOnly = StringToBool(LookupTag(Message,"Local-Only"),false);
  397. Config->NeedsCleanup = StringToBool(LookupTag(Message,"Needs-Cleanup"),false);
  398. Config->Removable = StringToBool(LookupTag(Message,"Removable"),false);
  399. // Some debug text
  400. if (Debug == true)
  401. {
  402. clog << "Configured access method " << Config->Access << endl;
  403. clog << "Version:" << Config->Version <<
  404. " SingleInstance:" << Config->SingleInstance <<
  405. " Pipeline:" << Config->Pipeline <<
  406. " SendConfig:" << Config->SendConfig <<
  407. " LocalOnly: " << Config->LocalOnly <<
  408. " NeedsCleanup: " << Config->NeedsCleanup <<
  409. " Removable: " << Config->Removable << endl;
  410. }
  411. return true;
  412. }
  413. /*}}}*/
  414. // Worker::MediaChange - Request a media change /*{{{*/
  415. // ---------------------------------------------------------------------
  416. /* */
  417. bool pkgAcquire::Worker::MediaChange(string Message)
  418. {
  419. int status_fd = _config->FindI("APT::Status-Fd",-1);
  420. if(status_fd > 0)
  421. {
  422. string Media = LookupTag(Message,"Media");
  423. string Drive = LookupTag(Message,"Drive");
  424. ostringstream msg,status;
  425. ioprintf(msg,_("Please insert the disc labeled: "
  426. "'%s' "
  427. "in the drive '%s' and press enter."),
  428. Media.c_str(),Drive.c_str());
  429. status << "media-change: " // message
  430. << Media << ":" // media
  431. << Drive << ":" // drive
  432. << msg.str() // l10n message
  433. << endl;
  434. std::string const dlstatus = status.str();
  435. FileFd::Write(status_fd, dlstatus.c_str(), dlstatus.size());
  436. }
  437. if (Log == 0 || Log->MediaChange(LookupTag(Message,"Media"),
  438. LookupTag(Message,"Drive")) == false)
  439. {
  440. char S[300];
  441. snprintf(S,sizeof(S),"603 Media Changed\nFailed: true\n\n");
  442. if (Debug == true)
  443. clog << " -> " << Access << ':' << QuoteString(S,"\n") << endl;
  444. OutQueue += S;
  445. OutReady = true;
  446. return true;
  447. }
  448. char S[300];
  449. snprintf(S,sizeof(S),"603 Media Changed\n\n");
  450. if (Debug == true)
  451. clog << " -> " << Access << ':' << QuoteString(S,"\n") << endl;
  452. OutQueue += S;
  453. OutReady = true;
  454. return true;
  455. }
  456. /*}}}*/
  457. // Worker::SendConfiguration - Send the config to the method /*{{{*/
  458. // ---------------------------------------------------------------------
  459. /* */
  460. bool pkgAcquire::Worker::SendConfiguration()
  461. {
  462. if (Config->SendConfig == false)
  463. return true;
  464. if (OutFd == -1)
  465. return false;
  466. /* Write out all of the configuration directives by walking the
  467. configuration tree */
  468. std::ostringstream Message;
  469. Message << "601 Configuration\n";
  470. _config->Dump(Message, NULL, "Config-Item: %F=%V\n", false);
  471. Message << '\n';
  472. if (Debug == true)
  473. clog << " -> " << Access << ':' << QuoteString(Message.str(),"\n") << endl;
  474. OutQueue += Message.str();
  475. OutReady = true;
  476. return true;
  477. }
  478. /*}}}*/
  479. // Worker::QueueItem - Add an item to the outbound queue /*{{{*/
  480. // ---------------------------------------------------------------------
  481. /* Send a URI Acquire message to the method */
  482. bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
  483. {
  484. if (OutFd == -1)
  485. return false;
  486. string Message = "600 URI Acquire\n";
  487. Message.reserve(300);
  488. Message += "URI: " + Item->URI;
  489. Message += "\nFilename: " + Item->Owner->DestFile;
  490. HashStringList const hsl = Item->Owner->HashSums();
  491. for (HashStringList::const_iterator hs = hsl.begin(); hs != hsl.end(); ++hs)
  492. Message += "\nExpected-" + hs->HashType() + ": " + hs->HashValue();
  493. if(Item->Owner->FileSize > 0)
  494. {
  495. string MaximumSize;
  496. strprintf(MaximumSize, "%llu", Item->Owner->FileSize);
  497. Message += "\nMaximum-Size: " + MaximumSize;
  498. }
  499. Message += Item->Owner->Custom600Headers();
  500. Message += "\n\n";
  501. if (RealFileExists(Item->Owner->DestFile))
  502. {
  503. std::string SandboxUser = _config->Find("APT::Sandbox::User");
  504. ChangeOwnerAndPermissionOfFile("Item::QueueURI", Item->Owner->DestFile.c_str(),
  505. SandboxUser.c_str(), "root", 0600);
  506. }
  507. if (Debug == true)
  508. clog << " -> " << Access << ':' << QuoteString(Message,"\n") << endl;
  509. OutQueue += Message;
  510. OutReady = true;
  511. return true;
  512. }
  513. /*}}}*/
  514. // Worker::OutFdRead - Out bound FD is ready /*{{{*/
  515. // ---------------------------------------------------------------------
  516. /* */
  517. bool pkgAcquire::Worker::OutFdReady()
  518. {
  519. int Res;
  520. do
  521. {
  522. Res = write(OutFd,OutQueue.c_str(),OutQueue.length());
  523. }
  524. while (Res < 0 && errno == EINTR);
  525. if (Res <= 0)
  526. return MethodFailure();
  527. OutQueue.erase(0,Res);
  528. if (OutQueue.empty() == true)
  529. OutReady = false;
  530. return true;
  531. }
  532. /*}}}*/
  533. // Worker::InFdRead - In bound FD is ready /*{{{*/
  534. // ---------------------------------------------------------------------
  535. /* */
  536. bool pkgAcquire::Worker::InFdReady()
  537. {
  538. if (ReadMessages() == false)
  539. return false;
  540. RunMessages();
  541. return true;
  542. }
  543. /*}}}*/
  544. // Worker::MethodFailure - Called when the method fails /*{{{*/
  545. // ---------------------------------------------------------------------
  546. /* This is called when the method is believed to have failed, probably because
  547. read returned -1. */
  548. bool pkgAcquire::Worker::MethodFailure()
  549. {
  550. _error->Error("Method %s has died unexpectedly!",Access.c_str());
  551. // do not reap the child here to show meaningfull error to the user
  552. ExecWait(Process,Access.c_str(),false);
  553. Process = -1;
  554. close(InFd);
  555. close(OutFd);
  556. InFd = -1;
  557. OutFd = -1;
  558. OutReady = false;
  559. InReady = false;
  560. OutQueue = string();
  561. MessageQueue.erase(MessageQueue.begin(),MessageQueue.end());
  562. return false;
  563. }
  564. /*}}}*/
  565. // Worker::Pulse - Called periodically /*{{{*/
  566. // ---------------------------------------------------------------------
  567. /* */
  568. void pkgAcquire::Worker::Pulse()
  569. {
  570. if (CurrentItem == 0)
  571. return;
  572. struct stat Buf;
  573. if (stat(CurrentItem->Owner->DestFile.c_str(),&Buf) != 0)
  574. return;
  575. CurrentSize = Buf.st_size;
  576. // Hmm? Should not happen...
  577. if (CurrentSize > TotalSize && TotalSize != 0)
  578. TotalSize = CurrentSize;
  579. }
  580. /*}}}*/
  581. // Worker::ItemDone - Called when the current item is finished /*{{{*/
  582. // ---------------------------------------------------------------------
  583. /* */
  584. void pkgAcquire::Worker::ItemDone()
  585. {
  586. CurrentItem = 0;
  587. CurrentSize = 0;
  588. TotalSize = 0;
  589. Status = string();
  590. }
  591. /*}}}*/