+ if (State.CandidateVer == 0 && Remove == false)
+ {
+ if (AllowFail == false)
+ return false;
+
+ if (Pkg->ProvidesList != 0)
+ {
+ ioprintf(c1out,_("Package %s is a virtual package provided by:\n"),
+ Pkg.Name());
+
+ pkgCache::PrvIterator I = Pkg.ProvidesList();
+ for (; I.end() == false; I++)
+ {
+ pkgCache::PkgIterator Pkg = I.OwnerPkg();
+
+ if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer())
+ {
+ if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false)
+ c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() <<
+ _(" [Installed]") << endl;
+ else
+ c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << endl;
+ }
+ }
+ c1out << _("You should explicitly select one to install.") << endl;
+ }
+ else
+ {
+ ioprintf(c1out,
+ _("Package %s has no available version, but exists in the database.\n"
+ "This typically means that the package was mentioned in a dependency and\n"
+ "never uploaded, has been obsoleted or is not available with the contents\n"
+ "of sources.list\n"),Pkg.Name());
+
+ string List;
+ SPtrArray<bool> Seen = new bool[Cache.Head().PackageCount];
+ memset(Seen,0,Cache.Head().PackageCount*sizeof(*Seen));
+ pkgCache::DepIterator Dep = Pkg.RevDependsList();
+ for (; Dep.end() == false; Dep++)
+ {
+ if (Dep->Type != pkgCache::Dep::Replaces)
+ continue;
+ if (Seen[Dep.ParentPkg()->ID] == true)
+ continue;
+ Seen[Dep.ParentPkg()->ID] = true;
+ List += string(Dep.ParentPkg().Name()) + " ";
+ }
+ ShowList(c1out,_("However the following packages replace it:"),List);
+ }
+
+ _error->Error(_("Package %s has no installation candidate"),Pkg.Name());
+ return false;
+ }
+
+ Fix.Clear(Pkg);
+ Fix.Protect(Pkg);
+ if (Remove == true)
+ {
+ Fix.Remove(Pkg);
+ Cache.MarkDelete(Pkg,_config->FindB("APT::Get::Purge",false));
+ return true;
+ }
+
+ // Install it
+ Cache.MarkInstall(Pkg,false);
+ if (State.Install() == false)
+ {
+ if (_config->FindB("APT::Get::ReInstall",false) == true)
+ {
+ if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false)
+ ioprintf(c1out,_("Sorry, re-installation of %s is not possible, it cannot be downloaded.\n"),
+ Pkg.Name());
+ else
+ Cache.SetReInstall(Pkg,true);
+ }
+ else
+ {
+ if (AllowFail == true)
+ ioprintf(c1out,_("Sorry, %s is already the newest version.\n"),
+ Pkg.Name());
+ }
+ }
+ else
+ ExpectedInst++;
+
+ // Install it with autoinstalling enabled.
+ if (State.InstBroken() == true && BrokenFix == false)
+ Cache.MarkInstall(Pkg,true);
+ return true;
+}
+ /*}}}*/
+// TryToChangeVer - Try to change a candidate version /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool TryToChangeVer(pkgCache::PkgIterator Pkg,pkgDepCache &Cache,
+ const char *VerTag,bool IsRel)
+{
+ pkgVersionMatch Match(VerTag,(IsRel == true?pkgVersionMatch::Release:pkgVersionMatch::Version));
+
+ pkgCache::VerIterator Ver = Match.Find(Pkg);
+
+ if (Ver.end() == true)
+ {
+ if (IsRel == true)
+ return _error->Error(_("Release '%s' for '%s' was not found"),
+ VerTag,Pkg.Name());
+ return _error->Error(_("Version '%s' for '%s' was not found"),
+ VerTag,Pkg.Name());
+ }
+
+ if (strcmp(VerTag,Ver.VerStr()) != 0)
+ {
+ ioprintf(c1out,_("Selected version %s (%s) for %s\n"),
+ Ver.VerStr(),Ver.RelStr().c_str(),Pkg.Name());
+ }
+
+ Cache.SetCandidateVersion(Ver);
+ return true;
+}
+ /*}}}*/
+// FindSrc - Find a source record /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
+ pkgSrcRecords &SrcRecs,string &Src,
+ pkgDepCache &Cache)
+{
+ // We want to pull the version off the package specification..
+ string VerTag;
+ string TmpSrc = Name;
+ string::size_type Slash = TmpSrc.rfind('=');
+ if (Slash != string::npos)
+ {
+ VerTag = string(TmpSrc.begin() + Slash + 1,TmpSrc.end());
+ TmpSrc = string(TmpSrc.begin(),TmpSrc.begin() + Slash);
+ }
+
+ /* Lookup the version of the package we would install if we were to
+ install a version and determine the source package name, then look
+ in the archive for a source package of the same name. In theory
+ we could stash the version string as well and match that too but
+ today there aren't multi source versions in the archive. */
+ if (_config->FindB("APT::Get::Only-Source") == false &&
+ VerTag.empty() == true)
+ {
+ pkgCache::PkgIterator Pkg = Cache.FindPkg(TmpSrc);
+ if (Pkg.end() == false)
+ {
+ pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);
+ if (Ver.end() == false)
+ {
+ pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
+ Src = Parse.SourcePkg();
+ }
+ }
+ }
+
+ // No source package name..
+ if (Src.empty() == true)
+ Src = TmpSrc;
+
+ // The best hit
+ pkgSrcRecords::Parser *Last = 0;
+ unsigned long Offset = 0;
+ string Version;
+ bool IsMatch = false;
+
+ // If we are matching by version then we need exact matches to be happy
+ if (VerTag.empty() == false)
+ IsMatch = true;
+
+ /* Iterate over all of the hits, which includes the resulting
+ binary packages in the search */
+ pkgSrcRecords::Parser *Parse;
+ SrcRecs.Restart();
+ while ((Parse = SrcRecs.Find(Src.c_str(),false)) != 0)
+ {
+ string Ver = Parse->Version();
+
+ // Skip name mismatches
+ if (IsMatch == true && Parse->Package() != Src)
+ continue;
+
+ if (VerTag.empty() == false)
+ {
+ /* Don't want to fall through because we are doing exact version
+ matching. */
+ if (Cache.VS().CmpVersion(VerTag,Ver) != 0)
+ continue;
+
+ Last = Parse;
+ Offset = Parse->Offset();
+ break;
+ }
+
+ // Newer version or an exact match
+ if (Last == 0 || Cache.VS().CmpVersion(Version,Ver) < 0 ||
+ (Parse->Package() == Src && IsMatch == false))
+ {
+ IsMatch = Parse->Package() == Src;
+ Last = Parse;
+ Offset = Parse->Offset();
+ Version = Ver;
+ }
+ }
+
+ if (Last == 0)
+ return 0;
+
+ if (Last->Jump(Offset) == false)
+ return 0;
+
+ return Last;
+}
+ /*}}}*/
+
+// DoUpdate - Update the package lists /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool DoUpdate(CommandLine &CmdL)
+{
+ if (CmdL.FileSize() != 1)
+ return _error->Error(_("The update command takes no arguments"));
+
+ // Get the source list
+ pkgSourceList List;
+ 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 download object
+ AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
+ pkgAcquire Fetcher(&Stat);
+
+ // Populate it with the source selection
+ if (List.GetIndexes(&Fetcher) == false)
+ return false;
+
+ // Run it
+ if (Fetcher.Run() == pkgAcquire::Failed)
+ return false;
+
+ bool Failed = false;
+ for (pkgAcquire::Item **I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
+ {
+ if ((*I)->Status == pkgAcquire::Item::StatDone)
+ continue;
+
+ (*I)->Finished();
+
+ fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
+ (*I)->ErrorText.c_str());
+ Failed = true;
+ }
+
+ // Clean out any old list files
+ if (_config->FindB("APT::Get::List-Cleanup",true) == true)
+ {
+ if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
+ Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
+ return false;
+ }
+
+ // Prepare the cache.
+ CacheFile Cache;
+ if (Cache.Open() == false)
+ return false;
+
+ if (Failed == true)
+ 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.Open() == 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);