summaryrefslogtreecommitdiff
path: root/cmdline/apt-get.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-02-08 11:02:46 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2011-02-08 11:02:46 +0100
commit86e2dc4dd728924d71995ebaeb83a4d9abba94d5 (patch)
treeb535bac6a1c5d75a3db5c810fb225c1e26f080b7 /cmdline/apt-get.cc
parentde6d91438ef2e3632615647647099f4c6fa227fa (diff)
parent33e46bc7032c2bcab654ab3f6a0a10ad82264ead (diff)
merged from the debian-sid branch
Diffstat (limited to 'cmdline/apt-get.cc')
-rw-r--r--cmdline/apt-get.cc197
1 files changed, 135 insertions, 62 deletions
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index 8754744da..0419359a3 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -538,7 +538,9 @@ bool ShowEssential(ostream &out,CacheFile &Cache)
//VersionsList += string(Cache[I].CurVersion) + "\n"; ???
}
}
-
+ else
+ continue;
+
if (I->CurrentVer == 0)
continue;
@@ -626,6 +628,8 @@ class CacheSetHelperAPTGet : public APT::CacheSetHelper {
APT::PackageSet virtualPkgs;
public:
+ std::list<std::pair<pkgCache::VerIterator, std::string> > selectedByRelease;
+
CacheSetHelperAPTGet(std::ostream &out) : APT::CacheSetHelper(true), out(out) {
explicitlyNamed = true;
}
@@ -644,9 +648,9 @@ public:
}
virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
string const &ver, bool const &verIsRel) {
- if (ver != Ver.VerStr())
- ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"),
- Ver.VerStr(), Ver.RelStr().c_str(), Pkg.FullName(true).c_str());
+ if (ver == Ver.VerStr())
+ return;
+ selectedByRelease.push_back(make_pair(Ver, ver));
}
bool showVirtualPackageErrors(pkgCacheFile &Cache) {
@@ -827,6 +831,37 @@ struct TryToInstall {
}
}
+ bool propergateReleaseCandiateSwitching(std::list<std::pair<pkgCache::VerIterator, std::string> > start, std::ostream &out)
+ {
+ for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
+ s != start.end(); ++s)
+ Cache->GetDepCache()->SetCandidateVersion(s->first);
+
+ bool Success = true;
+ std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
+ for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
+ s != start.end(); ++s)
+ {
+ Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache)));
+ // We continue here even if it failed to enhance the ShowBroken output
+ Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed);
+ }
+ for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
+ c != Changed.end(); ++c)
+ {
+ if (c->second.end() == true)
+ ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"),
+ c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str());
+ else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group)
+ {
+ pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache);
+ ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(),
+ V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str());
+ }
+ }
+ return Success;
+ }
+
void doAutoInstall() {
for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin();
P != doAutoInstallLater.end(); ++P) {
@@ -860,7 +895,11 @@ struct TryToRemove {
if ((Pkg->CurrentVer == 0 && PurgePkgs == false) ||
(PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled))
+ {
ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.FullName(true).c_str());
+ // MarkInstall refuses to install packages on hold
+ Pkg->SelectedState = pkgCache::State::Hold;
+ }
else
Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs);
}
@@ -1077,8 +1116,6 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = 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;
@@ -1608,10 +1645,6 @@ bool DoAutomaticRemove(CacheFile &Cache)
if(Debug)
std::cout << "DoAutomaticRemove()" << std::endl;
- // we don't want to autoremove and we don't want to see it, so why calculating?
- if (doAutoRemove == false && hideAutoRemove == true)
- return true;
-
if (doAutoRemove == true &&
_config->FindB("APT::Get::Remove",true) == false)
{
@@ -1622,7 +1655,7 @@ bool DoAutomaticRemove(CacheFile &Cache)
bool purgePkgs = _config->FindB("APT::Get::Purge", false);
bool smallList = (hideAutoRemove == false &&
- strcasecmp(_config->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
+ strcasecmp(_config->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
string autoremovelist, autoremoveversions;
unsigned long autoRemoveCount = 0;
@@ -1645,8 +1678,12 @@ bool DoAutomaticRemove(CacheFile &Cache)
}
else
{
+ // if the package is a new install and already garbage we don't need to
+ // install it in the first place, so nuke it instead of show it
+ if (Cache[Pkg].Install() == true && Pkg.CurrentVer() == 0)
+ Cache->MarkDelete(Pkg, false);
// only show stuff in the list that is not yet marked for removal
- if(Cache[Pkg].Delete() == false)
+ else if(hideAutoRemove == false && Cache[Pkg].Delete() == false)
{
++autoRemoveCount;
// we don't need to fill the strings if we don't need them
@@ -1659,6 +1696,20 @@ bool DoAutomaticRemove(CacheFile &Cache)
}
}
}
+
+ // Now see if we had destroyed anything (if we had done anything)
+ if (Cache->BrokenCount() != 0)
+ {
+ c1out << _("Hmm, seems like the AutoRemover destroyed something which really\n"
+ "shouldn't happen. Please file a bug report against apt.") << endl;
+ c1out << endl;
+ c1out << _("The following information may help to resolve the situation:") << endl;
+ c1out << endl;
+ ShowBroken(c1out,Cache,false);
+
+ return _error->Error(_("Internal Error, AutoRemover broke stuff"));
+ }
+
// if we don't remove them, we should show them!
if (doAutoRemove == false && (autoremovelist.empty() == false || autoRemoveCount != 0))
{
@@ -1671,18 +1722,6 @@ bool DoAutomaticRemove(CacheFile &Cache)
"%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount);
c1out << _("Use 'apt-get autoremove' to remove them.") << std::endl;
}
- // Now see if we had destroyed anything (if we had done anything)
- else if (Cache->BrokenCount() != 0)
- {
- c1out << _("Hmm, seems like the AutoRemover destroyed something which really\n"
- "shouldn't happen. Please file a bug report against apt.") << endl;
- c1out << endl;
- c1out << _("The following information may help to resolve the situation:") << endl;
- c1out << endl;
- ShowBroken(c1out,Cache,false);
-
- return _error->Error(_("Internal Error, AutoRemover broke stuff"));
- }
return true;
}
/*}}}*/
@@ -1755,14 +1794,7 @@ bool DoInstall(CommandLine &CmdL)
return false;
}
- unsigned short order[] = { 0, 0, 0 };
- if (fallback == MOD_INSTALL) {
- order[0] = MOD_INSTALL;
- order[1] = MOD_REMOVE;
- } else {
- order[0] = MOD_REMOVE;
- order[1] = MOD_INSTALL;
- }
+ unsigned short const order[] = { MOD_REMOVE, MOD_INSTALL, 0 };
TryToInstall InstallAction(Cache, Fix, BrokenFix);
TryToRemove RemoveAction(Cache, Fix);
@@ -1775,6 +1807,7 @@ bool DoInstall(CommandLine &CmdL)
{
if (order[i] == MOD_INSTALL) {
InstallAction = std::for_each(verset[MOD_INSTALL].begin(), verset[MOD_INSTALL].end(), InstallAction);
+ InstallAction.propergateReleaseCandiateSwitching(helper.selectedByRelease, c0out);
InstallAction.doAutoInstall();
}
else if (order[i] == MOD_REMOVE)
@@ -1839,16 +1872,15 @@ bool DoInstall(CommandLine &CmdL)
pkgCache::PkgIterator I(Cache,Cache.List[J]);
if ((*Cache)[I].Install() == false)
continue;
+ pkgCache::VerIterator Cand = Cache[I].CandidateVerIter(Cache);
+ if (Cand.Pseudo() == true)
+ continue;
- const char **J;
- for (J = CmdL.FileList + 1; *J != 0; J++)
- if (strcmp(*J,I.Name()) == 0)
- break;
-
- if (*J == 0) {
- List += I.FullName(true) + " ";
- VersionsList += string(Cache[I].CandVersion) + "\n";
- }
+ if (verset[MOD_INSTALL].find(Cand) != verset[MOD_INSTALL].end())
+ continue;
+
+ List += I.FullName(true) + " ";
+ VersionsList += string(Cache[I].CandVersion) + "\n";
}
ShowList(c1out,_("The following extra packages will be installed:"),List,VersionsList);
@@ -2176,13 +2208,15 @@ bool DoDownload(CommandLine &CmdL)
APT::CacheSetHelper helper(c0out);
APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache,
CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper);
- pkgAcquire Fetcher;
- AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
- Fetcher.Setup(&Stat);
if (verset.empty() == true)
return false;
+ pkgAcquire Fetcher;
+ AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
+ if (_config->FindB("APT::Get::Print-URIs") == true)
+ Fetcher.Setup(&Stat);
+
pkgRecords Recs(Cache);
pkgSourceList *SrcList = Cache.GetSourceList();
for (APT::VersionSet::const_iterator Ver = verset.begin();
@@ -2213,9 +2247,18 @@ bool DoDownload(CommandLine &CmdL)
// get the file
new pkgAcqFile(&Fetcher, uri, hash.toStr(), (*Ver)->Size, descr, Pkg.Name(), ".");
}
- bool result = (Fetcher.Run() == pkgAcquire::Continue);
- return result;
+ // Just print out the uris and exit if the --print-uris flag was used
+ if (_config->FindB("APT::Get::Print-URIs") == true)
+ {
+ pkgAcquire::UriIterator I = Fetcher.UriBegin();
+ for (; I != Fetcher.UriEnd(); I++)
+ cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
+ I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
+ return true;
+ }
+
+ return (Fetcher.Run() == pkgAcquire::Continue);
}
/*}}}*/
// DoCheck - Perform the check operation /*{{{*/
@@ -2844,6 +2887,7 @@ bool GuessThirdPartyChangelogUri(CacheFile &Cache,
// now strip away the filename and add srcpkg_srcver.changelog
return true;
}
+ /*}}}*/
// DownloadChangelog - Download the changelog /*{{{*/
// ---------------------------------------------------------------------
bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher,
@@ -2868,13 +2912,19 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher,
"http://packages.debian.org/changelogs");
path = GetChangelogPath(CacheFile, Pkg, Ver);
strprintf(changelog_uri, "%s/%s/changelog", server.c_str(), path.c_str());
+ if (_config->FindB("APT::Get::Print-URIs", false) == true)
+ {
+ std::cout << '\'' << changelog_uri << '\'' << std::endl;
+ return true;
+ }
+
strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), changelog_uri.c_str());
// queue it
new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
- // try downloading it, if that fails, they third-party-changelogs location
- // FIXME: res is "Continue" even if I get a 404?!?
- int res = Fetcher.Run();
+ // try downloading it, if that fails, try third-party-changelogs location
+ // FIXME: Fetcher.Run() is "Continue" even if I get a 404?!?
+ Fetcher.Run();
if (!FileExists(targetfile))
{
string third_party_uri;
@@ -2882,7 +2932,7 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher,
{
strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), third_party_uri.c_str());
new pkgAcqFile(&Fetcher, third_party_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
- res = Fetcher.Run();
+ Fetcher.Run();
}
}
@@ -2925,30 +2975,53 @@ bool DoChangelog(CommandLine &CmdL)
APT::CacheSetHelper helper(c0out);
APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache,
CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper);
+ if (verset.empty() == true)
+ return false;
pkgAcquire Fetcher;
+
+ if (_config->FindB("APT::Get::Print-URIs", false) == true)
+ for (APT::VersionSet::const_iterator Ver = verset.begin();
+ Ver != verset.end(); ++Ver)
+ return DownloadChangelog(Cache, Fetcher, Ver, "");
+
AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
Fetcher.Setup(&Stat);
- if (verset.empty() == true)
- return false;
- char *tmpdir = mkdtemp(strdup("/tmp/apt-changelog-XXXXXX"));
- if (tmpdir == NULL) {
- return _error->Errno("mkdtemp", "mkdtemp failed");
+ bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
+
+ char tmpname[100];
+ char* tmpdir = NULL;
+ if (downOnly == false)
+ {
+ const char* const tmpDir = getenv("TMPDIR");
+ if (tmpDir != NULL && *tmpDir != '\0')
+ snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", tmpDir);
+ else
+ strncpy(tmpname, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname));
+ tmpdir = mkdtemp(tmpname);
+ if (tmpdir == NULL)
+ return _error->Errno("mkdtemp", "mkdtemp failed");
}
-
+
for (APT::VersionSet::const_iterator Ver = verset.begin();
Ver != verset.end();
++Ver)
{
- string changelogfile = string(tmpdir) + "changelog";
- if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile))
+ string changelogfile;
+ if (downOnly == false)
+ changelogfile.append(tmpname).append("changelog");
+ else
+ changelogfile.append(Ver.ParentPkg().Name()).append(".changelog");
+ if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile) && downOnly == false)
+ {
DisplayFileInPager(changelogfile);
- // cleanup temp file
- unlink(changelogfile.c_str());
+ // cleanup temp file
+ unlink(changelogfile.c_str());
+ }
}
// clenaup tmp dir
- rmdir(tmpdir);
- free(tmpdir);
+ if (tmpdir != NULL)
+ rmdir(tmpdir);
return true;
}
/*}}}*/