}
delete [] Added;
- return ShowList(out,_("WARNING: The following essential packages will be removed\n"
+ return ShowList(out,_("WARNING: The following essential packages will be removed.\n"
"This should NOT be done unless you know exactly what you are doing!"),List,VersionsList);
}
const char *Prompt = _("Yes, do as I say!");
ioprintf(c2out,
- _("You are about to do something potentially harmful\n"
+ _("You are about to do something potentially harmful.\n"
"To continue type in the phrase '%s'\n"
" ?] "),Prompt);
c2out << flush;
return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
return true;
-}
- /*}}}*/
-// DoUpgrade - Upgrade all packages /*{{{*/
-// ---------------------------------------------------------------------
-/* Upgrade all packages without installing new packages or erasing old
- packages */
-bool DoUpgrade(CommandLine &CmdL)
-{
- CacheFile Cache;
- if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
- return false;
-
- // Do the upgrade
- if (pkgAllUpgrade(Cache) == false)
- {
- ShowBroken(c1out,Cache,false);
- return _error->Error(_("Internal error, AllUpgrade broke stuff"));
- }
-
- return InstallPackages(Cache,true);
-}
- /*}}}*/
-// RecurseDirty - Mark used packages as dirty /*{{{*/
-// ---------------------------------------------------------------------
-/* Mark all reachable packages as dirty. */
-void RecurseDirty (CacheFile &Cache, pkgCache::PkgIterator Pkg, pkgCache::State::PkgRemoveState DirtLevel)
-{
- // If it is not installed, and we are in manual mode, ignore it
- if ((Pkg->CurrentVer == 0 && Cache[Pkg].Install() == false || Cache[Pkg].Delete() == true) &&
- DirtLevel == pkgCache::State::RemoveManual)
- {
-// fprintf(stdout,"This one is not installed/virtual %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
- return;
- }
-
- // If it is not installed, and it is not virtual, ignore it
- if ((Pkg->CurrentVer == 0 && Cache[Pkg].Install() == false || Cache[Pkg].Delete() == true) &&
- Pkg->VersionList != 0)
- {
-// fprintf(stdout,"This one is not installed %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
- return;
- }
-
- // If it is similar or more dirty than we are ;-), because we've been here already, don't mark it
- // This is necessary because virtual packages just relay the current level,
- // so it may be possible e.g. that this was already seen with ::RemoveSuggested, but
- // we are ::RemoveRequired
- if (Cache[Pkg].Dirty() >= DirtLevel)
- {
- //fprintf(stdout,"Seen already %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
- return;
- }
-
- // If it is less important than the current DirtLevel, don't mark it
- if (Cache[Pkg].AutomaticRemove != pkgCache::State::RemoveManual &&
- Cache[Pkg].AutomaticRemove > DirtLevel)
- {
-// fprintf(stdout,"We don't need %s %d %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel, Cache[Pkg].Dirty());
- return;
- }
-
- // Mark it as used
- Cache->SetDirty(Pkg, DirtLevel);
-
- //fprintf(stdout,"We keep %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
-
- // We are a virtual package
- if (Pkg->VersionList == 0)
- {
-// fprintf(stdout,"We are virtual %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
- for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); ! Prv.end(); ++Prv)
- RecurseDirty (Cache, Prv.OwnerPkg(), DirtLevel);
- return;
- }
-
- // Depending on the type of dependency, follow it
- for (pkgCache::DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); ! D.end(); ++D)
- {
-// fprintf(stdout,"We depend on %s %s\n", D.TargetPkg().Name(), D.DepType());
-
- switch(D->Type)
- {
- case pkgCache::Dep::Depends:
- case pkgCache::Dep::PreDepends:
- RecurseDirty (Cache, D.TargetPkg(), pkgCache::State::RemoveRequired);
- break;
- case pkgCache::Dep::Recommends:
- RecurseDirty (Cache, D.TargetPkg(), pkgCache::State::RemoveRecommended);
- break;
- case pkgCache::Dep::Suggests:
- RecurseDirty (Cache, D.TargetPkg(), pkgCache::State::RemoveSuggested);
- break;
- case pkgCache::Dep::Conflicts:
- case pkgCache::Dep::Replaces:
- case pkgCache::Dep::Obsoletes:
- // We don't handle these here
- break;
- }
- }
-// fprintf(stdout,"We keep %s %d %d <END>\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
}
/*}}}*/
// DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
/* Remove unused automatic packages */
bool DoAutomaticRemove(CacheFile &Cache)
{
- std::cout << "DoAutomaticRemove()" << std::endl;
- for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
- if(!Cache[Pkg].Dirty() && Cache[Pkg].AutomaticRemove > 0)
- std::cout << "has auto-remove information: " << Pkg.Name()
- << " " << (int)Cache[Pkg].AutomaticRemove
- << std::endl;
-
+ if(_config->FindI("Debug::pkgAutoRemove",false))
+ std::cout << "DoAutomaticRemove()" << std::endl;
if (_config->FindB("APT::Get::Remove",true) == false)
- return _error->Error(_("We are not supposed to delete stuff, can't start AutoRemover"));
-
- for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
- Cache->SetDirty(Pkg, pkgCache::State::RemoveUnknown);
-
- for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
- RecurseDirty (Cache, Pkg, pkgCache::State::RemoveManual);
-
+ return _error->Error(_("We are not supposed to delete stuff, can't "
+ "start AutoRemover"));
+ // do the actual work
+ pkgMarkUsed(Cache);
+ // look over the cache to see what can be removed
for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
{
- if (! Cache[Pkg].Dirty() &&
- (Pkg->CurrentVer != 0 && Cache[Pkg].Install() == false && Cache[Pkg].Delete() == false))
+ if (Cache[Pkg].Garbage &&
+ (Pkg->CurrentVer != 0 && Cache[Pkg].Install() == false &&
+ Cache[Pkg].Delete() == false))
{
- fprintf(stdout,"We could delete %s %d\n", Pkg.Name(), Cache[Pkg].AutomaticRemove);
+ fprintf(stdout,"We could delete %s\n", Pkg.Name());
Cache->MarkDelete(Pkg,_config->FindB("APT::Get::Purge",false));
}
}
return _error->Error(_("Internal Error, AutoRemover broke stuff"));
}
return true;
+}
+// DoUpgrade - Upgrade all packages /*{{{*/
+// ---------------------------------------------------------------------
+/* Upgrade all packages without installing new packages or erasing old
+ packages */
+bool DoUpgrade(CommandLine &CmdL)
+{
+ CacheFile Cache;
+ if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
+ return false;
+
+ // Do the upgrade
+ if (pkgAllUpgrade(Cache) == false)
+ {
+ ShowBroken(c1out,Cache,false);
+ return _error->Error(_("Internal error, AllUpgrade broke stuff"));
+ }
+
+ return InstallPackages(Cache,true);
}
/*}}}*/
// DoInstall - Install packages from the command line /*{{{*/
/* Install named packages */
bool DoInstall(CommandLine &CmdL)
{
+ // 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"));
+ }
+
CacheFile Cache;
if (Cache.OpenForInstall() == false ||
Cache.CheckDeps(CmdL.FileSize() != 1) == false)
return _error->Error(_("Broken packages"));
}
- //if (_config->FindB("APT::Get::AutomaticRemove")) {
+ if (_config->FindB("APT::Get::AutomaticRemove")) {
if (!DoAutomaticRemove(Cache))
return false;
- //}
+ }
/* Print out a list of packages that are going to be installed extra
to what the user asked */
{0,"remove","APT::Get::Remove",0},
{0,"only-source","APT::Get::Only-Source",0},
{0,"arch-only","APT::Get::Arch-Only",0},
- {0,"experimental-automatic-remove","APT::Get::AutomaticRemove",0},
+ {0,"automatic-remove","APT::Get::AutomaticRemove",0},
{0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
{'c',"config-file",0,CommandLine::ConfigFile},
{'o',"option",0,CommandLine::ArbItem},