Просмотр исходного кода

Added the remove command
Author: jgg
Date: 1998-10-19 23:45:35 GMT
Added the remove command

Arch Librarian лет назад: 22
Родитель
Сommit
303a1703ca
2 измененных файлов с 119 добавлено и 46 удалено
  1. 6 6
      cmdline/apt-cache.cc
  2. 113 40
      cmdline/apt-get.cc

+ 6 - 6
cmdline/apt-cache.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: apt-cache.cc,v 1.9 1998/10/02 04:39:55 jgg Exp $
+// $Id: apt-cache.cc,v 1.10 1998/10/19 23:45:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    apt-cache - Manages the cache files
    apt-cache - Manages the cache files
@@ -222,7 +222,7 @@ bool DoAdd(CommandLine &CmdL)
       return _error->Error("You must give at least one file name");
       return _error->Error("You must give at least one file name");
    
    
    // Open the cache
    // Open the cache
-   FileFd CacheF(_config->FindDir("Dir::Cache::srcpkgcache"),FileFd::WriteAny);
+   FileFd CacheF(_config->FindFile("Dir::Cache::srcpkgcache"),FileFd::WriteAny);
    if (_error->PendingError() == true)
    if (_error->PendingError() == true)
       return false;
       return false;
    
    
@@ -284,7 +284,7 @@ int ShowHelp()
    cout << "       apt-cache [options] showpkg pkg1 [pkg2 ...]" << endl;
    cout << "       apt-cache [options] showpkg pkg1 [pkg2 ...]" << endl;
    cout << endl;
    cout << endl;
    cout << "apt-cache is a low-level tool used to manipulate APT's binary" << endl;
    cout << "apt-cache is a low-level tool used to manipulate APT's binary" << endl;
-   cout << "cache files stored in " << _config->FindDir("Dir::Cache") << endl;
+   cout << "cache files stored in " << _config->FindFile("Dir::Cache") << endl;
    cout << "It is not ment for ordinary use only as a debug aide." << endl;
    cout << "It is not ment for ordinary use only as a debug aide." << endl;
    cout << endl;
    cout << endl;
    cout << "Commands:" << endl;
    cout << "Commands:" << endl;
@@ -297,8 +297,8 @@ int ShowHelp()
    cout << endl;
    cout << endl;
    cout << "Options:" << endl;
    cout << "Options:" << endl;
    cout << "  -h   This help text." << endl;
    cout << "  -h   This help text." << endl;
-   cout << "  -p=? The package cache. [" << _config->FindDir("Dir::Cache::pkgcache") << ']' << endl;
-   cout << "  -s=? The source cache. [" << _config->FindDir("Dir::Cache::srcpkgcache") << ']' << endl;
+   cout << "  -p=? The package cache. [" << _config->FindFile("Dir::Cache::pkgcache") << ']' << endl;
+   cout << "  -s=? The source cache. [" << _config->FindFile("Dir::Cache::srcpkgcache") << ']' << endl;
    cout << "  -q   Disable progress indicator. " << endl;
    cout << "  -q   Disable progress indicator. " << endl;
    cout << "  -c=? Read this configuration file" << endl;
    cout << "  -c=? Read this configuration file" << endl;
    cout << "  -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl;
    cout << "  -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl;
@@ -358,7 +358,7 @@ int main(int argc,const char *argv[])
       }
       }
 
 
       // Open the cache file
       // Open the cache file
-      FileFd CacheF(_config->FindDir("Dir::Cache::pkgcache"),FileFd::ReadOnly);
+      FileFd CacheF(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly);
       if (_error->PendingError() == true)
       if (_error->PendingError() == true)
 	 break;
 	 break;
       
       

+ 113 - 40
cmdline/apt-get.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: apt-get.cc,v 1.2 1998/10/08 04:55:05 jgg Exp $
+// $Id: apt-get.cc,v 1.3 1998/10/19 23:45:36 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    apt-get - Cover for dpkg
    apt-get - Cover for dpkg
