]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-worker.cc
Working acquire code
[apt.git] / apt-pkg / acquire-worker.cc
index 58f67d979506bdaeefa7b224ccef9853a8554b58..2cbab7720464a8c0fe3bad9c389f3139f6ab13a2 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire-worker.cc,v 1.5 1998/10/23 00:49:58 jgg Exp $
+// $Id: acquire-worker.cc,v 1.10 1998/11/05 07:21:39 jgg Exp $
 /* ######################################################################
 
    Acquire Worker 
@@ -106,7 +106,9 @@ bool pkgAcquire::Worker::Start()
         close(Pipes[I]);
       return false;
    }
-      
+   for (int I = 0; I != 4; I++)
+      SetCloseExec(Pipes[0],true);
+   
    // Fork off the process
    Process = fork();
    if (Process < 0)
@@ -122,8 +124,6 @@ bool pkgAcquire::Worker::Start()
       dup2(Pipes[1],STDOUT_FILENO);
       dup2(Pipes[2],STDIN_FILENO);
       dup2(((filebuf *)clog.rdbuf())->fd(),STDERR_FILENO);
-      for (int I = 0; I != 4; I++)
-        close(Pipes[I]);
       SetCloseExec(STDOUT_FILENO,false);
       SetCloseExec(STDIN_FILENO,false);      
       SetCloseExec(STDERR_FILENO,false);
@@ -152,7 +152,8 @@ bool pkgAcquire::Worker::Start()
       return _error->Error("Method %s did not start correctly",Method.c_str());
 
    RunMessages();
-   SendConfiguration();
+   if (OwnerQ != 0)
+      SendConfiguration();
    
    return true;
 }
@@ -187,6 +188,11 @@ bool pkgAcquire::Worker::RunMessages()
       if (End == Message.c_str())
         return _error->Error("Invalid message from method %s: %s",Access.c_str(),Message.c_str());
 
+      string URI = LookupTag(Message,"URI");
+      pkgAcquire::Queue::QItem *Itm = 0;
+      if (URI.empty() == false)
+        Itm = OwnerQ->FindItem(URI,this);
+      
       // Determine the message number and dispatch
       switch (Number)
       {
@@ -209,15 +215,49 @@ bool pkgAcquire::Worker::RunMessages()
            
         // 200 URI Start
         case 200:
-        break;
+        {
+           if (Itm == 0)
+           {
+              _error->Error("Method gave invalid 200 URI Start message");
+              break;
+           }
+           CurrentItem = Itm;
+           CurrentSize = 0;
+           TotalSize = atoi(LookupTag(Message,"Size","0").c_str());
+           
+           break;
+        }
         
         // 201 URI Done
         case 201:
-        break;
+        {
+           if (Itm == 0)
+           {
+              _error->Error("Method gave invalid 201 URI Done message");
+              break;
+           }
+
+           pkgAcquire::Item *Owner = Itm->Owner;
+           OwnerQ->ItemDone(Itm);
+           Owner->Done(Message,atoi(LookupTag(Message,"Size","0").c_str()),
+                                         LookupTag(Message,"MD5-Hash"));
+           break;
+        }       
         
         // 400 URI Failure
         case 400:
-        break;
+        {
+           if (Itm == 0)
+           {
+              _error->Error("Method gave invalid 400 URI Failure message");
+              break;
+           }
+
+           pkgAcquire::Item *Owner = Itm->Owner;
+           OwnerQ->ItemDone(Itm);
+           Owner->Failed(Message);
+           break;
+        }       
         
         // 401 General Failure
         case 401: