]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/sourcelist.cc
Beautified URI printing to not include passwords
[apt.git] / apt-pkg / sourcelist.cc
index 62d5e6fcd5eb98b23757a2e2bbe9a7f30026140a..1fdbd834e7589f7facd0608c78fc962f0c5eda0a 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: sourcelist.cc,v 1.1 1998/07/07 04:17:06 jgg Exp $
+// $Id: sourcelist.cc,v 1.17 1999/10/17 07:30:23 jgg Exp $
 /* ######################################################################
 
    List of Sources
@@ -9,14 +9,14 @@
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
 #ifdef __GNUG__
-#pragma implementation "pkglib/sourcelist.h"
+#pragma implementation "apt-pkg/sourcelist.h"
 #endif
 
-#include <pkglib/sourcelist.h>
-#include <pkglib/error.h>
-#include <pkglib/fileutl.h>
-#include <strutl.h>
-#include <options.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/strutl.h>
 
 #include <fstream.h>
 #include <stdio.h>
@@ -41,7 +41,7 @@ pkgSourceList::pkgSourceList(string File)
 /* */
 bool pkgSourceList::ReadMainList()
 {
-   return Read(PKG_DEB_CF_SOURCELIST);
+   return Read(_config->FindFile("Dir::Etc::sourcelist"));
 }
                                                                        /*}}}*/
 // SourceList::Read - Parse the sourcelist file                                /*{{{*/
@@ -73,7 +73,7 @@ bool pkgSourceList::Read(string File)
       string Type;
       string URI;
       Item Itm;
-      char *C = Buffer;
+      const char *C = Buffer;
       if (ParseQuoteWord(C,Type) == false)
         return _error->Error("Malformed line %u in source list %s (type)",CurLine,File.c_str());
       if (ParseQuoteWord(C,URI) == false)
@@ -90,7 +90,7 @@ bool pkgSourceList::Read(string File)
       {
         if (ParseQuoteWord(C,Itm.Section) == true)
            return _error->Error("Malformed line %u in source list %s (Absolute dist)",CurLine,File.c_str());
-        Itm.Dist = SubstVar(Itm.Dist,"$(ARCH)",PKG_DEB_ARCH);
+        Itm.Dist = SubstVar(Itm.Dist,"$(ARCH)",_config->Find("APT::Architecture"));
         List.push_back(Itm);
         continue;
       }
@@ -108,52 +108,13 @@ bool pkgSourceList::Read(string File)
    return true;
 }
                                                                        /*}}}*/
-// SourceList::SanitizeURI - Hash the uri                              /*{{{*/
-// ---------------------------------------------------------------------
-/* This converts a URI into a safe filename. It quotes all unsafe characters
-   and converts / to _ and removes the scheme identifier. */
-string pkgSourceList::SanitizeURI(string URI)
-{
-   string::const_iterator I = URI.begin() + URI.find(':') + 1;
-   for (; I < URI.end() && *I == '/'; I++);
-
-   // "\x00-\x20{}|\\\\^\\[\\]<>\"\x7F-\xFF";
-   URI = QuoteString(string(I,URI.end() - I),"\\|{}[]<>\"^~_=!@#$%^&*");
-   string::iterator J = URI.begin();
-   for (; J != URI.end(); J++)
-      if (*J == '/') 
-        *J = '_';
-   return URI;
-}
-                                                                       /*}}}*/
-// SourceList::MatchPkgFile - Find the package file that has the ver   /*{{{*/
-// ---------------------------------------------------------------------
-/* This will return List.end() if it could not find the matching 
-   file */
-pkgSourceList::const_iterator pkgSourceList::MatchPkgFile(pkgCache::VerIterator Ver)
-{
-   string Base = PKG_DEB_ST_LIST;
-   for (const_iterator I = List.begin(); I != List.end(); I++)
-   {
-      string URI = I->PackagesURI();
-      switch (I->Type)
-      {
-        case Item::Deb:
-        if (Base + SanitizeURI(URI) == Ver.File().FileName())
-           return I;
-        break;
-      };      
-   }
-   return List.end();
-}
-                                                                       /*}}}*/
 // SourceList::Item << - Writes the item to a stream                   /*{{{*/
 // ---------------------------------------------------------------------
 /* This is not suitable for rebuilding the sourcelist file but it good for
    debugging. */
 ostream &operator <<(ostream &O,pkgSourceList::Item &Itm)
 {
-   O << Itm.Type << ' ' << Itm.URI << ' ' << Itm.Dist << ' ' << Itm.Section;
+   O << (int)Itm.Type << ' ' << Itm.URI << ' ' << Itm.Dist << ' ' << Itm.Section;
    return O;
 }
                                                                        /*}}}*/
