Kaynağa Gözat

* updated from http://people.ubuntu.com/~mvo/bzr/apt/auto-mark/

Michael Vogt 19 yıl önce
ebeveyn
işleme
b51ff02a55

+ 16 - 5
apt-pkg/depcache.cc

@@ -948,11 +948,22 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
 	       std::clog << "Installing " << InstPkg.Name() 
 			 << " as dep of " << Pkg.Name() 
 			 << std::endl;
-	    MarkInstall(InstPkg,true,Depth + 1, false, ForceImportantDeps);
-
-	    // Set the autoflag, after MarkInstall because MarkInstall unsets it
-	    if (P->CurrentVer == 0)
-	       PkgState[InstPkg->ID].Flags |= Flag::Auto;
+ 	    // now check if we should consider it a automatic dependency or not
+ 	    string sec = _config->Find("APT::Never-MarkAuto-Section","");
+ 	    if(Pkg.Section() && (string(Pkg.Section()) ==  sec))
+ 	    {
+ 	       if(_config->FindB("Debug::pkgDepCache::AutoInstall",false) == true)
+ 		  std::clog << "Setting NOT as auto-installed because its a direct dep of a package in section " << sec << std::endl;
+ 	       MarkInstall(InstPkg,true,Depth + 1, true);
+ 	    }
+ 	    else 
+ 	    {
+ 	       // mark automatic dependency
+ 	       MarkInstall(InstPkg,true,Depth + 1, false, ForceImportantDeps);
+ 	       // Set the autoflag, after MarkInstall because MarkInstall unsets it
+ 	       if (P->CurrentVer == 0)
+ 		  PkgState[InstPkg->ID].Flags |= Flag::Auto;
+ 	    }
 	 }
 	 continue;
       }

+ 2 - 1
apt-pkg/packagemanager.cc

@@ -95,9 +95,10 @@ bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
    be downloaded. */
 bool pkgPackageManager::FixMissing()
 {   
+   pkgDepCache::ActionGroup group(Cache);
    pkgProblemResolver Resolve(&Cache);
    List->SetFileList(FileNames);
-   
+
    bool Bad = false;
    for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
    {

+ 33 - 6
cmdline/apt-get.cc

@@ -1421,8 +1421,8 @@ bool DoAutomaticRemove(CacheFile &Cache)
 {
    bool Debug = _config->FindI("Debug::pkgAutoRemove",false);
    bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false);
+   bool hideAutoRemove = _config->FindB("APT::Get::HideAutoRemove");
    pkgDepCache::ActionGroup group(*Cache);
-   
 
    if(Debug)
       std::cout << "DoAutomaticRemove()" << std::endl;
@@ -1444,9 +1444,13 @@ bool DoAutomaticRemove(CacheFile &Cache)
 	 if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install())
 	    if(Debug)
 	       std::cout << "We could delete %s" <<  Pkg.Name() << std::endl;
-	   
-	 autoremovelist += string(Pkg.Name()) + " ";
-	 autoremoveversions += string(Cache[Pkg].CandVersion) + " ";
+	  
+	 // only show stuff in the list that is not yet marked for removal
+	 if(Cache[Pkg].Delete() == false) 
+	 {
+	    autoremovelist += string(Pkg.Name()) + " ";
+	    autoremoveversions += string(Cache[Pkg].CandVersion) + "\n";
+	 }
 	 if (doAutoRemove)
 	 {
 	    if(Pkg.CurrentVer() != 0 && 
@@ -1457,8 +1461,9 @@ bool DoAutomaticRemove(CacheFile &Cache)
 	 }
       }
    }
-   ShowList(c1out, _("The following packages were automatically installed and are no longer required:"), autoremovelist, autoremoveversions);
-   if (!doAutoRemove && autoremovelist.size() > 0)
+   if (!hideAutoRemove) 
+      ShowList(c1out, _("The following packages were automatically installed and are no longer required:"), autoremovelist, autoremoveversions);
+   if (!doAutoRemove && !hideAutoRemove && autoremovelist.size() > 0)
       c1out << _("Use 'apt-get autoremove' to remove them.") << std::endl;
 
    // Now see if we destroyed anything
@@ -1556,6 +1561,7 @@ bool DoInstall(CommandLine &CmdL)
    if (Cache->BrokenCount() != 0)
       BrokenFix = true;
    
+   unsigned int AutoMarkChanged = 0;
    unsigned int ExpectedInst = 0;
    unsigned int Packages = 0;
    pkgProblemResolver Fix(Cache);
@@ -1678,6 +1684,19 @@ bool DoInstall(CommandLine &CmdL)
 		  return false;
 	    if (TryToInstall(Pkg,Cache,Fix,Remove,BrokenFix,ExpectedInst) == false)
 	       return false;
+
+	    // see if we need to fix the auto-mark flag 
+	    // e.g. apt-get install foo 
+	    // where foo is marked automatic
+	    if(!Remove && 
+	       Cache[Pkg].Install() == false && 
+	       (Cache[Pkg].Flags & pkgCache::Flag::Auto))
+	    {
+	       ioprintf(c1out,_("%s set to manual installed.\n"),
+			Pkg.Name());
+	       Cache->MarkAuto(Pkg,false);
+	       AutoMarkChanged++;
+	    }
 	 }      
       }
 
@@ -1842,6 +1861,14 @@ bool DoInstall(CommandLine &CmdL)
 
    }
 
+   // if nothing changed in the cache, but only the automark information
+   // we write the StateFile here, otherwise it will be written in 
+   // cache.commit()
+   if (AutoMarkChanged > 0 &&
+       Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
+       Cache->BadCount() == 0)
+      Cache->writeStateFile(NULL);
+
    // See if we need to prompt
    if (Cache->InstCount() == ExpectedInst && Cache->DelCount() == 0)
       return InstallPackages(Cache,false,false);

+ 1 - 0
cmdline/apt-mark

@@ -60,4 +60,5 @@ if __name__ == "__main__":
             else:
                 outfile.write(str(tagfile.Section)+"\n")
         # all done, rename the tmpfile
+        os.chmod(outfile.name, 0644)
         os.rename(outfile.name, STATE_FILE)

+ 4 - 0
doc/examples/configure-index

@@ -33,6 +33,7 @@ APT
   {
      Arch-Only "false";
      AutomaticRemove "false";       
+     HideAutoRemove "false";
      Download-Only "false";
      Simulate "false";
      Assume-Yes "false";
@@ -99,6 +100,9 @@ APT
   APT::Install-Recommends "false";
   APT::Install-Suggests "false";
 
+  // consider dependencies of packages in this section manual
+  Never-MarkAuto-Section "metapackages";
+
   // Write progress messages on this fd (for stuff like base-config)
   Status-Fd "-1";
   // Keep the list of FDs open (normally apt closes all fds when it

+ 1 - 1
po/apt-all.pot

@@ -2218,7 +2218,7 @@ msgstr ""
 msgid "Malformed line %u in source list %s (vendor id)"
 msgstr ""
 
-#: apt-pkg/packagemanager.cc:402
+#: apt-pkg/packagemanager.cc:402 apt-pkg/packagemanager.cc:403
 #, c-format
 msgid ""
 "This installation run will require temporarily removing the essential "