+ if (!CheckAuth(Fetcher))
+ return false;
+
+ /* Unlock the dpkg lock if we are not going to be doing an install
+ after. */
+ if (_config->FindB("APT::Get::Download-Only",false) == true)
+ _system->UnLock();
+
+ // Run it
+ while (1)
+ {
+ bool Transient = false;
+ if (_config->FindB("APT::Get::Download",true) == false)
+ {
+ for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd();)
+ {
+ if ((*I)->Local == true)
+ {
+ I++;
+ continue;
+ }
+
+ // Close the item and check if it was found in cache
+ (*I)->Finished();
+ if ((*I)->Complete == false)
+ Transient = true;
+
+ // Clear it out of the fetch list
+ delete *I;
+ I = Fetcher.ItemsBegin();
+ }
+ }
+
+ if (Fetcher.Run() == pkgAcquire::Failed)
+ return false;
+
+ // Print out errors
+ bool Failed = false;
+ for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
+ {
+ if ((*I)->Status == pkgAcquire::Item::StatDone &&
+ (*I)->Complete == true)
+ continue;
+
+ if ((*I)->Status == pkgAcquire::Item::StatIdle)
+ {
+ Transient = true;
+ // Failed = true;
+ continue;
+ }
+
+ fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
+ (*I)->ErrorText.c_str());
+ Failed = true;
+ }
+
+ /* If we are in no download mode and missing files and there were
+ 'failures' then the user must specify -m. Furthermore, there
+ is no such thing as a transient error in no-download mode! */
+ if (Transient == true &&
+ _config->FindB("APT::Get::Download",true) == false)
+ {
+ Transient = false;
+ Failed = true;
+ }
+
+ if (_config->FindB("APT::Get::Download-Only",false) == true)
+ {
+ if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
+ return _error->Error(_("Some files failed to download"));
+ c1out << _("Download complete and in download only mode") << endl;
+ return true;
+ }
+
+ if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
+ {
+ return _error->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
+ }
+
+ if (Transient == true && Failed == true)
+ return _error->Error(_("--fix-missing and media swapping is not currently supported"));
+
+ // Try to deal with missing package files
+ if (Failed == true && PM->FixMissing() == false)
+ {
+ cerr << _("Unable to correct missing packages.") << endl;
+ return _error->Error(_("Aborting Install."));
+ }
+
+ _system->UnLock();
+ pkgPackageManager::OrderResult Res = PM->DoInstall();
+ if (Res == pkgPackageManager::Failed || _error->PendingError() == true)
+ return false;
+ if (Res == pkgPackageManager::Completed)
+ return true;
+
+ // Reload the fetcher object and loop again for media swapping
+ Fetcher.Shutdown();
+ if (PM->GetArchives(&Fetcher,&List,&Recs) == false)
+ return false;
+
+ _system->Lock();
+ }
+}
+ /*}}}*/
+// TryToInstall - Try to install a single package /*{{{*/
+// ---------------------------------------------------------------------
+/* This used to be inlined in DoInstall, but with the advent of regex package
+ name matching it was split out.. */
+bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache,
+ pkgProblemResolver &Fix,bool Remove,bool BrokenFix,
+ unsigned int &ExpectedInst,bool AllowFail = true)
+{
+ /* This is a pure virtual package and there is a single available
+ provides */
+ if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0 &&
+ Pkg.ProvidesList()->NextProvides == 0)
+ {
+ pkgCache::PkgIterator Tmp = Pkg.ProvidesList().OwnerPkg();
+ ioprintf(c1out,_("Note, selecting %s instead of %s\n"),
+ Tmp.Name(),Pkg.Name());
+ Pkg = Tmp;
+ }
+
+ // Handle the no-upgrade case
+ if (_config->FindB("APT::Get::upgrade",true) == false &&
+ Pkg->CurrentVer != 0)
+ {
+ if (AllowFail == true)
+ ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"),
+ Pkg.Name());
+ return true;
+ }
+
+ // Check if there is something at all to install
+ pkgDepCache::StateCache &State = Cache[Pkg];
+ if (Remove == true && Pkg->CurrentVer == 0)
+ {
+ Fix.Clear(Pkg);
+ Fix.Protect(Pkg);
+ Fix.Remove(Pkg);
+
+ /* We want to continue searching for regex hits, so we return false here
+ otherwise this is not really an error. */
+ if (AllowFail == false)
+ return false;
+
+ ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.Name());
+ return true;
+ }
+
+ 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 is not available, but is referred to by another package.\n"
+ "This may mean that the package is missing, has been obsoleted, or\n"
+ "is only available from another source\n"),Pkg.Name());
+
+ string List;
+ string VersionsList;
+ 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()) + " ";
+ //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
+ }
+ ShowList(c1out,_("However the following packages replace it:"),List,VersionsList);
+ }
+
+ _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,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
+ Pkg.Name());
+ else
+ Cache.SetReInstall(Pkg,true);
+ }
+ else
+ {
+ if (AllowFail == true)
+ ioprintf(c1out,_("%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)