]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-item.cc
Wow
[apt.git] / apt-pkg / acquire-item.cc
index 9f9d082fed52a48d62f6b31ebce776b67b9903c9..532d4e6f2f1c4eb4c62d790b4ccb090cbfc4fc2e 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire-item.cc,v 1.7 1998/11/05 07:21:35 jgg Exp $
+// $Id: acquire-item.cc,v 1.12 1998/11/13 07:08:48 jgg Exp $
 /* ######################################################################
 
    Acquire Item - Item to acquire
@@ -18,6 +18,7 @@
 #endif
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
 #include <strutl.h>
 
 #include <sys/stat.h>
@@ -30,7 +31,9 @@
 // Acquire::Item::Item - Constructor                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), QueueCounter(0)
+pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), FileSize(0),
+                       Mode(0), ID(0), Complete(false), Local(false), 
+                       QueueCounter(0)
 {
    Owner->Add(this);
    Status = StatIdle;
@@ -59,11 +62,29 @@ void pkgAcquire::Item::Failed(string Message)
    }   
 }
                                                                        /*}}}*/
+// Acquire::Item::Start - Item has begun to download                   /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcquire::Item::Start(string Message,unsigned long Size)
+{
+   Status = StatFetching;
+   if (FileSize == 0 && Complete == false)
+      FileSize = Size;
+}
+                                                                       /*}}}*/
 // Acquire::Item::Done - Item downloaded OK                            /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-void pkgAcquire::Item::Done(string,unsigned long,string)
+void pkgAcquire::Item::Done(string Message,unsigned long Size,string)
 {
+   // We just downloaded something..
+   string FileName = LookupTag(Message,"Filename");
+   if (Complete == false && FileName == DestFile)
+   {
+      if (Owner->Log != 0)
+        Owner->Log->Fetched(Size,atoi(LookupTag(Message,"Resume-Point","0").c_str()));
+   }
+   
    Status = StatDone;
    ErrorText = string();
    Owner->Dequeue(this);
@@ -98,8 +119,19 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location)
    
    DestFile = _config->FindDir("Dir::State::lists") + "partial/";
    DestFile += URItoFileName(Location->PackagesURI());
-   
-   QueueURI(Location->PackagesURI() + ".gz",Location->PackagesInfo());
+
+   // Create the item 
+   Desc.URI = Location->PackagesURI() + ".gz";
+   Desc.Description = Location->PackagesInfo();
+   Desc.Owner = this;
+
+   // Set the short description to the archive component
+   if (Location->Dist[Location->Dist.size() - 1] == '/')
+      Desc.ShortDesc = Location->Dist;
+   else
+      Desc.ShortDesc = Location->Dist + '/' + Location->Section;  
+      
+   QueueURI(Desc);
    
    // Create the Release fetch class
    new pkgAcqIndexRel(Owner,Location);
@@ -138,17 +170,19 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string MD5)
       FinalFile += URItoFileName(Location->PackagesURI());
       Rename(DestFile,FinalFile);
       
+      /* We restore the original name to DestFile so that the clean operation
+         will work OK */
+      DestFile = _config->FindDir("Dir::State::lists") + "partial/";
+      DestFile += URItoFileName(Location->PackagesURI());
+      
       // Remove the compressed version.
       if (Erase == true)
-      {
-        DestFile = _config->FindDir("Dir::State::lists") + "partial/";
-        DestFile += URItoFileName(Location->PackagesURI());
         unlink(DestFile.c_str());
-      }      
       return;
    }
 
    Erase = false;
+   Complete = true;
    
    // Handle the unzipd case
    string FileName = LookupTag(Message,"Alt-Filename");
@@ -159,8 +193,11 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string MD5)
         return;
       
       Decompression = true;
+      Local = true;
       DestFile += ".decomp";
-      QueueURI("copy:" + FileName,string());
+      Desc.URI = "copy:" + FileName;
+      QueueURI(Desc);
+      Mode = "copy";
       return;
    }
 
@@ -177,10 +214,14 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string MD5)
 
    if (FileName == DestFile)
       Erase = true;
+   else
+      Local = true;
    
    Decompression = true;
    DestFile += ".decomp";
-   QueueURI("gzip:" + FileName,string());
+   Desc.URI = "gzip:" + FileName,Location->PackagesInfo();
+   QueueURI(Desc);
+   Mode = "gzip";
 }
                                                                        /*}}}*/
 
@@ -194,7 +235,18 @@ pkgAcqIndexRel::pkgAcqIndexRel(pkgAcquire *Owner,
    DestFile = _config->FindDir("Dir::State::lists") + "partial/";
    DestFile += URItoFileName(Location->ReleaseURI());
    
-   QueueURI(Location->ReleaseURI(),Location->ReleaseInfo());
+   // Create the item
+   Desc.URI = Location->ReleaseURI();
+   Desc.Description = Location->ReleaseInfo();
+   Desc.Owner = this;
+
+   // Set the short description to the archive component
+   if (Location->Dist[Location->Dist.size() - 1] == '/')
+      Desc.ShortDesc = Location->Dist;
+   else
+      Desc.ShortDesc = Location->Dist + '/' + Location->Section;  
+      
+   QueueURI(Desc);
 }
                                                                        /*}}}*/
 // AcqIndexRel::Custom600Headers - Insert custom request headers       /*{{{*/
