cmdline/apt-get.cc: Add apt-get markauto, showauto and unmarkauto commands.
[ntk/apt.git] / cmdline / apt-get.cc
index 62f712c..8f9faf1 100644 (file)
@@ -692,7 +692,7 @@ bool CacheFile::CheckDeps(bool AllowBroken)
    }
    else
    {
-      c1out << _("You might want to run `apt-get -f install' to correct these.") << endl;
+      c1out << _("You might want to run 'apt-get -f install' to correct these.") << endl;
       ShowBroken(c1out,*this,true);
 
       return _error->Error(_("Unmet dependencies. Try using -f."));
@@ -811,20 +811,19 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
    pkgRecords Recs(Cache);
    if (_error->PendingError() == true)
       return false;
-   
-   // Lock the archive directory
-   FileFd Lock;
-   if (_config->FindB("Debug::NoLocking",false) == false &&
-       _config->FindB("APT::Get::Print-URIs") == false)
-   {
-      Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"));
-      if (_error->PendingError() == true)
-        return _error->Error(_("Unable to lock the download directory"));
-   }
-   
+
    // Create the download object
+   pkgAcquire Fetcher;
    AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));   
-   pkgAcquire Fetcher(&Stat);
+   if (_config->FindB("APT::Get::Print-URIs", false) == true)
+   {
+      // force a hashsum for compatibility reasons
+      _config->CndSet("Acquire::ForceHash", "md5sum");
+      if (Fetcher.Setup(&Stat, "") == false)
+        return false;
+   }
+   else if (Fetcher.Setup(&Stat, _config->FindDir("Dir::Cache::Archives")) == false)
+      return false;
 
    // Read the source list
    pkgSourceList List;
@@ -1148,20 +1147,27 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache,
                  Pkg.FullName(true).c_str());
         
         pkgCache::PrvIterator I = Pkg.ProvidesList();
+        unsigned short provider = 0;
         for (; I.end() == false; I++)
         {
            pkgCache::PkgIterator Pkg = I.OwnerPkg();
            
            if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer())
            {
+              c1out << "  " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr();
               if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false)
-                 c1out << "  " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr() <<
-                 _(" [Installed]") << endl;
-              else
-                 c1out << "  " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr() << endl;
-           }      
+                 c1out << _(" [Installed]");
+              c1out << endl;
+              ++provider;
+           }
         }
-        c1out << _("You should explicitly select one to install.") << endl;
+        // if we found no candidate which provide this package, show non-candidates
+        if (provider == 0)
+           for (I = Pkg.ProvidesList(); I.end() == false; I++)
+              c1out << "  " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr()
+               << _(" [Not candidate version]") << endl;
+        else
+           c1out << _("You should explicitly select one to install.") << endl;
       }
       else
       {
@@ -1258,6 +1264,11 @@ bool TryToChangeVer(pkgCache::PkgIterator Pkg,pkgDepCache &Cache,
    }
    
    Cache.SetCandidateVersion(Ver);
+
+   // Set the all package to the same candidate
+   if (Ver.Pseudo() == true)
+      Cache.SetCandidateVersion(Match.Find(Pkg.Group().FindPkg("all")));
+
    return true;
 }
                                                                        /*}}}*/
@@ -1304,6 +1315,10 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
                  break;
               fuzzy = true;
               Ver = Pkg.VersionList();
