Arranged to rename downloaded files to include all impo...
authorArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 16:52:39 +0000 (16:52 +0000)
committerArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 16:52:39 +0000 (16:52 +0000)
Author: jgg
Date: 1999-02-01 02:22:11 GMT
Arranged to rename downloaded files to include all important info

apt-pkg/acquire-item.cc
apt-pkg/acquire-item.h
apt-pkg/cacheiterators.h
apt-pkg/deb/deblistparser.cc
apt-pkg/pkgcache.h
doc/cache.sgml

index e641900..beb4260 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire-item.cc,v 1.21 1999/01/31 22:25:34 jgg Exp $
+// $Id: acquire-item.cc,v 1.22 1999/02/01 02:22:11 jgg Exp $
 /* ######################################################################
 
    Acquire Item - Item to acquire
@@ -59,7 +59,7 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
    {
       /* This indicates that the file is not available right now but might
          be sometime later. If we do a retry cycle then this should be
-        retried */
+        retried [CDROMs] */
       if (Cnf->LocalOnly == true &&
          StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
       {
@@ -75,7 +75,8 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
                                                                        /*}}}*/
 // Acquire::Item::Start - Item has begun to download                   /*{{{*/
 // ---------------------------------------------------------------------
-/* */
+/* Stash status and the file size. Note that setting Complete means 
+   sub-phases of the acquire process such as decompresion are operating */
 void pkgAcquire::Item::Start(string Message,unsigned long Size)
 {
    Status = StatFetching;
@@ -349,7 +350,8 @@ void pkgAcqIndexRel::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
 
 // AcqArchive::AcqArchive - Constructor                                        /*{{{*/
 // ---------------------------------------------------------------------
-/* */
+/* This just sets up the initial fetch environment and queues the first
+   possibilitiy */
 pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
                             pkgRecords *Recs,pkgCache::VerIterator const &Version,
                             string &StoreFilename) :
@@ -358,6 +360,11 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
 {
    Retries = _config->FindI("Acquire::Retries",0);
       
+   // Generate the final file name as: package_version_arch.deb
+   StoreFilename = QuoteString(Version.ParentPkg().Name(),"_:") + '_' +
+                   QuoteString(Version.VerStr(),"_:") + '_' +
+                   QuoteString(Version.Arch(),"_:") + ".deb";
+   
    // Select a source
    if (QueueNext() == false && _error->PendingError() == false)
       _error->Error("I wasn't able to locate file for the %s package. "
@@ -367,7 +374,9 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
                                                                        /*}}}*/
 // AcqArchive::QueueNext - Queue the next file source                  /*{{{*/
 // ---------------------------------------------------------------------
-/* This queues the next available file version for download. */
+/* This queues the next available file version for download. It checks if
+   the archive is already available in the cache and stashs the MD5 for
+   checking later. */
 bool pkgAcqArchive::QueueNext()
 {
    for (; Vf.end() == false; Vf++)
@@ -398,7 +407,7 @@ bool pkgAcqArchive::QueueNext()
                              "field for package %s."
                              ,Version.ParentPkg().Name());
 
-      // See if we already have the file.
+      // See if we already have the file. (Legacy filenames)
       FileSize = Version->Size;
       string FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile);
       struct stat Buf;
@@ -418,8 +427,27 @@ bool pkgAcqArchive::QueueNext()
            happen.. */
         unlink(FinalFile.c_str());
       }
-      
-      DestFile = _config->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(PkgFile);
+
+      // Check it again using the new style output filenames
+      FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename);
+      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;
+           StoreFilename = DestFile = FinalFile;
+           return true;
+        }
+        
+        /* 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(StoreFilename);
       
       // Create the item
       Desc.URI = Location->ArchiveURI(PkgFile);
@@ -479,7 +507,7 @@ void pkgAcqArchive::Done(string Message,unsigned long Size,string Md5Hash)
    
    // Done, move it into position
    string FinalFile = _config->FindDir("Dir::Cache::Archives");
-   FinalFile += flNotDir(DestFile);
+   FinalFile += flNotDir(StoreFilename);
    Rename(DestFile,FinalFile);
    
    StoreFilename = DestFile = FinalFile;
index 4429b1c..fd01bbb 100644 (file)
@@ -1,19 +1,19 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire-item.h,v 1.15 1999/01/31 22:25:34 jgg Exp $
+// $Id: acquire-item.h,v 1.16 1999/02/01 02:22:11 jgg Exp $
 /* ######################################################################
 
    Acquire Item - Item to acquire
 
    When an item is instantiated it will add it self to the local list in
    the Owner Acquire class. Derived classes will then call QueueURI to 
-   register all the URI's they wish to fetch for at the initial moment.   
+   register all the URI's they wish to fetch at the initial moment.   
    
    Two item classes are provided to provide functionality for downloading
    of Index files and downloading of Packages.
    
    A Archive class is provided for downloading .deb files. It does Md5
-   checking and source location.
+   checking and source location as well as a retry algorithm.
    
    ##################################################################### */
                                                                        /*}}}*/