@@ -229,6 +281,8 @@ void pkgAcqIndexRel::Done(string Message,unsigned long Size,string MD5)
       return;
    }
 
+   Complete = true;
+   
    // The files timestamp matches
    if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
       return;
@@ -236,7 +290,9 @@ void pkgAcqIndexRel::Done(string Message,unsigned long Size,string MD5)
    // We have to copy it into place
    if (FileName != DestFile)
    {
-      QueueURI("copy:" + FileName,string());
+      Local = true;
+      Desc.URI = "copy:" + FileName;
+      QueueURI(Desc);
       return;
    }
    
@@ -246,3 +302,134 @@ void pkgAcqIndexRel::Done(string Message,unsigned long Size,string MD5)
    Rename(DestFile,FinalFile);
 }
                                                                        /*}}}*/
+
+// AcqArchive::AcqArchive - Constructor                                        /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
+                            pkgRecords *Recs,pkgCache::VerIterator const &Version) :
+               Item(Owner), Version(Version), Sources(Sources), Recs(Recs)
+{
+   // Select a source
+   pkgCache::VerFileIterator Vf = Version.FileList();
+   for (; Vf.end() == false; Vf++)
+   {
+      // Ignore not source sources
+      if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0)
+        continue;
+
+      // Try to cross match against the source list
+      string PkgFile = flNotDir(Vf.File().FileName());
+      pkgSourceList::const_iterator Location;
+      for (Location = Sources->begin(); Location != Sources->end(); Location++)
+        if (PkgFile == URItoFileName(Location->PackagesURI()))
+           break;
+
+      if (Location == Sources->end())
+        continue;
+      
+      // Grab the text package record
+      pkgRecords::Parser &Parse = Recs->Lookup(Vf);
+      if (_error->PendingError() == true)
+        return;
+      
+      PkgFile = Parse.FileName();
+      MD5 = Parse.MD5Hash();
+      if (PkgFile.empty() == true)
+      {
+        _error->Error("Unable to locate a file name for package %s, "
+                      "perhaps the package files are corrupted.",
+                      Version.ParentPkg().Name());
+        return;
+      }
+
+      // See if we already have the file.
+      FileSize = Version->Size;
+      string FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile);
+      struct stat Buf;
+      if (stat(FinalFile.c_str(),&Buf) == 0)
+      {
+        // Make sure the size matches
+        if ((unsigned)Buf.st_size == Version->Size)
+        {
+           Complete = true;
+           Local = true;
+           Status = StatDone;
+           DestFile = FinalFile;
+           return;
+        }
+        
+        /* Hmm, we have a file and its size does not match, this shouldnt
+           happen.. */
+        unlink(FinalFile.c_str());
+      }
+      
+      DestFile = _config->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(PkgFile);
+      
+      // Create the item
+      Desc.URI = Location->ArchiveURI(PkgFile);
+      Desc.Description = Location->ArchiveInfo(Version);
+      Desc.Owner = this;
+      Desc.ShortDesc = Version.ParentPkg().Name();
+      QueueURI(Desc);
+      
+      return;
+   }
+   
+  _error->Error("I wasn't able to locate file for the %s package. "
+               "This probably means you need to rerun update.",
+               Version.ParentPkg().Name());
+}
+                                                                       /*}}}*/
+// AcqArchive::Done - Finished fetching                                        /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcqArchive::Done(string Message,unsigned long Size,string Md5Hash)
+{
+   Item::Done(Message,Size,MD5);
+   
+   // Check the size
+   if (Size != Version->Size)
+   {
+      _error->Error("Size mismatch for package %s",Version.ParentPkg().Name());
+      return;
+   }
+   
+   // Check the md5
+   if (Md5Hash.empty() == false && MD5.empty() == false)
+   {
+      if (Md5Hash != MD5)
+      {
+        _error->Error("MD5Sum mismatch for package %s",Version.ParentPkg().Name());
+        return;
+      }
+   }
+
+   // Grab the output filename
+   string FileName = LookupTag(Message,"Filename");
+   if (FileName.empty() == true)
+   {
+      Status = StatError;
+      ErrorText = "Method gave a blank filename";
+      return;
+   }
+
+   Complete = true;
+   
+   // We have to copy it into place
+   if (FileName != DestFile)
+   {
+      DestFile = FileName;
+      Local = true;
+      return;
+   }
+   
+   // Done, move it into position
+   string FinalFile = _config->FindDir("Dir::Cache::Archives");
+   FinalFile += flNotDir(DestFile);
+   Rename(DestFile,FinalFile);
+   
+   DestFile = FinalFile;
+   Complete = true;
+}
+                                                                       /*}}}*/