@@ -168,7 +129,13 @@ bool pkgSourceList::Item::SetType(string S)
       return true;
    }
 
-   return true;
+   if (S == "deb-src")
+   {
+      Type = DebSrc;
+      return true;
+   }
+
+   return false;
 }
                                                                        /*}}}*/
 // SourceList::Item::SetURI - Set the URI                              /*{{{*/
@@ -182,7 +149,7 @@ bool pkgSourceList::Item::SetURI(string S)
    if (S.find(':') == string::npos)
       return false;
 
-   S = SubstVar(S,"$(ARCH)",PKG_DEB_ARCH);
+   S = SubstVar(S,"$(ARCH)",_config->Find("APT::Architecture"));
    
    // Make sure that the URN is / postfixed
    URI = S;
@@ -202,13 +169,28 @@ string pkgSourceList::Item::PackagesURI() const
    {
       case Deb:
       if (Dist[Dist.size() - 1] == '/')
-        Res = URI + Dist;
+      {
+        if (Dist != "/")
+           Res = URI + Dist;
+        else 
+           Res = URI;
+      }      
       else
-        Res = URI + "dists/" + Dist + '/' + Section + 
-        "/binary-" + PKG_DEB_ARCH + '/';
+        Res = URI + "dists/" + Dist + '/' + Section +
+        "/binary-" + _config->Find("APT::Architecture") + '/';
       
       Res += "Packages";
       break;
+      
+      case DebSrc:
+      if (Dist[Dist.size() - 1] == '/')
+        Res = URI + Dist;
+      else
+        Res = URI + "dists/" + Dist + '/' + Section +
+        "/source/";
+      
+      Res += "Sources";
+      break;
    };
    return Res;
 }
@@ -224,12 +206,86 @@ string pkgSourceList::Item::PackagesInfo() const
       case Deb:
       Res += SiteOnly(URI) + ' ';
       if (Dist[Dist.size() - 1] == '/')
-        Res += Dist;
+      {
+        if (Dist != "/")
+           Res += Dist;
+      }      
       else
         Res += Dist + '/' + Section;
       
       Res += " Packages";
       break;
+     
+      case DebSrc:
+      Res += SiteOnly(URI) + ' ';
+      if (Dist[Dist.size() - 1] == '/')
+        Res += Dist;
+      else
+        Res += Dist + '/' + Section;
+      
+      Res += " Sources";
+      break;
+   };
+   return Res;
+}
+                                                                       /*}}}*/
+// SourceList::Item::ReleaseURI - Returns a URI to the release file    /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string pkgSourceList::Item::ReleaseURI() const
+{
+   string Res;
+   switch (Type)
+   {
+      case Deb:
+      if (Dist[Dist.size() - 1] == '/')
+      {
+        if (Dist != "/")
+           Res = URI + Dist;
+        else
+           Res = URI;
+      }      
+      else
+        Res = URI + "dists/" + Dist + '/' + Section +
+        "/binary-" + _config->Find("APT::Architecture") + '/';
+      
+      Res += "Release";
+      break;
+      
+      case DebSrc:
+      if (Dist[Dist.size() - 1] == '/')
+        Res = URI + Dist;
+      else
+        Res = URI + "dists/" + Dist + '/' + Section +
+        "/source/";
+      
+      Res += "Release";
+      break;
+   };
+   return Res;
+}
+                                                                       /*}}}*/
+// SourceList::Item::ReleaseInfo - Shorter version of the URI          /*{{{*/
+// ---------------------------------------------------------------------
+/* This is a shorter version that is designed to be < 60 chars or so */
+string pkgSourceList::Item::ReleaseInfo() const
+{
+   string Res;
+   switch (Type)
+   {
+      case Deb:
+      case DebSrc:
+      Res += SiteOnly(URI) + ' ';
+      if (Dist[Dist.size() - 1] == '/')
+      {
+        if (Dist != "/")
+           Res += Dist;
+      }      
+      else
+        Res += Dist + '/' + Section;
+      
+      Res += " Release";
+      break;
    };
    return Res;
 }