@@ -85,49 +85,66 @@ void ShowBroken(ostream &out,pkgDepCache &Cache)
    pkgCache::PkgIterator I = Cache.PkgBegin();
    pkgCache::PkgIterator I = Cache.PkgBegin();
    for (;I.end() != true; I++)
    for (;I.end() != true; I++)
    {
    {
-      if (Cache[I].InstBroken() == true)
+      if (Cache[I].InstBroken() == false)
+	  continue;
+	  
+      // Print out each package and the failed dependencies
+      out <<"  " <<  I.Name() << ":";
+      int Indent = strlen(I.Name()) + 3;
+      bool First = true;
+      if (Cache[I].InstVerIter(Cache).end() == true)
       {
       {
-	 // Print out each package and the failed dependencies
-	 out <<"  " <<  I.Name() << ":";
-	 int Indent = strlen(I.Name()) + 3;
-	 bool First = true;
-	 for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++)
+	 cout << endl;
+	 continue;
+      }
+      
+      for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++)
+      {
+	 if (Cache.IsImportantDep(D) == false || (Cache[D] &
+						  pkgDepCache::DepInstall) != 0)
+	    continue;
+	 
+	 if (First == false)
+	    for (int J = 0; J != Indent; J++)
+	       out << ' ';
+	 First = false;
+	 
+	 if (D->Type == pkgCache::Dep::Conflicts)
+	    out << " Conflicts:" << D.TargetPkg().Name();
+	 else
+	    out << " Depends:" << D.TargetPkg().Name();
+	 
+	 // Show a quick summary of the version requirements
+	 if (D.TargetVer() != 0)
+	    out << " (" << D.CompType() << " " << D.TargetVer() << 
+	    ")";
+	 
+	 /* Show a summary of the target package if possible. In the case
+	  of virtual packages we show nothing */
+	 
+	 pkgCache::PkgIterator Targ = D.TargetPkg();
+	 if (Targ->ProvidesList == 0)
 	 {
 	 {
-	    if (Cache.IsImportantDep(D) == false || (Cache[D] &
-						     pkgDepCache::DepInstall) != 0)
-	       continue;
-	    
-	    if (First == false)
-	       for (int J = 0; J != Indent; J++)
-		  out << ' ';
-	    First = false;
-	    
-	    if (D->Type == pkgCache::Dep::Conflicts)
-	       out << " Conflicts:" << D.TargetPkg().Name();
+	    out << " but ";
+	    pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache);
+	    if (Ver.end() == false)
+	       out << Ver.VerStr() << " is installed";
 	    else
 	    else
-	       out << " Depends:" << D.TargetPkg().Name();
-	    
-	    // Show a quick summary of the version requirements
-	    if (D.TargetVer() != 0)
-	       out << " (" << D.CompType() << " " << D.TargetVer() << 
-	           ")";
-	    
-	    /* Show a summary of the target package if possible. In the case
-	       of virtual packages we show nothing */
-	    pkgCache::PkgIterator Targ = D.TargetPkg();
-	    if (Targ->ProvidesList == 0)
 	    {
 	    {
-	       out << " but ";
-	       pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache);
-	       if (Ver.end() == false)
-		  out << Ver.VerStr() << "is installed";
+	       if (Cache[Targ].CandidateVerIter(Cache).end() == true)
+	       {
+		  if (Targ->ProvidesList == 0)
+		     out << "it is not installable";
+		  else
+		     out << "it is a virtual package";
+	       }		  
 	       else
 	       else
 		  out << "it is not installed";
 		  out << "it is not installed";
-	    }
-	    
-	    out << endl;
-	 }	    
-      }   
+	    }	       
+	 }
+	 
+	 out << endl;
+      }	    
    }   
    }   
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -340,7 +357,7 @@ bool CacheFile::Open()
    Progress.Done();
    Progress.Done();
    
    
    // Open the cache file
    // Open the cache file
-   File = new FileFd(_config->FindDir("Dir::Cache::pkgcache"),FileFd::ReadOnly);
+   File = new FileFd(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly);
    if (_error->PendingError() == true)
    if (_error->PendingError() == true)
       return false;
       return false;
    
    
@@ -463,8 +480,13 @@ bool DoInstall(CommandLine &CmdL)
       return false;
       return false;
    
    
    int ExpectedInst = 0;
    int ExpectedInst = 0;
+   int Packages = 0;
    pkgProblemResolver Fix(Cache);
    pkgProblemResolver Fix(Cache);
    
    
