]> git.saurik.com Git - apt.git/commitdiff
merged from lp:~donkult/apt/sid
authorMichael Vogt <michael.vogt@ubuntu.com>
Tue, 8 Feb 2011 09:25:47 +0000 (10:25 +0100)
committerMichael Vogt <michael.vogt@ubuntu.com>
Tue, 8 Feb 2011 09:25:47 +0000 (10:25 +0100)
1  2 
apt-pkg/acquire-item.cc
apt-pkg/acquire-item.h

index 2c4ce91a01496bde3cd24e66982995ffd8d71d3a,77600949317e49d704b8bc2a0cc26dcd0d496cd3..d4df31e85bc067f8267c340a48e929bac176ff46
@@@ -184,6 -184,153 +184,151 @@@ void pkgAcquire::Item::ReportMirrorFail
     }
  }
                                                                        /*}}}*/
 -/* Get the DiffIndex file first and see if there are patches availabe 
 - * If so, create a pkgAcqIndexDiffs fetcher that will get and apply the
 - * patches. If anything goes wrong in that process, it will fall back to
 - * the original packages file
+ // AcqSubIndex::AcqSubIndex - Constructor                             /*{{{*/
+ // ---------------------------------------------------------------------
++/* Get the Index file first and see if there are languages available
++ * If so, create a pkgAcqIndexTrans for the found language(s).
+  */
+ pkgAcqSubIndex::pkgAcqSubIndex(pkgAcquire *Owner, string const &URI,
+                                string const &URIDesc, string const &ShortDesc,
+                                HashString const &ExpectedHash)
+    : Item(Owner), ExpectedHash(ExpectedHash)
+ {
+    Debug = _config->FindB("Debug::pkgAcquire::SubIndex",false);
+    DestFile = _config->FindDir("Dir::State::lists") + "partial/";
+    DestFile += URItoFileName(URI);
+    Desc.URI = URI;
+    Desc.Description = URIDesc;
+    Desc.Owner = this;
+    Desc.ShortDesc = ShortDesc;
+    QueueURI(Desc);
+    if(Debug)
+       std::clog << "pkgAcqSubIndex: " << Desc.URI << std::endl;
+ }
+                                                                       /*}}}*/
+ // AcqSubIndex::Custom600Headers - Insert custom request headers      /*{{{*/
+ // ---------------------------------------------------------------------
+ /* The only header we use is the last-modified header. */
+ string pkgAcqSubIndex::Custom600Headers()
+ {
+    string Final = _config->FindDir("Dir::State::lists");
+    Final += URItoFileName(Desc.URI);
+    struct stat Buf;
+    if (stat(Final.c_str(),&Buf) != 0)
+       return "\nIndex-File: true";
+    return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
+ }
+                                                                       /*}}}*/
+ void pkgAcqSubIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)     /*{{{*/
+ {
+    if(Debug)
+       std::clog << "pkgAcqSubIndex failed: " << Desc.URI << std::endl;
+    Complete = false;
+    Status = StatDone;
+    Dequeue();
+    // No good Index is provided, so try guessing
+    std::vector<std::string> langs = APT::Configuration::getLanguages(true);
+    for (std::vector<std::string>::const_iterator l = langs.begin();
+       l != langs.end(); ++l)
+    {
+       if (*l == "none") continue;
+       string const file = "Translation-" + *l;
+       new pkgAcqIndexTrans(Owner, Desc.URI.substr(0, Desc.URI.rfind('/')+1).append(file),
+               Desc.Description.erase(Desc.Description.rfind(' ')+1).append(file),
+               file);
+    }
+ }
+                                                                       /*}}}*/
+ void pkgAcqSubIndex::Done(string Message,unsigned long Size,string Md5Hash,   /*{{{*/
+                          pkgAcquire::MethodConfig *Cnf)
+ {
+    if(Debug)
+       std::clog << "pkgAcqSubIndex::Done(): " << Desc.URI << std::endl;
+    string FileName = LookupTag(Message,"Filename");
+    if (FileName.empty() == true)
+    {
+       Status = StatError;
+       ErrorText = "Method gave a blank filename";
+       return;
+    }
+    if (FileName != DestFile)
+    {
+       Local = true;
+       Desc.URI = "copy:" + FileName;
+       QueueURI(Desc);
+       return;
+    }
+    Item::Done(Message,Size,Md5Hash,Cnf);
+    string FinalFile = _config->FindDir("Dir::State::lists")+URItoFileName(Desc.URI);
+    // sucess in downloading the index
+    // rename the index
+    if(Debug)
+       std::clog << "Renaming: " << DestFile << " -> " << FinalFile << std::endl;
+    Rename(DestFile,FinalFile);
+    chmod(FinalFile.c_str(),0644);
+    DestFile = FinalFile;
+    if(ParseIndex(DestFile) == false)
+       return Failed("", NULL);
+    Complete = true;
+    Status = StatDone;
+    Dequeue();
+    return;
+ }
+                                                                       /*}}}*/
+ bool pkgAcqSubIndex::ParseIndex(string const &IndexFile)              /*{{{*/
+ {
+    indexRecords SubIndexParser;
+    if (FileExists(IndexFile) == false || SubIndexParser.Load(IndexFile) == false)
+       return false;
+    std::vector<std::string> lang = APT::Configuration::getLanguages(true);
+    for (std::vector<std::string>::const_iterator l = lang.begin();
+       l != lang.end(); ++l)
+    {
+       if (*l == "none")
+        continue;
+       string file = "Translation-" + *l;
+       indexRecords::checkSum const *Record = SubIndexParser.Lookup(file);
+       HashString expected;
+       if (Record == NULL)
+       {
+        // FIXME: the Index file provided by debian currently only includes bz2 records
+        Record = SubIndexParser.Lookup(file + ".bz2");
+        if (Record == NULL)
+           continue;
+       }
+       else
+       {
+        expected = Record->Hash;
+        if (expected.empty() == true)
+           continue;
+       }
+       IndexTarget target;
+       target.Description = Desc.Description.erase(Desc.Description.rfind(' ')+1).append(file);
+       target.MetaKey = file;
+       target.ShortDesc = file;
+       target.URI = Desc.URI.substr(0, Desc.URI.rfind('/')+1).append(file);
+       new pkgAcqIndexTrans(Owner, &target, expected, &SubIndexParser);
+    }
+    return true;
+ }
+                                                                       /*}}}*/
  // AcqDiffIndex::AcqDiffIndex - Constructor                           /*{{{*/
  // ---------------------------------------------------------------------
  /* Get the DiffIndex file first and see if there are patches availabe 
index 943c61876c6e6a8938bc7289a68bf9828f065f21,9bcc32f21331ef4a061c81122d5e983de4c4d897..2ae7bf27c4665687f9d3eecfdeabd7ee3b88c3d8
@@@ -287,6 -287,50 +287,50 @@@ struct DiffInfo 
     unsigned long size;
  };
                                                                        /*}}}*/
 -   /** \brief Create a new pkgAcqDiffIndex.
+ /** \brief An item that is responsible for fetching a SubIndex                {{{
+  *
+  *  The MetaIndex file includes only records for important indexes
+  *  and records for these SubIndex files so these can carry records
+  *  for addition files like PDiffs and Translations
+  */
+ class pkgAcqSubIndex : public pkgAcquire::Item
+ {
+  protected:
+    /** \brief If \b true, debugging information will be written to std::clog. */
+    bool Debug;
+    /** \brief The item that is currently being downloaded. */
+    pkgAcquire::ItemDesc Desc;
+    /** \brief The Hash that this file should have after download
+     */
+    HashString ExpectedHash;
+  public:
+    // Specialized action members
+    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
+    virtual void Done(string Message,unsigned long Size,string Md5Hash,
+                    pkgAcquire::MethodConfig *Cnf);
+    virtual string DescURI() {return Desc.URI;};
+    virtual string Custom600Headers();
+    virtual bool ParseIndex(string const &IndexFile);
++   /** \brief Create a new pkgAcqSubIndex.
+     *
+     *  \param Owner The Acquire object that owns this item.
+     *
+     *  \param URI The URI of the list file to download.
+     *
+     *  \param URIDesc A long description of the list file to download.
+     *
+     *  \param ShortDesc A short description of the list file to download.
+     *
+     *  \param ExpectedHash The list file's MD5 signature.
+     */
+    pkgAcqSubIndex(pkgAcquire *Owner, string const &URI,string const &URIDesc,
+                  string const &ShortDesc, HashString const &ExpectedHash);
+ };
+                                                                       /*}}}*/
  /** \brief An item that is responsible for fetching an index file of  {{{
   *  package list diffs and starting the package list's download.
   *