+              // exit right away from the Pkg.VersionList() loop if we
+              // don't have any versions
+              if (Ver.end() == true)
+                 break;
            }
            // We match against a concrete version (or a part of this version)
            if (VerTag.empty() == false &&
@@ -1442,23 +1457,19 @@ bool DoUpdate(CommandLine &CmdL)
    if (List.ReadMainList() == false)
       return false;
 
-   // Lock the list directory
-   FileFd Lock;
-   if (_config->FindB("Debug::NoLocking",false) == false)
-   {
-      Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
-      if (_error->PendingError() == true)
-        return _error->Error(_("Unable to lock the list directory"));
-   }
-   
    // Create the progress
    AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
       
    // Just print out the uris an exit if the --print-uris flag was used
    if (_config->FindB("APT::Get::Print-URIs") == true)
    {
+      // force a hashsum for compatibility reasons
+      _config->CndSet("Acquire::ForceHash", "md5sum");
+
       // get a fetcher
-      pkgAcquire Fetcher(&Stat);
+      pkgAcquire Fetcher;
+      if (Fetcher.Setup(&Stat) == false)
+        return false;
 
       // Populate it with the source selection and get all Indexes 
       // (GetAll=true)
@@ -1777,11 +1788,14 @@ bool DoInstall(CommandLine &CmdL)
         
            // Run over the matches
            bool Hit = false;
-           for (Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++)
+           for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp)
            {
-              if (regexec(&Pattern,Pkg.Name(),0,0,0) != 0)
+              if (regexec(&Pattern,Grp.Name(),0,0,0) != 0)
                  continue;
-           
+              Pkg = Grp.FindPkg("native");
+              if (unlikely(Pkg.end() == true))
+                 continue;
+
               ioprintf(c1out,_("Note, selecting %s for regex '%s'\n"),
                        Pkg.Name(),S);
            
@@ -1828,7 +1842,7 @@ bool DoInstall(CommandLine &CmdL)
         packages */
       if (BrokenFix == true && Cache->BrokenCount() != 0)
       {
-        c1out << _("You might want to run `apt-get -f install' to correct these:") << endl;
+        c1out << _("You might want to run 'apt-get -f install' to correct these:") << endl;
         ShowBroken(c1out,Cache,false);
 
         return _error->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
@@ -1999,6 +2013,60 @@ bool DoInstall(CommandLine &CmdL)
 
    return InstallPackages(Cache,false);   
 }
+
+/* show automatically installed packages. */
+bool DoShowAuto(CommandLine &CmdL)
+{
+   OpProgress progress;
+   pkgCacheFile Cache;
+   if (Cache.Open(progress, false) == false)
+      return false;
+
+   for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++)
+      if (Cache[P].Flags & pkgCache::Flag::Auto)
+          ioprintf(c1out,_("%s\n"), P.Name());
+   return true;
+}
+
+/* mark packages as automatically/manually installed. */
+bool DoMarkAuto(CommandLine &CmdL)
+{
+   bool Action = true;
+   int AutoMarkChanged = 0;
+   OpTextProgress progress;
+   CacheFile Cache;
+   if (Cache.Open() == false)
+      return false;
+
+   if (strcasecmp(CmdL.FileList[0],"markauto") == 0)
+      Action = true;
+   else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0)
+      Action = false;
+
+   for (const char **I = CmdL.FileList + 1; *I != 0; I++)
+   {
+      const char *S = *I;
+      // Locate the package
+      pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
+      if (Pkg.end() == true) {
+         return _error->Error(_("Couldn't find package %s"),S);
+      }
+      else
+      {
+         if (!Action)
+            ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name());
+         else
+            ioprintf(c1out,_("%s set to automatically installed.\n"),
+                      Pkg.Name());
+
+         Cache->MarkAuto(Pkg,Action);
+         AutoMarkChanged++;
+      }
+   }
+   if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false))
+      return Cache->writeStateFile(NULL);
+   return false;
+}
                                                                        /*}}}*/
 // DoDistUpgrade - Automatic smart upgrader                            /*{{{*/
 // ---------------------------------------------------------------------
@@ -2207,7 +2275,9 @@ bool DoSource(CommandLine &CmdL)
 
    // Create the download object
    AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));   
-   pkgAcquire Fetcher(&Stat);
+   pkgAcquire Fetcher;
+   if (Fetcher.Setup(&Stat) == false)
+      return false;
 
    DscFile *Dsc = new DscFile[CmdL.FileSize()];
    
@@ -2464,7 +2534,9 @@ bool DoBuildDep(CommandLine &CmdL)
 
    // Create the download object
    AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));   
-   pkgAcquire Fetcher(&Stat);
+   pkgAcquire Fetcher;
+   if (Fetcher.Setup(&Stat) == false)
+      return false;
 
    unsigned J = 0;
    for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
@@ -2780,6 +2852,9 @@ bool ShowHelp(CommandLine &CmdL)
       "   clean - Erase downloaded archive files\n"
       "   autoclean - Erase old downloaded archive files\n"
       "   check - Verify that there are no broken dependencies\n"
+      "   markauto - Mark the given packages as automatically installed\n"
+      "   unmarkauto - Mark the given packages as manually installed\n"
+      "   showauto - Display a list of automatically installed packages\n"
       "\n"
       "Options:\n"
       "  -h  This help text.\n"
@@ -2886,6 +2961,9 @@ int main(int argc,const char *argv[])                                     /*{{{*/
                                    {"purge",&DoInstall},
                                   {"autoremove",&DoInstall},
                                   {"purge",&DoInstall},
+                                  {"showauto",&DoShowAuto},
+                                  {"markauto",&DoMarkAuto},
+                                  {"unmarkauto",&DoMarkAuto},
                                    {"dist-upgrade",&DoDistUpgrade},
                                    {"dselect-upgrade",&DoDSelectUpgrade},
                                   {"build-dep",&DoBuildDep},