+   bool DefRemove = false;
+   if (strcasecmp(CmdL.FileList[0],"remove") == 0)
+      DefRemove = true;
+   
    for (const char **I = CmdL.FileList + 1; *I != 0; I++)
    for (const char **I = CmdL.FileList + 1; *I != 0; I++)
    {
    {
       // Duplicate the string
       // Duplicate the string
@@ -475,26 +497,60 @@ bool DoInstall(CommandLine &CmdL)
       strcpy(S,*I);
       strcpy(S,*I);
       
       
       // See if we are removing the package
       // See if we are removing the package
-      bool Remove = false;
+      bool Remove = DefRemove;
       if (S[Length - 1] == '-')
       if (S[Length - 1] == '-')
       {
       {
 	 Remove = true;
 	 Remove = true;
 	 S[--Length] = 0;
 	 S[--Length] = 0;
       }
       }
+      if (S[Length - 1] == '+')
+      {
+	 Remove = false;
+	 S[--Length] = 0;
+      }
       
       
       // Locate the package
       // Locate the package
       pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
       pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
+      Packages++;
       if (Pkg.end() == true)
       if (Pkg.end() == true)
 	 return _error->Error("Couldn't find package %s",S);
 	 return _error->Error("Couldn't find package %s",S);
       
       
       // Check if there is something new to install
       // Check if there is something new to install
       pkgDepCache::StateCache &State = (*Cache)[Pkg];
       pkgDepCache::StateCache &State = (*Cache)[Pkg];
       if (State.CandidateVer == 0)
       if (State.CandidateVer == 0)
+      {
+	 if (Pkg->ProvidesList != 0)
+	 {
+	    c1out << "Package " << S << " is a virtual package provided by:" << endl;
+
+	    pkgCache::PrvIterator I = Pkg.ProvidesList();
+	    for (; I.end() == false; I++)
+	    {
+	       pkgCache::PkgIterator Pkg = I.OwnerPkg();
+	       
+	       if ((*Cache)[Pkg].CandidateVerIter(*Cache) == I.OwnerVer())
+		  c1out << "  " << Pkg.Name() << " " << I.OwnerVer().VerStr() << endl;
+
+	       if ((*Cache)[Pkg].InstVerIter(*Cache) == I.OwnerVer())
+		  c1out << "  " << Pkg.Name() << " " << I.OwnerVer().VerStr() <<
+		    " [Installed]"<< endl;
+	    }
+	    c1out << "You should explicly select one to install." << endl;
+	 }
+	 else
+	 {
+	    c1out << "Package " << S << " has no available version, but exists in the database." << endl;
+	    c1out << "This typically means that the package was mentioned in a dependency and " << endl;
+	    c1out << "never uploaded, or that it is an obsolete package." << endl;
+	 }
+	 
 	 return _error->Error("Package %s has no installation candidate",S);
 	 return _error->Error("Package %s has no installation candidate",S);
+      }
       
       
       Fix.Protect(Pkg);
       Fix.Protect(Pkg);
       if (Remove == true)
       if (Remove == true)
       {
       {
+	 Fix.Remove(Pkg);
 	 Cache->MarkDelete(Pkg);
 	 Cache->MarkDelete(Pkg);
 	 continue;
 	 continue;
       }
       }
@@ -512,12 +568,27 @@ bool DoInstall(CommandLine &CmdL)
    }
    }
 
 
    // Call the scored problem resolver
    // Call the scored problem resolver
+   Fix.InstallProtect();
    if (Fix.Resolve(true) == false)
    if (Fix.Resolve(true) == false)
       _error->Discard();
       _error->Discard();
 
 
    // Now we check the state of the packages,
    // Now we check the state of the packages,
    if (Cache->BrokenCount() != 0)
    if (Cache->BrokenCount() != 0)
    {
    {
+      c1out << "Some packages could not be installed. This may mean that you have" << endl;
+      c1out << "requested an impossible situation or if you are using the unstable" << endl;
+      c1out << "distribution that some required packages have not yet been created" << endl;
+      c1out << "or been moved out of Incoming." << endl;
+      if (Packages == 1)
+      {
+	 c1out << endl;
+	 c1out << "Since you only requested a single operation it is extremely likely that" << endl;
+	 c1out << "the package is simply not installable and a bug report against" << endl;
+	 c1out << "that package should be filed." << endl;
+      }
+
+      c1out << "The following information may help to resolve the situation:" << endl;
+      c1out << endl;
       ShowBroken(c1out,Cache);
       ShowBroken(c1out,Cache);
       return _error->Error("Sorry, broken packages");
       return _error->Error("Sorry, broken packages");
    }   
    }   
@@ -659,6 +730,7 @@ int ShowHelp()
    cout << "   update - Retrieve new lists of packages" << endl;
    cout << "   update - Retrieve new lists of packages" << endl;
    cout << "   upgrade - Perform an upgrade" << endl;
    cout << "   upgrade - Perform an upgrade" << endl;
    cout << "   install - Install new packages (pkg is libc6 not libc6.deb)" << endl;
    cout << "   install - Install new packages (pkg is libc6 not libc6.deb)" << endl;
+   cout << "   remove - Remove packages" << endl;
    cout << "   dist-upgrade - Distribution upgrade, see apt-get(8)" << endl;
    cout << "   dist-upgrade - Distribution upgrade, see apt-get(8)" << endl;
    cout << "   dselect-upgrade - Follow dselect selections" << endl;
    cout << "   dselect-upgrade - Follow dselect selections" << endl;
    cout << "   clean - Erase downloaded archive files" << endl;
    cout << "   clean - Erase downloaded archive files" << endl;
@@ -746,6 +818,7 @@ int main(int argc,const char *argv[])
    } Map[] = {{"update",&DoUpdate},
    } Map[] = {{"update",&DoUpdate},
               {"upgrade",&DoUpgrade},
               {"upgrade",&DoUpgrade},
               {"install",&DoInstall},
               {"install",&DoInstall},
+              {"remove",&DoInstall},
               {"dist-upgrade",&DoDistUpgrade},
               {"dist-upgrade",&DoDistUpgrade},
               {"dselect-upgrade",&DoDSelectUpgrade},
               {"dselect-upgrade",&DoDSelectUpgrade},
               {"clean",&DoClean},
               {"clean",&DoClean},