@@ -242,15 +298,22 @@ string pkgSourceList::Item::ArchiveInfo(pkgCache::VerIterator Ver) const
    string Res;
    switch (Type)
    {
+      case DebSrc:
       case Deb:
       Res += SiteOnly(URI) + ' ';
       if (Dist[Dist.size() - 1] == '/')
-        Res += Dist;
+      {
+        if (Dist != "/")
+           Res += Dist;
+      }      
       else
         Res += Dist + '/' + Section;
       
       Res += " ";
       Res += Ver.ParentPkg().Name();
+      Res += " ";
+      Res += Ver.VerStr();
+      
       break;
    };
    return Res;
@@ -265,201 +328,53 @@ string pkgSourceList::Item::ArchiveURI(string File) const
    switch (Type)
    {
       case Deb:
+      case DebSrc:
       Res = URI + File;
       break;
    };
    return Res;
 }
                                                                        /*}}}*/
-// SourceList::Item::SiteOnly - Strip off the path part of a URI       /*{{{*/
+// SourceList::Item::SourceInfo        - Returns an info line for a source     /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-string pkgSourceList::Item::SiteOnly(string URI) const
-{
-   unsigned int Pos = URI.find(':');
-   if (Pos == string::npos || Pos + 3 > URI.length())
-      return URI;
-   if (URI[Pos + 1] != '/' || URI[Pos + 2] != '/')
-      return URI;
-
-   Pos = URI.find('/',Pos + 3);
-   if (Pos == string::npos)
-      return URI;
-   return string(URI,0,Pos);
-}
-                                                                       /*}}}*/
-
-// UpdateMeta - Update the meta information                            /*{{{*/
-// ---------------------------------------------------------------------
-/* The meta information is package files, revision information and mirror
-   lists. */
-bool pkgUpdateMeta(pkgSourceList &List,pkgAquire &Engine)
-{
-   if (Engine.OutputDir(PKG_DEB_ST_LIST) == false)
-      return false;
-   
-   for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
-   {
-      string URI = I->PackagesURI();
-      string GetInfo = I->PackagesInfo();
-      switch (I->Type)
-      {
-        case pkgSourceList::Item::Deb:
-           if (Engine.Get(URI + ".gz",List.SanitizeURI(URI),GetInfo) == false)
-              return false;
-        break;
-      };      
-   }
-   
-   return true;
-}
-                                                                       /*}}}*/
-// MakeSrcCache - Generate a cache file of all the package files       /*{{{*/
-// ---------------------------------------------------------------------
-/* This goes over the source list and builds a cache of all the package
-   files. */
-bool pkgMakeSrcCache(pkgSourceList &List)
+string pkgSourceList::Item::SourceInfo(string Pkg,string Ver,string Comp) const
 {
-   // First we date check the cache
-   bool Bad = false;
-   while (Bad == false)
+   string Res;
+   switch (Type)
    {
-      if (FileExists(PKG_DEB_CA_SRCCACHE) == false)
-         break;
-         
-      pkgCache Cache(PKG_DEB_CA_SRCCACHE,true,true);
-      if (_error->PendingError() == true)
-      {
-        _error->Discard();
-        break;
-      }
-      
-      // They are certianly out of sync
-      if (Cache.Head().PackageFileCount != List.size())
-         break;
-      
-      for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++)
+      case DebSrc:
+      case Deb:
+      Res += SiteOnly(URI) + ' ';
+      if (Dist[Dist.size() - 1] == '/')
       {
-        // Search for a match in the source list
-        Bad = true;
-        for (pkgSourceList::const_iterator I = List.begin(); 
-             I != List.end(); I++)
-        {
-           string File = string(PKG_DEB_ST_LIST) + 
-              List.SanitizeURI(I->PackagesURI());
-           if (F.FileName() == File)
-           {
-              Bad = false;
-              break;
-           }
-        }
-        
-        // Check if the file matches what was cached
-        Bad |= !F.IsOk();
-        if (Bad == true)
-           break;
+        if (Dist != "/")
+           Res += Dist;
       }      
-
-      if (Bad == false)
-        return true;
-   }
-   
-   unlink(PKG_DEB_CA_SRCCACHE);
-   pkgCache::MergeState Merge(PKG_DEB_CA_SRCCACHE);
-   if (_error->PendingError() == true)
-            return false;
-   
-   for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
-   {
-      string File = string(PKG_DEB_ST_LIST) + List.SanitizeURI(I->PackagesURI());
-      if (Merge.MergePackageFile(File,"??","??") == false)
-        return false;
-   }
-          
-   return true;
+      else
+        Res += Dist + '/' + Section;
+      
+      Res += " ";
+      Res += Pkg;
+      Res += " ";
+      Res += Ver;
+      if (Comp.empty() == false)
+        Res += " (" + Comp + ")";
+      break;
+   };
+   return Res;
 }
                                                                        /*}}}*/