@@ -33,11 +33,13 @@ class pkgAcquire::Item
 {  
    protected:
    
+   // Some private helper methods for registering URIs
    pkgAcquire *Owner;
    inline void QueueURI(ItemDesc &Item)
                  {Owner->Enqueue(Item);};
    inline void Dequeue() {Owner->Dequeue(this);};
    
+   // Safe rename function with timestamp preservation
    void Rename(string From,string To);
    
    public:
@@ -57,14 +59,16 @@ class pkgAcquire::Item
    // File to write the fetch into
    string DestFile;
 
+   // Action members invoked by the worker
    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
    virtual void Done(string Message,unsigned long Size,string Md5Hash);
    virtual void Start(string Message,unsigned long Size);
+   virtual string Custom600Headers() {return string();};
+   
+   // Inquire functions
    virtual string MD5Sum() {return string();};
    virtual string Describe() = 0;
-   
-   virtual string Custom600Headers() {return string();};
-      
+         
    Item(pkgAcquire *Owner);
    virtual ~Item();
 };
@@ -81,6 +85,7 @@ class pkgAcqIndex : public pkgAcquire::Item
    
    public:
    
+   // Specialized action members
    virtual void Done(string Message,unsigned long Size,string Md5Hash);   
    virtual string Custom600Headers();
    virtual string Describe();
@@ -98,6 +103,7 @@ class pkgAcqIndexRel : public pkgAcquire::Item
    
    public:
    
+   // Specialized action members
    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
    virtual void Done(string Message,unsigned long Size,string Md5Hash);   
    virtual string Custom600Headers();
@@ -111,6 +117,7 @@ class pkgAcqArchive : public pkgAcquire::Item
 {
    protected:
    
+   // State information for the retry mechanism
    pkgCache::VerIterator Version;
    pkgAcquire::ItemDesc Desc;
    pkgSourceList *Sources;
@@ -119,15 +126,17 @@ class pkgAcqArchive : public pkgAcquire::Item
    string &StoreFilename;
    pkgCache::VerFileIterator Vf;
    unsigned int Retries;
-   
+
+   // Queue the next available file for download.
    bool QueueNext();
    
    public:
    
+   // Specialized action members
    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
-   virtual string MD5Sum() {return MD5;};
    virtual void Done(string Message,unsigned long Size,string Md5Hash);
    virtual string Describe();
+   virtual string MD5Sum() {return MD5;};
    
    pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
                 pkgRecords *Recs,pkgCache::VerIterator const &Version,
index 1de5746..6e71e8c 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: cacheiterators.h,v 1.11 1998/12/14 08:07:28 jgg Exp $
+// $Id: cacheiterators.h,v 1.12 1999/02/01 02:22:11 jgg Exp $
 /* ######################################################################
    
    Cache Iterators - Iterators for navigating the cache structure
@@ -120,6 +120,7 @@ class pkgCache::VerIterator
    
    inline const char *VerStr() const {return Ver->VerStr == 0?0:Owner.StrP + Ver->VerStr;};
    inline const char *Section() const {return Ver->Section == 0?0:Owner.StrP + Ver->Section;};
+   inline const char *Arch() const {return Ver->Arch == 0?0:Owner.StrP + Ver->Arch;};
    inline PkgIterator ParentPkg() const {return PkgIterator(Owner,Owner.PkgP + Ver->ParentPkg);};
    inline DepIterator DependsList() const;
    inline PrvIterator ProvidesList() const;
index 4797694..d6f25bd 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: deblistparser.cc,v 1.14 1999/01/27 02:48:53 jgg Exp $
+// $Id: deblistparser.cc,v 1.15 1999/02/01 02:22:11 jgg Exp $
 /* ######################################################################
    
    Package Cache Generator - Generator for the cache structure.
@@ -65,6 +65,7 @@ bool debListParser::NewVersion(pkgCache::VerIterator Ver)
 {
    // Parse the section
    Ver->Section = UniqFindTagWrite("Section");
+   Ver->Arch = UniqFindTagWrite("Architecture");
    
    // Archive Size
    Ver->Size = (unsigned)Section.FindI("Size");
index 2d174cc..ce9c866 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: pkgcache.h,v 1.15 1998/12/14 08:07:29 jgg Exp $
+// $Id: pkgcache.h,v 1.16 1999/02/01 02:22:11 jgg Exp $
 /* ######################################################################
    
    Cache - Structure definitions for the cache file
@@ -227,7 +227,8 @@ struct pkgCache::Version
 {
    __apt_ptrloc VerStr;            // Stringtable
    __apt_ptrloc Section;           // StringTable (StringItem)
-   
+   __apt_ptrloc Arch;              // StringTable
+      
    // Lists
    __apt_ptrloc FileList;          // VerFile
    __apt_ptrloc NextVer;           // Version
index 7e7328a..2e80838 100644 (file)
@@ -4,7 +4,7 @@
 <title>APT Cache File Format</title>
 
 <author>Jason Gunthorpe <email>jgg@debian.org</email></author>
-<version>$Id: cache.sgml,v 1.5 1998/12/14 08:23:10 jgg Exp $</version>
+<version>$Id: cache.sgml,v 1.6 1999/02/01 02:22:11 jgg Exp $</version>
 
 <abstract>
 This document describes the complete implementation and format of the APT
@@ -414,6 +414,7 @@ VerStr).
    {
       unsigned long VerStr;            // Stringtable
       unsigned long Section;           // StringTable (StringItem)
+      unsigned long Arch;              // StringTable
       
       // Lists
       unsigned long FileList;          // VerFile
@@ -443,6 +444,9 @@ a 0 in all other fields excluding VerStr and Possibly NextVer.
 This string indicates which section it is part of. The string should be
 contained in the StringItem list.
 
+<tag>Arch<item>
+Architecture the package was compiled for.
+
 <tag>NextVer<item>
 Next step in the linked list.