-// MakeStatusCache - Generates a cache that includes the status files  /*{{{*/
+// SourceList::Item::SiteOnly - Strip off the path part of a URI       /*{{{*/
 // ---------------------------------------------------------------------
-/* This copies the package source cache and then merges the status and 
-   xstatus files into it. */
-bool pkgMakeStatusCache()
+/* */
+string pkgSourceList::Item::SiteOnly(string URI) const
 {
-   // Quickly check if the existing package cache is ok
-   bool Bad = false;
-   while (Bad == false)
-   {
-      if (FileExists(PKG_DEB_CA_PKGCACHE) == false)
-         break;
-      
-      /* We check the dates of the two caches. This takes care of most things
-         quickly and easially */
-      struct stat Src;
-      struct stat Pkg;
-      if (stat(PKG_DEB_CA_PKGCACHE,&Pkg) != 0 || 
-         stat(PKG_DEB_CA_SRCCACHE,&Src) != 0)
-        break;
-      if (difftime(Src.st_mtime,Pkg.st_mtime) > 0)
-        break;
-
-      pkgCache Cache(PKG_DEB_CA_PKGCACHE,true,true);
-      if (_error->PendingError() == true)
-      {
-        _error->Discard();
-        break;
-      }
-      
-      for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++)
-      {
-        if (F.IsOk() == false)
-        {
-           Bad = true;
-           break;
-        }
-      }
-      
-      if (Bad == false)
-        return true;
-   }   
-
-   // Check the integrity of the source cache.
-   {
-      pkgCache Cache(PKG_DEB_CA_SRCCACHE,true,true);
-      if (_error->PendingError() == true)
-        return false;
-   }
-   
-   // Sub scope so that merge destructs before we rename the file...
-   string Cache = PKG_DEB_CA_PKGCACHE ".new";
-   {
-      if (CopyFile(PKG_DEB_CA_SRCCACHE,Cache) == false)
-        return false;
-
-      pkgCache::MergeState Merge(Cache);
-      if (_error->PendingError() == true)
-        return false;
-      
-      // Merge in the user status file
-      if (FileExists(PKG_DEB_ST_USERSTATUS) == true)
-        if (Merge.MergePackageFile(PKG_DEB_ST_USERSTATUS,"status","0",
-                                   pkgFLAG_NotSource) == false)
-           return false;
-      
-      // Merge in the extra status file
-      if (FileExists(PKG_DEB_ST_XSTATUS) == true)
-        if (Merge.MergePackageFile(PKG_DEB_ST_XSTATUS,"status","0",
-                                   pkgFLAG_NotSource) == false)
-           return false;
-      
-      // Merge in the status file
-      if (Merge.MergePackageFile("/var/lib/dpkg/status","status","0",
-                                pkgFLAG_NotSource) == false)
-        return false;
-   }
-   
-   if (rename(Cache.c_str(),PKG_DEB_CA_PKGCACHE) != 0)
-      return false;
-   
-   return true;
+   ::URI U(URI);
+   U.User = string();
+   U.Password = string();
+   U.Path = string();
+   U.Port = 0;
+   return U;
 }
                                                                        /*}}}*/