From b47081521b0df1f835a2111254fa1fcd77240a85 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 23 Jan 2007 18:43:42 +0100 Subject: * cmdline/report-mirror-failure - basic mirror failure script added --- cmdline/report-mirror-failure | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 cmdline/report-mirror-failure (limited to 'cmdline') diff --git a/cmdline/report-mirror-failure b/cmdline/report-mirror-failure new file mode 100755 index 000000000..8301ed079 --- /dev/null +++ b/cmdline/report-mirror-failure @@ -0,0 +1,21 @@ +#!/usr/bin/python + +import sys +import urllib +import apt_pkg + +apt_pkg.init() +url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", + "http://people.ubuntu.com:9000/mirror-failure") + #"http://localhost:9000/mirror-failure") +if not url: + sys.exit(0) + +data = {} +data['url'] = sys.argv[1] +data['error'] = sys.argv[2] +f = urllib.urlopen(url, urllib.urlencode(data)) +f.read() +f.close() + + -- cgit v1.2.3 From 362d29343e5d25248bcd84300aa1b18effe891e7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 24 Jan 2007 14:42:17 +0100 Subject: make the mirror failures actually produce a error message --- cmdline/makefile | 6 ++++++ cmdline/report-mirror-failure | 21 --------------------- 2 files changed, 6 insertions(+), 21 deletions(-) delete mode 100755 cmdline/report-mirror-failure (limited to 'cmdline') diff --git a/cmdline/makefile b/cmdline/makefile index 882a0e1b5..f07c7da3b 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -52,3 +52,9 @@ SOURCE=apt-key TO=$(BIN) TARGET=program include $(COPY_H) + +# The apt-key program +SOURCE=apt-report-mirror-failure +TO=$(LIB) +TARGET=program +include $(COPY_H) diff --git a/cmdline/report-mirror-failure b/cmdline/report-mirror-failure deleted file mode 100755 index 8301ed079..000000000 --- a/cmdline/report-mirror-failure +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python - -import sys -import urllib -import apt_pkg - -apt_pkg.init() -url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", - "http://people.ubuntu.com:9000/mirror-failure") - #"http://localhost:9000/mirror-failure") -if not url: - sys.exit(0) - -data = {} -data['url'] = sys.argv[1] -data['error'] = sys.argv[2] -f = urllib.urlopen(url, urllib.urlencode(data)) -f.read() -f.close() - - -- cgit v1.2.3 From 36280399db0ae203d3f1ae4d44b946f31e9a38ce Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Feb 2007 12:32:50 +0100 Subject: * commited the latest mirror failure detection code --- cmdline/apt-report-mirror-failure | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 cmdline/apt-report-mirror-failure (limited to 'cmdline') diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure new file mode 100755 index 000000000..70b16cf4f --- /dev/null +++ b/cmdline/apt-report-mirror-failure @@ -0,0 +1,23 @@ +#!/usr/bin/python + +import sys +import urllib +import apt_pkg + +print "apt-report-mirror-failure" + +apt_pkg.init() +url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", + "http://people.ubuntu.com:9000/mirror-failure") + #"http://localhost:9000/mirror-failure") +if not url: + sys.exit(0) + +data = {} +data['url'] = sys.argv[1] +data['error'] = sys.argv[2] +f = urllib.urlopen(url, urllib.urlencode(data)) +f.read() +f.close() + + -- cgit v1.2.3 From 361593e92a44255cc0ef98417e7457911716cab5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Feb 2007 13:02:47 +0100 Subject: * get the mirror failure stuff really working --- cmdline/apt-report-mirror-failure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure index 70b16cf4f..277b23e9a 100755 --- a/cmdline/apt-report-mirror-failure +++ b/cmdline/apt-report-mirror-failure @@ -4,8 +4,6 @@ import sys import urllib import apt_pkg -print "apt-report-mirror-failure" - apt_pkg.init() url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", "http://people.ubuntu.com:9000/mirror-failure") @@ -13,6 +11,8 @@ url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", if not url: sys.exit(0) +print "Reporting mirror failure to '%s'" % url + data = {} data['url'] = sys.argv[1] data['error'] = sys.argv[2] -- cgit v1.2.3 From f0b509cdb44cb5e79e9c5ddd7ebec46965138534 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 5 Feb 2007 19:06:42 +0100 Subject: * apt-pkg/acquire-item.cc: - use FailReason in pkgAcquire::Item::Failed when available * methods/mirror.cc: - move some debug output into if(Debug) --- cmdline/apt-report-mirror-failure | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure index 277b23e9a..fb43f0e74 100755 --- a/cmdline/apt-report-mirror-failure +++ b/cmdline/apt-report-mirror-failure @@ -14,8 +14,9 @@ if not url: print "Reporting mirror failure to '%s'" % url data = {} -data['url'] = sys.argv[1] -data['error'] = sys.argv[2] +data['mirror'] = sys.argv[1] +data['failurl'] = sys.argv[2] +data['error'] = sys.argv[3] f = urllib.urlopen(url, urllib.urlencode(data)) f.read() f.close() -- cgit v1.2.3 From 3f599bb721c4ac58d8ff18991c9704b5f30eaa2b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 6 Feb 2007 10:49:25 +0100 Subject: * apt-pkg/acquire-item.cc: - default to "/usr/lib/apt/apt-report-mirror-failure" * cmdline/apt-report-mirror-failure: - no default comit url for now * debian/rules: - move apt-report-mirror-failure into /usr/lib/apt * doc/examples/configure-index: - more documentation * methods/mirror.cc: - updated TODO --- cmdline/apt-report-mirror-failure | 4 ++-- cmdline/makefile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure index fb43f0e74..1567e78e3 100755 --- a/cmdline/apt-report-mirror-failure +++ b/cmdline/apt-report-mirror-failure @@ -5,8 +5,8 @@ import urllib import apt_pkg apt_pkg.init() -url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", - "http://people.ubuntu.com:9000/mirror-failure") +url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", None) + #"http://people.ubuntu.com:9000/mirror-failure") #"http://localhost:9000/mirror-failure") if not url: sys.exit(0) diff --git a/cmdline/makefile b/cmdline/makefile index f07c7da3b..8d284c2f3 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -55,6 +55,6 @@ include $(COPY_H) # The apt-key program SOURCE=apt-report-mirror-failure -TO=$(LIB) +TO=$(BIN) TARGET=program include $(COPY_H) -- cgit v1.2.3 From ba688e8d8be99334b96f32a861ad23a0abb9b886 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 13 Mar 2007 12:02:38 +0100 Subject: * cmdline/apt-get.cc: - fix version output in autoremove list (LP#68941) --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 765591b14..4ffb9414b 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1446,7 +1446,7 @@ bool DoAutomaticRemove(CacheFile &Cache) std::cout << "We could delete %s" << Pkg.Name() << std::endl; autoremovelist += string(Pkg.Name()) + " "; - autoremoveversions += string(Cache[Pkg].CandVersion) + " "; + autoremoveversions += string(Cache[Pkg].CandVersion) + "\n"; if (doAutoRemove) { if(Pkg.CurrentVer() != 0 && -- cgit v1.2.3 From 7db98f31498a85da22cc00e446bce8ac8c319554 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 14 Mar 2007 13:10:42 +0100 Subject: * cmdline/apt-get.cc: - "apt-get install foo" on a already installed package foo will clean the automatic installed flag --- cmdline/apt-get.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 4ffb9414b..430b1bccb 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1556,6 +1556,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); @@ -1692,6 +1693,18 @@ 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(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++; + } } } @@ -1854,6 +1867,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); -- cgit v1.2.3 From 28e454d68b9cc6ba60e19dcbcfe3a97c151ef8f8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 14 Mar 2007 13:47:49 +0100 Subject: - do not show packages already marked for removal as auto-installed --- cmdline/apt-get.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 430b1bccb..d1d6ab7b4 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -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) + "\n"; + + // 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 && @@ -1697,7 +1701,8 @@ bool DoInstall(CommandLine &CmdL) // see if we need to fix the auto-mark flag // e.g. apt-get install foo // where foo is marked automatic - if(Cache[Pkg].Install() == false && + if(!Remove && + Cache[Pkg].Install() == false && (Cache[Pkg].Flags & pkgCache::Flag::Auto)) { ioprintf(c1out,_("%s set to manual installed.\n"), -- cgit v1.2.3 From 31dc104687b79d3d9dea7d8c0e1a2bde80598ff0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 14 Mar 2007 17:11:25 +0100 Subject: * cmdline/apt-mark: fix chmod()/rename() ordering --- cmdline/apt-mark | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-mark b/cmdline/apt-mark index 728f083dc..dadc01366 100755 --- a/cmdline/apt-mark +++ b/cmdline/apt-mark @@ -60,5 +60,5 @@ if __name__ == "__main__": else: outfile.write(str(tagfile.Section)+"\n") # all done, rename the tmpfile - os.rename(outfile.name, STATE_FILE) os.chmod(outfile.name, 0644) + os.rename(outfile.name, STATE_FILE) -- cgit v1.2.3 From 3238423f4d0bebf02c02fa6e5ca5b6db4fca56c5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 18 Jun 2007 14:06:21 +0200 Subject: * implement warning when Vcs-*: header is found in source record --- cmdline/apt-get.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 554677f39..51bcfde12 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2114,6 +2114,28 @@ bool DoSource(CommandLine &CmdL) if (Last == 0) return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); + string srec = Last->AsStr(); + string::size_type pos = srec.find("\nVcs-"); + if (pos != string::npos ) + { + pos += strlen("\nVcs-"); + string vcs = srec.substr(pos,srec.find(":",pos)-pos); + pos += vcs.length()+2; + string::size_type epos = srec.find("\n", pos); + string uri = srec.substr(pos,epos-pos).c_str(); + ioprintf(c1out, _("WARNING: '%s' is maintained in " + "the '%s' version control system at:\n" + "'%s'\n"), + Src.c_str(), vcs.c_str(), uri.c_str()); + if(vcs == "Bzr") + ioprintf(c1out,_("Please use: 'bzr get %s'\n" + "to modify the package.\n"), + uri.c_str()); + ioprintf(c1out, "Are you sure you want to continue [yN]? "); + if(!YnPrompt(false)) + return _error->Error(_("Abort.")); + } + // Back track vector Lst; if (Last->Files(Lst) == false) -- cgit v1.2.3 From 541c83b92a4919ba0aed6150f71e227d07f93a02 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 27 Jun 2007 13:34:34 +0200 Subject: * cmdline/apt-get.cc: - fix InstallTask code when a pkgRecord ends with a single '\n' (thanks to Soren Hansen for reporting) --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 51bcfde12..974427f51 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1519,7 +1519,7 @@ bool TryInstallTask(pkgDepCache &Cache, pkgProblemResolver &Fix, // build regexp for the task char S[300]; - snprintf(S, sizeof(S), "^Task:.*[^a-z]%s[^a-z].*\n", taskname); + snprintf(S, sizeof(S), "^Task:.*[^a-z]%s[^a-z].*$", taskname); regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE); bool found = false; -- cgit v1.2.3 From 927677f0ae5f92bb6935c91b08ee6ffe220d4bfa Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Jun 2007 18:19:58 +0200 Subject: * cmdline/apt-get.cc: - make the ouput more friendly for copy and paste (thanks to Matt Zimmerman) --- cmdline/apt-get.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 51bcfde12..930d88d99 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2128,7 +2128,8 @@ bool DoSource(CommandLine &CmdL) "'%s'\n"), Src.c_str(), vcs.c_str(), uri.c_str()); if(vcs == "Bzr") - ioprintf(c1out,_("Please use: 'bzr get %s'\n" + ioprintf(c1out,_("Please use:\n" + "bzr get %s\n" "to modify the package.\n"), uri.c_str()); ioprintf(c1out, "Are you sure you want to continue [yN]? "); -- cgit v1.2.3 From 8756297c0f5987d2320955c21e5c64395ce311cc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Jun 2007 18:38:55 +0200 Subject: * cmdline/apt-get.cc: - remove '' around xs-vcs-$repo to make pasting easier --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 930d88d99..fa7ae32eb 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2125,7 +2125,7 @@ bool DoSource(CommandLine &CmdL) string uri = srec.substr(pos,epos-pos).c_str(); ioprintf(c1out, _("WARNING: '%s' is maintained in " "the '%s' version control system at:\n" - "'%s'\n"), + "%s\n"), Src.c_str(), vcs.c_str(), uri.c_str()); if(vcs == "Bzr") ioprintf(c1out,_("Please use:\n" -- cgit v1.2.3 From 774a66876919712d5b8e12174f01f0337d2f3393 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 29 Jun 2007 13:04:17 +0200 Subject: * cmdline/apt-get.cc: - ignore Vcs-Browser flag (#121770) --- cmdline/apt-get.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index fa7ae32eb..08bb1bc34 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2116,10 +2116,15 @@ bool DoSource(CommandLine &CmdL) string srec = Last->AsStr(); string::size_type pos = srec.find("\nVcs-"); - if (pos != string::npos ) + while (pos != string::npos) { pos += strlen("\nVcs-"); string vcs = srec.substr(pos,srec.find(":",pos)-pos); + if(vcs == "Browser") + { + pos = srec.find("\nVcs-", pos); + continue; + } pos += vcs.length()+2; string::size_type epos = srec.find("\n", pos); string uri = srec.substr(pos,epos-pos).c_str(); @@ -2135,6 +2140,8 @@ bool DoSource(CommandLine &CmdL) ioprintf(c1out, "Are you sure you want to continue [yN]? "); if(!YnPrompt(false)) return _error->Error(_("Abort.")); + else + break; } // Back track -- cgit v1.2.3 From b799e134fc730519cc8f0c0ea4387badffac4092 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 8 Aug 2007 12:52:56 +0200 Subject: * cmdline/apt-get.cc: - remove YnPrompt when a XS-Vcs- tag is found, improve the notice (LP: #129575) --- cmdline/apt-get.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index ead053136..e7b7d5204 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2130,20 +2130,17 @@ bool DoSource(CommandLine &CmdL) pos += vcs.length()+2; string::size_type epos = srec.find("\n", pos); string uri = srec.substr(pos,epos-pos).c_str(); - ioprintf(c1out, _("WARNING: '%s' is maintained in " + ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in " "the '%s' version control system at:\n" "%s\n"), Src.c_str(), vcs.c_str(), uri.c_str()); if(vcs == "Bzr") ioprintf(c1out,_("Please use:\n" "bzr get %s\n" - "to modify the package.\n"), + "to retrieve the latest (possible unreleased) " + "updates to the package.\n"), uri.c_str()); - ioprintf(c1out, "Are you sure you want to continue [yN]? "); - if(!YnPrompt(false)) - return _error->Error(_("Abort.")); - else - break; + break; } // Back track -- cgit v1.2.3 From fd9a8ca2ed30994a7946acbf54f25d27fe2b10cb Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 13 Feb 2008 19:52:12 +0100 Subject: cmdline/apt-key: import net_update key from the project/ directory for now --- cmdline/apt-key | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-key b/cmdline/apt-key index e0c4b5e48..7d6f9c589 100755 --- a/cmdline/apt-key +++ b/cmdline/apt-key @@ -12,7 +12,7 @@ GPG="$GPG_CMD --keyring /etc/apt/trusted.gpg" MASTER_KEYRING=/usr/share/keyrings/ubuntu-master-keyring.gpg ARCHIVE_KEYRING=/usr/share/keyrings/ubuntu-archive-keyring.gpg REMOVED_KEYS=/usr/share/keyrings/ubuntu-archive-removed-keys.gpg -ARCHIVE_KEYRING_URI=http://archive.ubuntu.com/ubuntu/ubuntu-archive-keyring.gpg +ARCHIVE_KEYRING_URI=http://archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg add_keys_with_verify_against_master_keyring() { ADD_KEYRING=$1 -- cgit v1.2.3 From 6f320e7b0fe9e9f1e1ac4452ba7a4c1eca297842 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 11 Mar 2008 09:54:45 +0100 Subject: * cmdline/apt-get.cc: - fix incorrect help output for -f (LP: #57487) --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 8956332a3..c522d4f87 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2662,7 +2662,7 @@ bool ShowHelp(CommandLine &CmdL) " -d Download only - do NOT install or unpack archives\n" " -s No-act. Perform ordering simulation\n" " -y Assume Yes to all queries and do not prompt\n" - " -f Attempt to continue if the integrity check fails\n" + " -f Attempt to correct a system with broken dependencies in place\n" " -m Attempt to continue if archives are unlocatable\n" " -u Show a list of upgraded packages as well\n" " -b Build the source package after fetching it\n" -- cgit v1.2.3 From 95717122196eb888bc81f5c3e8daa74cad8db649 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 11 Mar 2008 17:41:55 +0100 Subject: - run the problemResolver after a task was installed so that it can correct any missing dependencies --- cmdline/apt-get.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index c522d4f87..c8671447e 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1506,10 +1506,13 @@ bool TryInstallTask(pkgDepCache &Cache, pkgProblemResolver &Fix, buf[end-start] = 0x0; if (regexec(&Pattern,buf,0,0,0) != 0) continue; - res &= TryToInstall(Pkg,Cache,Fix,Remove,false,ExpectedInst); + res &= TryToInstall(Pkg,Cache,Fix,Remove,true,ExpectedInst); found = true; } + // now let the problem resolver deal with any issues + Fix.Resolve(true); + if(!found) _error->Error(_("Couldn't find task %s"),taskname); -- cgit v1.2.3 From c22356d86150dfee4903ff146a64cd5ad63be827 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 13 Mar 2008 23:42:43 +0100 Subject: * cmdline/apt-get.cc: - do two passes when installing tasks, first ignoring dependencies, then resolving them and run the problemResolver at the end so that it can correct any missing dependencies. This should fix livecd building for kubuntu (thanks to Jonathan Riddell for reporting the problem) --- cmdline/apt-get.cc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index c8671447e..cabbde5cb 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1495,19 +1495,24 @@ bool TryInstallTask(pkgDepCache &Cache, pkgProblemResolver &Fix, bool found = false; bool res = true; - for (Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + + // two runs, first ignore dependencies, second install any missing + for(int IgnoreBroken=1; IgnoreBroken >= 0; IgnoreBroken--) { - pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache); - if(ver.end()) - continue; - pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); - parser.GetRec(start,end); - strncpy(buf, start, end-start); - buf[end-start] = 0x0; - if (regexec(&Pattern,buf,0,0,0) != 0) - continue; - res &= TryToInstall(Pkg,Cache,Fix,Remove,true,ExpectedInst); - found = true; + for (Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + { + pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache); + if(ver.end()) + continue; + pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); + parser.GetRec(start,end); + strncpy(buf, start, end-start); + buf[end-start] = 0x0; + if (regexec(&Pattern,buf,0,0,0) != 0) + continue; + res &= TryToInstall(Pkg,Cache,Fix,Remove,IgnoreBroken,ExpectedInst); + found = true; + } } // now let the problem resolver deal with any issues -- cgit v1.2.3 From 397d56f56b3ffaf38df57571c11f0699e2810902 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 8 Apr 2008 14:20:06 +0200 Subject: * cmdline/apt-key: - only check against master-keys in net-update to not break custom CDs (thanks to Colin Watson) --- cmdline/apt-key | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-key b/cmdline/apt-key index 77a2a4623..de04d16da 100755 --- a/cmdline/apt-key +++ b/cmdline/apt-key @@ -29,9 +29,8 @@ add_keys_with_verify_against_master_keyring() { # when adding new keys, make sure that the archive-master-keyring # is honored. so: - # all keys that are exported and have the name - # "Ubuntu Archive Automatic Signing Key" must have a valid signature - # from a key in the ubuntu-master-keyring + # all keys that are exported must have a valid signature + # from a key in the $distro-master-keyring add_keys=`$GPG_CMD --keyring $ADD_KEYRING --with-colons --list-keys | grep ^pub | cut -d: -f5` master_keys=`$GPG_CMD --keyring $MASTER --with-colons --list-keys | grep ^pub | cut -d: -f5` for add_key in $add_keys; do @@ -81,13 +80,14 @@ update() { exit 1 fi - # add new keys, if no MASTER_KEYRING is used, use the traditional - # way - if [ -z "$MASTER_KEYRING" ]; then - $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --import - else - add_keys_with_verify_against_master_keyring $ARCHIVE_KEYRING $MASTER_KEYRING - fi + # add new keys from the package; + + # we do not use add_keys_with_verify_against_master_keyring here, + # because we "update" is run on regular package updates. A + # attacker might as well replace the master-archive-keyring file + # in the package and add his own keys. so this check wouldn't + # add any security. we *need* this check on net-update though + $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --import # remove no-longer supported/used keys keys=`$GPG_CMD --keyring $REMOVED_KEYS --with-colons --list-keys | grep ^pub | cut -d: -f5` -- cgit v1.2.3 From 9772f307fdf1f4cc94690b4ba3705a8f891033fe Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 8 Dec 2008 09:37:09 -0800 Subject: * cmdline/apt-get.cc: - fix "apt-get source pkg=ver" if binary name != source name (LP: #202219) * doc/makefile: - add examples/apt-https-method-example.conf --- cmdline/apt-get.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index bd95e917b..ea7d45952 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1295,9 +1295,9 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, { string Ver = Parse->Version(); - // Skip name mismatches - if (IsMatch == true && Parse->Package() != Src) - continue; + // show name mismatches + if (IsMatch == true && Parse->Package() != Src) + ioprintf(c1out, _("No source package '%s' picking '%s' instead"), Parse->Package(), Src); if (VerTag.empty() == false) { -- cgit v1.2.3 From 71da8af4dabe8680802ef291267c2f53d7942d18 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 16 Dec 2008 07:38:42 +0100 Subject: Clarify the --help for 'purge' (LP: #243948) --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index ea7d45952..d5869da43 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2659,7 +2659,7 @@ bool ShowHelp(CommandLine &CmdL) " install - Install new packages (pkg is libc6 not libc6.deb)\n" " remove - Remove packages\n" " autoremove - Remove automatically all unused packages\n" - " purge - Remove and purge packages\n" + " purge - Remove packages and config files\n" " source - Download source archives\n" " build-dep - Configure build-dependencies for source packages\n" " dist-upgrade - Distribution upgrade, see apt-get(8)\n" -- cgit v1.2.3 From 236527f0fffe30fc8988e17d926778c23ac1f902 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 28 Jan 2009 17:39:37 +0100 Subject: LP: #263089 --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index d5869da43..38775f70d 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1297,7 +1297,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, // show name mismatches if (IsMatch == true && Parse->Package() != Src) - ioprintf(c1out, _("No source package '%s' picking '%s' instead"), Parse->Package(), Src); + ioprintf(c1out, _("No source package '%s' picking '%s' instead"), Parse->Package().c_str(), Src.c_str()); if (VerTag.empty() == false) { -- cgit v1.2.3 From 4bfb7a7756eed967c1edad63bc16a37b741cafaa Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Feb 2009 14:34:50 +0100 Subject: * cmdline/apt-get.cc: - default to "false" for the "APT::Get::Build-Dep-Automatic" option (follow debian here) --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 38775f70d..2117a7f2a 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2542,7 +2542,7 @@ bool DoBuildDep(CommandLine &CmdL) { // We successfully installed something; skip remaining alternatives skipAlternatives = hasAlternatives; - if(_config->FindB("APT::Get::Build-Dep-Automatic", true) == true) + if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true) Cache->MarkAuto(Pkg, true); continue; } -- cgit v1.2.3 From 5ef499349c609f5ef50bd633692faa2665f4f96f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Mar 2009 16:33:39 +0100 Subject: * cmdline/apt-get.cc - fix "apt-get source pkg" if there is a binary package and a source package of the same name but from different packages (LP: #330103) --- cmdline/apt-get.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 2117a7f2a..0339afdf1 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1272,16 +1272,23 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, } } } - - // 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; + bool MatchSrcOnly = false; + + // No source package name.. + if (Src.empty() == true) + Src = TmpSrc; + else + // if we have a source pkg name, make sure to only search + // for srcpkg names, otherwise apt gets confused if there + // is a binary package "pkg1" and a source package "pkg1" + // with the same name but that comes from different packages + MatchSrcOnly = true; // If we are matching by version then we need exact matches to be happy if (VerTag.empty() == false) @@ -1291,13 +1298,13 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, binary packages in the search */ pkgSrcRecords::Parser *Parse; SrcRecs.Restart(); - while ((Parse = SrcRecs.Find(Src.c_str(),false)) != 0) + while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0) { string Ver = Parse->Version(); // show name mismatches if (IsMatch == true && Parse->Package() != Src) - ioprintf(c1out, _("No source package '%s' picking '%s' instead"), Parse->Package().c_str(), Src.c_str()); + ioprintf(c1out, _("No source package '%s' picking '%s' instead\n"), Parse->Package().c_str(), Src.c_str()); if (VerTag.empty() == false) { -- cgit v1.2.3 From 5dad4134da37576de12721f34165c1fe4d138b3c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 19 Mar 2009 15:42:25 +0100 Subject: * methods/mirror.cc: - when download the mirror file and the server is down, return a propper error message (LP: #278635) --- cmdline/apt-report-mirror-failure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure index 1567e78e3..ef77d4954 100755 --- a/cmdline/apt-report-mirror-failure +++ b/cmdline/apt-report-mirror-failure @@ -5,7 +5,7 @@ import urllib import apt_pkg apt_pkg.init() -url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", None) +url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", "") #"http://people.ubuntu.com:9000/mirror-failure") #"http://localhost:9000/mirror-failure") if not url: -- cgit v1.2.3 From 6b802e56f55a43e9967cd8d41148646fd95ea8e3 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 26 Mar 2009 23:52:26 +0000 Subject: * cmdline/acqprogress.cc: - Call pkgAcquireStatus::Pulse even if quiet, so that we still get dlstatus messages on the status-fd (LP: #290234). --- cmdline/acqprogress.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/acqprogress.cc b/cmdline/acqprogress.cc index a5fee1db5..b3ded4142 100644 --- a/cmdline/acqprogress.cc +++ b/cmdline/acqprogress.cc @@ -145,11 +145,11 @@ void AcqTextStatus::Stop() bandwidth and ETA indicator. */ bool AcqTextStatus::Pulse(pkgAcquire *Owner) { + pkgAcquireStatus::Pulse(Owner); + if (Quiet > 0) return true; - pkgAcquireStatus::Pulse(Owner); - enum {Long = 0,Medium,Short} Mode = Long; char Buffer[sizeof(BlankLine)]; -- cgit v1.2.3 From 28b5ff3f76e63f0b4bbed5980b9c13f4a7c3cecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Minier?= Date: Sun, 10 May 2009 12:12:29 +0200 Subject: Drop duplicate "purge" in command list. --- cmdline/apt-get.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 0339afdf1..988abe216 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2778,7 +2778,6 @@ int main(int argc,const char *argv[]) {"remove",&DoInstall}, {"purge",&DoInstall}, {"autoremove",&DoInstall}, - {"purge",&DoInstall}, {"dist-upgrade",&DoDistUpgrade}, {"dselect-upgrade",&DoDSelectUpgrade}, {"build-dep",&DoBuildDep}, -- cgit v1.2.3 From 3d513bbd0c7cdcfb962403645dd9f05f0a127938 Mon Sep 17 00:00:00 2001 From: Brian Murray Date: Thu, 13 Aug 2009 13:25:21 -0700 Subject: incorporate string-fix patch from Matthew East for LP: #370094 --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 04f3944a9..7385c3dd3 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2127,7 +2127,7 @@ bool DoSource(CommandLine &CmdL) if(vcs == "Bzr") ioprintf(c1out,_("Please use:\n" "bzr get %s\n" - "to retrieve the latest (possible unreleased) " + "to retrieve the latest (possibly unreleased) " "updates to the package.\n"), uri.c_str()); break; -- cgit v1.2.3 From a69a3a044be84f72508fb468cdf13d9e5f724dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Minier?= Date: Fri, 28 Aug 2009 12:03:39 +0200 Subject: * cmdline/apt-key: - Emit a warning if removed keys keyring is missing and skip associated checks (LP: #218971) --- cmdline/apt-key | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-key b/cmdline/apt-key index 26aa55633..b579e5a53 100755 --- a/cmdline/apt-key +++ b/cmdline/apt-key @@ -90,13 +90,17 @@ update() { # add any security. we *need* this check on net-update though $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --import - # remove no-longer supported/used keys - keys=`$GPG_CMD --keyring $REMOVED_KEYS --with-colons --list-keys | grep ^pub | cut -d: -f5` - for key in $keys; do - if $GPG --list-keys --with-colons | grep ^pub | cut -d: -f5 | grep -q $key; then - $GPG --quiet --batch --delete-key --yes ${key} - fi - done + if [ -r "$REMOVED_KEYS" ]; then + # remove no-longer supported/used keys + keys=`$GPG_CMD --keyring $REMOVED_KEYS --with-colons --list-keys | grep ^pub | cut -d: -f5` + for key in $keys; do + if $GPG --list-keys --with-colons | grep ^pub | cut -d: -f5 | grep -q $key; then + $GPG --quiet --batch --delete-key --yes ${key} + fi + done + else + echo "Warning: removed keys keyring $REMOVED_KEYS missing or not readable" >&2 + fi } -- cgit v1.2.3 From 4df70e7528c21f948dfb7032271c499c53a21515 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 3 Feb 2010 09:42:36 -0800 Subject: * cmdline/apt-cdrom.cc: - make Acquire::cdrom::AutoDetect default, this can be turned off with "--no-auto-detect" --- cmdline/apt-cdrom.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index 0c9aab28c..8b9eacae6 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -147,7 +147,7 @@ bool DoAdd(CommandLine &) pkgCdrom cdrom; bool res = true; - bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); + bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect", true); unsigned int count = 0; if (AutoDetect && UdevCdroms.Dlopen()) -- cgit v1.2.3 From 6293e04ff36cd1cb4756fc30a4777ad6aaf8ffac Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Feb 2010 15:41:04 +0100 Subject: display the architecture of the package if it is not the default architecture in apt-get, display policy for all available architectures and use GrpIterator in apt-cache pkgnames --- cmdline/apt-cache.cc | 46 +++++++++++++++++++++++++++++++--------------- cmdline/apt-get.cc | 33 ++++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 26 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 7d7f58a62..cd806286c 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1417,11 +1417,15 @@ bool ShowPackage(CommandLine &CmdL) for (const char **I = CmdL.FileList + 1; *I != 0; I++) { + // FIXME: Handle the case in which pkgname name:arch is not found pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); if (Pkg.end() == true) { - _error->Warning(_("Unable to locate package %s"),*I); - continue; + Pkg = Cache.FindPkg(*I, "any"); + if (Pkg.end() == true) { + _error->Warning(_("Unable to locate package %s"),*I); + continue; + } } ++found; @@ -1457,16 +1461,17 @@ bool ShowPackage(CommandLine &CmdL) bool ShowPkgNames(CommandLine &CmdL) { pkgCache &Cache = *GCache; - pkgCache::PkgIterator I = Cache.PkgBegin(); - bool All = _config->FindB("APT::Cache::AllNames","false"); - + pkgCache::GrpIterator I = Cache.GrpBegin(); + bool const All = _config->FindB("APT::Cache::AllNames","false"); + if (CmdL.FileList[1] != 0) { for (;I.end() != true; I++) { - if (All == false && I->VersionList == 0) + if (All == false && I->FirstPackage == 0) + continue; + if (I.FindPkg("any")->VersionList == 0) continue; - if (strncmp(I.Name(),CmdL.FileList[1],strlen(CmdL.FileList[1])) == 0) cout << I.Name() << endl; } @@ -1477,7 +1482,9 @@ bool ShowPkgNames(CommandLine &CmdL) // Show all pkgs for (;I.end() != true; I++) { - if (All == false && I->VersionList == 0) + if (All == false && I->FirstPackage == 0) + continue; + if (I.FindPkg("any")->VersionList == 0) continue; cout << I.Name() << endl; } @@ -1565,19 +1572,27 @@ bool Policy(CommandLine &CmdL) return true; } - + + string const myArch = _config->Find("APT::Architecture"); + // Print out detailed information for each package for (const char **I = CmdL.FileList + 1; *I != 0; I++) { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); + pkgCache::GrpIterator Grp = Cache.FindGrp(*I); + pkgCache::PkgIterator Pkg = Grp.FindPkg("any"); if (Pkg.end() == true) { _error->Warning(_("Unable to locate package %s"),*I); continue; } - - cout << Pkg.Name() << ":" << endl; - + + for (; Pkg.end() != true; Pkg = Grp.NextPkg(Pkg)) { + + if (myArch == Pkg.Arch()) + cout << Pkg.Name() << ":" << endl; + else + cout << Pkg.Name() << ": [" << Pkg.Arch() << "]" << endl; + // Installed version cout << _(" Installed: "); if (Pkg->CurrentVer == 0) @@ -1622,8 +1637,9 @@ bool Policy(CommandLine &CmdL) return _error->Error(_("Cache is out of sync, can't x-ref a package file")); printf(_(" %4i %s\n"),Plcy.GetPriority(VF.File()), Indx->Describe(true).c_str()); - } - } + } + } + } } return true; diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 7325bbf22..2597a6acb 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -227,6 +227,17 @@ bool ShowList(ostream &out,string Title,string List,string VersionsList) return false; } /*}}}*/ +// ShowPkg - display a package name /*{{{*/ +// --------------------------------------------------------------------- +/* Displays the package name and maybe also the architecture + if it is not the main architecture */ +string ShowPkg(pkgCache::PkgIterator const Pkg) { + string p = Pkg.Name(); + if (_config->Find("APT::Architecture") != Pkg.Arch()) + p.append(":").append(Pkg.Arch()); + return p; +} + /*}}}*/ // ShowBroken - Debugging aide /*{{{*/ // --------------------------------------------------------------------- /* This prints out the names of all the packages that are broken along @@ -258,8 +269,8 @@ void ShowBroken(ostream &out,CacheFile &Cache,bool Now) } // Print out each package and the failed dependencies - out <<" " << I.Name() << ":"; - unsigned Indent = strlen(I.Name()) + 3; + out << " " << ShowPkg(I) << " :"; + unsigned const Indent = ShowPkg(I).size() + 3; bool First = true; pkgCache::VerIterator Ver; @@ -312,7 +323,7 @@ void ShowBroken(ostream &out,CacheFile &Cache,bool Now) out << ' ' << End.DepType() << ": "; FirstOr = false; - out << Start.TargetPkg().Name(); + out << ShowPkg(Start.TargetPkg()); // Show a quick summary of the version requirements if (Start.TargetVer() != 0) @@ -374,7 +385,7 @@ void ShowNew(ostream &out,CacheFile &Cache) { pkgCache::PkgIterator I(Cache,Cache.List[J]); if (Cache[I].NewInstall() == true) { - List += string(I.Name()) + " "; + List += ShowPkg(I) + " "; VersionsList += string(Cache[I].CandVersion) + "\n"; } } @@ -397,9 +408,9 @@ void ShowDel(ostream &out,CacheFile &Cache) if (Cache[I].Delete() == true) { if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge) - List += string(I.Name()) + "* "; + List += ShowPkg(I) + "* "; else - List += string(I.Name()) + " "; + List += ShowPkg(I) + " "; VersionsList += string(Cache[I].CandVersion)+ "\n"; } @@ -424,7 +435,7 @@ void ShowKept(ostream &out,CacheFile &Cache) I->CurrentVer == 0 || Cache[I].Delete() == true) continue; - List += string(I.Name()) + " "; + List += ShowPkg(I) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } ShowList(out,_("The following packages have been kept back:"),List,VersionsList); @@ -445,7 +456,7 @@ void ShowUpgraded(ostream &out,CacheFile &Cache) if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true) continue; - List += string(I.Name()) + " "; + List += ShowPkg(I) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } ShowList(out,_("The following packages will be upgraded:"),List,VersionsList); @@ -466,7 +477,7 @@ bool ShowDowngraded(ostream &out,CacheFile &Cache) if (Cache[I].Downgrade() == false || Cache[I].NewInstall() == true) continue; - List += string(I.Name()) + " "; + List += ShowPkg(I) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } return ShowList(out,_("The following packages will be DOWNGRADED:"),List,VersionsList); @@ -484,7 +495,7 @@ bool ShowHold(ostream &out,CacheFile &Cache) pkgCache::PkgIterator I(Cache,Cache.List[J]); if (Cache[I].InstallVer != (pkgCache::Version *)I.CurrentVer() && I->SelectedState == pkgCache::State::Hold) { - List += string(I.Name()) + " "; + List += ShowPkg(I) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } } @@ -518,7 +529,7 @@ bool ShowEssential(ostream &out,CacheFile &Cache) if (Added[I->ID] == false) { Added[I->ID] = true; - List += string(I.Name()) + " "; + List += ShowPkg(I) + " "; //VersionsList += string(Cache[I].CurVersion) + "\n"; ??? } } -- cgit v1.2.3 From 803ea2a87f81252b2c0d541b8502ed206ce57c84 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Feb 2010 00:04:31 +0100 Subject: Add yet another pseudo package which isn't as pseudo as the others: Arch all packages are now represented by arch depending packages which all depend on a package with the same name and the special arch "all". This packages has NO dependencies, but beside this the same information. It is the only package which has a size, the arch depending ones all have a zero size. While the arch depending pseudo packages are used for dependency resolution the arch "all" package is used for downloading and ordering of the package. --- cmdline/apt-cache.cc | 2 ++ cmdline/apt-get.cc | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index cd806286c..275daa187 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1587,6 +1587,8 @@ bool Policy(CommandLine &CmdL) } for (; Pkg.end() != true; Pkg = Grp.NextPkg(Pkg)) { + if (strcmp(Pkg.Arch(),"all") == 0) + continue; if (myArch == Pkg.Arch()) cout << Pkg.Name() << ":" << endl; diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 2597a6acb..93065004c 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -233,7 +233,7 @@ bool ShowList(ostream &out,string Title,string List,string VersionsList) if it is not the main architecture */ string ShowPkg(pkgCache::PkgIterator const Pkg) { string p = Pkg.Name(); - if (_config->Find("APT::Architecture") != Pkg.Arch()) + if (strcmp(Pkg.Arch(),"all") != 0 && _config->Find("APT::Architecture") != Pkg.Arch()) p.append(":").append(Pkg.Arch()); return p; } @@ -385,6 +385,8 @@ void ShowNew(ostream &out,CacheFile &Cache) { pkgCache::PkgIterator I(Cache,Cache.List[J]); if (Cache[I].NewInstall() == true) { + if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) + continue; List += ShowPkg(I) + " "; VersionsList += string(Cache[I].CandVersion) + "\n"; } @@ -407,6 +409,8 @@ void ShowDel(ostream &out,CacheFile &Cache) pkgCache::PkgIterator I(Cache,Cache.List[J]); if (Cache[I].Delete() == true) { + if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) + continue; if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge) List += ShowPkg(I) + "* "; else @@ -455,7 +459,9 @@ void ShowUpgraded(ostream &out,CacheFile &Cache) // Not interesting if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true) continue; - + if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) + continue; + List += ShowPkg(I) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } @@ -476,7 +482,9 @@ bool ShowDowngraded(ostream &out,CacheFile &Cache) // Not interesting if (Cache[I].Downgrade() == false || Cache[I].NewInstall() == true) continue; - + if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) + continue; + List += ShowPkg(I) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } -- cgit v1.2.3 From 42d71ab5fe58953a680bd300a99d173e23430d7c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Feb 2010 17:17:16 +0100 Subject: In SingleArch environments we don't need the arch "all" pseudo package for handling arch:all packages, so we create only one package and stop calling it a pseudo package. --- cmdline/apt-get.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 93065004c..343226bc3 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -585,6 +585,9 @@ void Stats(ostream &out,pkgDepCache &Dep) unsigned long ReInstall = 0; for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; I++) { + if (pkgCache::VerIterator(Dep, Dep[I].CandidateVer).Pseudo() == true) + continue; + if (Dep[I].NewInstall() == true) Install++; else -- cgit v1.2.3 From af3f8112590edf58cab36e72bca6d5f8e161fbc3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 15 Feb 2010 00:01:36 +0100 Subject: Activate support of :any and stuff in apt-get build-dep as we have now support for MultiArch, so Multi-Arch: allowed packages should already provide package:any --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 5ef5533e2..216383bc6 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2458,7 +2458,7 @@ bool DoBuildDep(CommandLine &CmdL) // Process the build-dependencies vector BuildDeps; - if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only",false)) == false) + if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only",true)) == false) return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str()); // Also ensure that build-essential packages are present -- cgit v1.2.3 From d44b437bd2897bf7fbfbde07a4511c6f7b9ef6a2 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 15 Feb 2010 13:02:27 +0100 Subject: * buildlib/apti18n.h.in, po/makefile: - add ngettext support with P_() --- cmdline/apt-get.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 216383bc6..c8c733716 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1526,10 +1526,9 @@ bool DoAutomaticRemove(CacheFile &Cache) // only show stuff in the list that is not yet marked for removal if(Cache[Pkg].Delete() == false) { + ++autoRemoveCount; // we don't need to fill the strings if we don't need them - if (smallList == true) - ++autoRemoveCount; - else + if (smallList == false) { autoremovelist += string(Pkg.Name()) + " "; autoremoveversions += string(Cache[Pkg].CandVersion) + "\n"; @@ -1542,9 +1541,12 @@ bool DoAutomaticRemove(CacheFile &Cache) if (doAutoRemove == false && (autoremovelist.empty() == false || autoRemoveCount != 0)) { if (smallList == false) - ShowList(c1out, _("The following packages were automatically installed and are no longer required:"), autoremovelist, autoremoveversions); + ShowList(c1out, P_("The following package is automatically installed and is no longer required:", + "The following packages were automatically installed and are no longer required:", + autoRemoveCount), autoremovelist, autoremoveversions); else - ioprintf(c1out, _("%lu packages were automatically installed and are no longer required.\n"), autoRemoveCount); + ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n", + "%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) -- cgit v1.2.3 From a94263ba750c561ecf40241104970bc303cbc0b7 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 25 Feb 2010 19:51:05 +0100 Subject: * cmdline/apt-mark: - don't crash if no arguments are given (Closes: #570962) --- cmdline/apt-mark | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-mark b/cmdline/apt-mark index 2326ece38..f4f6aa576 100755 --- a/cmdline/apt-mark +++ b/cmdline/apt-mark @@ -76,6 +76,10 @@ if __name__ == "__main__": help="print verbose status messages to stdout") (options, args) = parser.parse_args() + if not args: + parser.print_help() + sys.exit(1) + # get the state-file if not options.filename: STATE_FILE = apt_pkg.Config.FindDir("Dir::State") + "extended_states" -- cgit v1.2.3 From 75ce206243e409b170d06723430eb85a4a747882 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 26 Feb 2010 20:47:19 +0100 Subject: move ShowPkg() from apt-get to the PkgIterator and rename it to FullName() responseable for displaying a package name and the architecture in a uniform way. Pretty option can be used to not append the architecture if it is the native architecture or all - and use it all over the place in the commandline tools. --- cmdline/apt-cache.cc | 59 ++++++++++++++++++-------------------- cmdline/apt-get.cc | 80 ++++++++++++++++++++++------------------------------ 2 files changed, 62 insertions(+), 77 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 8323a740e..355e9aefb 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -139,7 +139,7 @@ bool UnMet(CommandLine &CmdL) // Oops, it failed.. if (Header == false) ioprintf(cout,_("Package %s version %s has an unmet dep:\n"), - P.Name(),V.VerStr()); + P.FullName(true).c_str(),V.VerStr()); Header = true; // Print out the dep type @@ -149,7 +149,7 @@ bool UnMet(CommandLine &CmdL) Start = RealStart; do { - cout << Start.TargetPkg().Name(); + cout << Start.TargetPkg().FullName(true); if (Start.TargetVer() != 0) cout << " (" << Start.CompType() << " " << Start.TargetVer() << ")"; @@ -182,7 +182,7 @@ bool DumpPackage(CommandLine &CmdL) continue; } - cout << "Package: " << Pkg.Name() << endl; + cout << "Package: " << Pkg.FullName(true) << endl; cout << "Versions: " << endl; for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++) { @@ -204,7 +204,7 @@ bool DumpPackage(CommandLine &CmdL) cout << "Reverse Depends: " << endl; for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; D++) { - cout << " " << D.ParentPkg().Name() << ',' << D.TargetPkg().Name(); + cout << " " << D.ParentPkg().FullName(true) << ',' << D.TargetPkg().FullName(true); if (D->Version != 0) cout << ' ' << DeNull(D.TargetVer()) << endl; else @@ -216,7 +216,7 @@ bool DumpPackage(CommandLine &CmdL) { cout << Cur.VerStr() << " - "; for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; Dep++) - cout << Dep.TargetPkg().Name() << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") "; + cout << Dep.TargetPkg().FullName(true) << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") "; cout << endl; } @@ -225,12 +225,12 @@ bool DumpPackage(CommandLine &CmdL) { cout << Cur.VerStr() << " - "; for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; Prv++) - cout << Prv.ParentPkg().Name() << " "; + cout << Prv.ParentPkg().FullName(true) << " "; cout << endl; } cout << "Reverse Provides: " << endl; for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++) - cout << Prv.OwnerPkg().Name() << " " << Prv.OwnerVer().VerStr() << endl; + cout << Prv.OwnerPkg().FullName(true) << " " << Prv.OwnerVer().VerStr() << endl; } return true; @@ -353,13 +353,13 @@ bool Dump(CommandLine &Cmd) for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) { - cout << "Package: " << P.Name() << endl; + cout << "Package: " << P.FullName(true) << endl; for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) { cout << " Version: " << V.VerStr() << endl; cout << " File: " << V.FileList().File().FileName() << endl; for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++) - cout << " Depends: " << D.TargetPkg().Name() << ' ' << + cout << " Depends: " << D.TargetPkg().FullName(true) << ' ' << DeNull(D.TargetVer()) << endl; for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; D++) { @@ -570,11 +570,11 @@ bool Depends(CommandLine &CmdL) pkgCache::VerIterator Ver = Pkg.VersionList(); if (Ver.end() == true) { - cout << '<' << Pkg.Name() << '>' << endl; + cout << '<' << Pkg.FullName(true) << '>' << endl; continue; } - cout << Pkg.Name() << endl; + cout << Pkg.FullName(true) << endl; for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) { @@ -596,9 +596,9 @@ bool Depends(CommandLine &CmdL) // Show the package if (Trg->VersionList == 0) - cout << D.DepType() << ": <" << Trg.Name() << ">" << endl; + cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; else - cout << D.DepType() << ": " << Trg.Name() << endl; + cout << D.DepType() << ": " << Trg.FullName(true) << endl; if (Recurse == true) Colours[D.TargetPkg()->ID]++; @@ -614,7 +614,7 @@ bool Depends(CommandLine &CmdL) if (V != Cache.VerP + V.ParentPkg()->VersionList || V->ParentPkg == D->Package) continue; - cout << " " << V.ParentPkg().Name() << endl; + cout << " " << V.ParentPkg().FullName(true) << endl; if (Recurse == true) Colours[D.ParentPkg()->ID]++; @@ -663,11 +663,11 @@ bool RDepends(CommandLine &CmdL) pkgCache::VerIterator Ver = Pkg.VersionList(); if (Ver.end() == true) { - cout << '<' << Pkg.Name() << '>' << endl; + cout << '<' << Pkg.FullName(true) << '>' << endl; continue; } - cout << Pkg.Name() << endl; + cout << Pkg.FullName(true) << endl; cout << "Reverse Depends:" << endl; for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++) @@ -684,9 +684,9 @@ bool RDepends(CommandLine &CmdL) cout << " "; if (Trg->VersionList == 0) - cout << D.DepType() << ": <" << Trg.Name() << ">" << endl; + cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; else - cout << Trg.Name() << endl; + cout << Trg.FullName(true) << endl; if (Recurse == true) Colours[D.ParentPkg()->ID]++; @@ -702,7 +702,7 @@ bool RDepends(CommandLine &CmdL) if (V != Cache.VerP + V.ParentPkg()->VersionList || V->ParentPkg == D->Package) continue; - cout << " " << V.ParentPkg().Name() << endl; + cout << " " << V.ParentPkg().FullName(true) << endl; if (Recurse == true) Colours[D.ParentPkg()->ID]++; @@ -863,7 +863,7 @@ bool XVcg(CommandLine &CmdL) // Only graph critical deps if (D.IsCritical() == true) { - printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg.Name(), D.TargetPkg().Name() ); + printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg.FullName(true).c_str(), D.TargetPkg().FullName(true).c_str() ); // Colour the node for recursion if (Show[D.TargetPkg()->ID] <= DoneNR) @@ -922,10 +922,10 @@ bool XVcg(CommandLine &CmdL) continue; if (Show[Pkg->ID] == DoneNR) - printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg.Name(), Pkg.Name(), + printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg.FullName(true).c_str(), Pkg.FullName(true).c_str(), Shapes[ShapeMap[Pkg->ID]]); else - printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg.Name(), Pkg.Name(), + printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg.FullName(true).c_str(), Pkg.FullName(true).c_str(), Shapes[ShapeMap[Pkg->ID]]); } @@ -1084,7 +1084,7 @@ bool Dotty(CommandLine &CmdL) // Only graph critical deps if (D.IsCritical() == true) { - printf("\"%s\" -> \"%s\"",Pkg.Name(),D.TargetPkg().Name()); + printf("\"%s\" -> \"%s\"",Pkg.FullName(true).c_str(),D.TargetPkg().FullName(true).c_str()); // Colour the node for recursion if (Show[D.TargetPkg()->ID] <= DoneNR) @@ -1138,10 +1138,10 @@ bool Dotty(CommandLine &CmdL) // Orange box for early recursion stoppage if (Show[Pkg->ID] == DoneNR) - printf("\"%s\" [color=orange,shape=%s];\n",Pkg.Name(), + printf("\"%s\" [color=orange,shape=%s];\n",Pkg.FullName(true).c_str(), Shapes[ShapeMap[Pkg->ID]]); else - printf("\"%s\" [shape=%s];\n",Pkg.Name(), + printf("\"%s\" [shape=%s];\n",Pkg.FullName(true).c_str(), Shapes[ShapeMap[Pkg->ID]]); } @@ -1561,7 +1561,7 @@ bool Policy(CommandLine &CmdL) continue; // Print the package name and the version we are forcing to - cout << " " << I.Name() << " -> "; + cout << " " << I.FullName(true) << " -> "; pkgCache::VerIterator V = Plcy.GetMatch(I); if (V.end() == true) @@ -1590,10 +1590,7 @@ bool Policy(CommandLine &CmdL) if (strcmp(Pkg.Arch(),"all") == 0) continue; - if (myArch == Pkg.Arch()) - cout << Pkg.Name() << ":" << endl; - else - cout << Pkg.Name() << ": [" << Pkg.Arch() << "]" << endl; + cout << Pkg.FullName(true) << ":" << endl; // Installed version cout << _(" Installed: "); @@ -1691,7 +1688,7 @@ bool Madison(CommandLine &CmdL) { if ((*IF)->FindInCache(*(VF.File().Cache())) == VF.File()) { - cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | " + cout << setw(10) << Pkg.FullName(true) << " | " << setw(10) << V.VerStr() << " | " << (*IF)->Describe(true) << endl; } } diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index c8c733716..4596c3d61 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -227,17 +227,6 @@ bool ShowList(ostream &out,string Title,string List,string VersionsList) return false; } /*}}}*/ -// ShowPkg - display a package name /*{{{*/ -// --------------------------------------------------------------------- -/* Displays the package name and maybe also the architecture - if it is not the main architecture */ -string ShowPkg(pkgCache::PkgIterator const Pkg) { - string p = Pkg.Name(); - if (strcmp(Pkg.Arch(),"all") != 0 && _config->Find("APT::Architecture") != Pkg.Arch()) - p.append(":").append(Pkg.Arch()); - return p; -} - /*}}}*/ // ShowBroken - Debugging aide /*{{{*/ // --------------------------------------------------------------------- /* This prints out the names of all the packages that are broken along @@ -269,8 +258,8 @@ void ShowBroken(ostream &out,CacheFile &Cache,bool Now) } // Print out each package and the failed dependencies - out << " " << ShowPkg(I) << " :"; - unsigned const Indent = ShowPkg(I).size() + 3; + out << " " << I.FullName(true) << " :"; + unsigned const Indent = I.FullName(true).size() + 3; bool First = true; pkgCache::VerIterator Ver; @@ -323,7 +312,7 @@ void ShowBroken(ostream &out,CacheFile &Cache,bool Now) out << ' ' << End.DepType() << ": "; FirstOr = false; - out << ShowPkg(Start.TargetPkg()); + out << Start.TargetPkg().FullName(true); // Show a quick summary of the version requirements if (Start.TargetVer() != 0) @@ -387,7 +376,7 @@ void ShowNew(ostream &out,CacheFile &Cache) if (Cache[I].NewInstall() == true) { if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) continue; - List += ShowPkg(I) + " "; + List += I.FullName(true) + " "; VersionsList += string(Cache[I].CandVersion) + "\n"; } } @@ -412,9 +401,9 @@ void ShowDel(ostream &out,CacheFile &Cache) if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) continue; if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge) - List += ShowPkg(I) + "* "; + List += I.FullName(true) + "* "; else - List += ShowPkg(I) + " "; + List += I.FullName(true) + " "; VersionsList += string(Cache[I].CandVersion)+ "\n"; } @@ -439,7 +428,7 @@ void ShowKept(ostream &out,CacheFile &Cache) I->CurrentVer == 0 || Cache[I].Delete() == true) continue; - List += ShowPkg(I) + " "; + List += I.FullName(true) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } ShowList(out,_("The following packages have been kept back:"),List,VersionsList); @@ -462,7 +451,7 @@ void ShowUpgraded(ostream &out,CacheFile &Cache) if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) continue; - List += ShowPkg(I) + " "; + List += I.FullName(true) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } ShowList(out,_("The following packages will be upgraded:"),List,VersionsList); @@ -485,7 +474,7 @@ bool ShowDowngraded(ostream &out,CacheFile &Cache) if (Cache[I].CandidateVerIter(Cache).Pseudo() == true) continue; - List += ShowPkg(I) + " "; + List += I.FullName(true) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } return ShowList(out,_("The following packages will be DOWNGRADED:"),List,VersionsList); @@ -503,7 +492,7 @@ bool ShowHold(ostream &out,CacheFile &Cache) pkgCache::PkgIterator I(Cache,Cache.List[J]); if (Cache[I].InstallVer != (pkgCache::Version *)I.CurrentVer() && I->SelectedState == pkgCache::State::Hold) { - List += ShowPkg(I) + " "; + List += I.FullName(true) + " "; VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n"; } } @@ -537,7 +526,7 @@ bool ShowEssential(ostream &out,CacheFile &Cache) if (Added[I->ID] == false) { Added[I->ID] = true; - List += ShowPkg(I) + " "; + List += I.FullName(true) + " "; //VersionsList += string(Cache[I].CurVersion) + "\n"; ??? } } @@ -561,7 +550,7 @@ bool ShowEssential(ostream &out,CacheFile &Cache) Added[P->ID] = true; char S[300]; - snprintf(S,sizeof(S),_("%s (due to %s) "),P.Name(),I.Name()); + snprintf(S,sizeof(S),_("%s (due to %s) "),P.FullName(true).c_str(),I.FullName(true).c_str()); List += S; //VersionsList += "\n"; ??? } @@ -1106,7 +1095,7 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, if (found_one == true) { ioprintf(c1out,_("Note, selecting %s instead of %s\n"), - Prov.Name(),Pkg.Name()); + Prov.FullName(true).c_str(),Pkg.FullName(true).c_str()); Pkg = Prov; } } @@ -1117,7 +1106,7 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, { if (AllowFail == true) ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"), - Pkg.Name()); + Pkg.FullName(true).c_str()); return true; } @@ -1134,7 +1123,7 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, if (AllowFail == false) return false; - ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.Name()); + ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.FullName(true).c_str()); return true; } @@ -1146,7 +1135,7 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, if (Pkg->ProvidesList != 0) { ioprintf(c1out,_("Package %s is a virtual package provided by:\n"), - Pkg.Name()); + Pkg.FullName(true).c_str()); pkgCache::PrvIterator I = Pkg.ProvidesList(); for (; I.end() == false; I++) @@ -1156,10 +1145,10 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) { if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) - c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << + c1out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr() << _(" [Installed]") << endl; else - c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << endl; + c1out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr() << endl; } } c1out << _("You should explicitly select one to install.") << endl; @@ -1169,7 +1158,7 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, 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()); + "is only available from another source\n"),Pkg.FullName(true).c_str()); string List; string VersionsList; @@ -1183,13 +1172,13 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, if (Seen[Dep.ParentPkg()->ID] == true) continue; Seen[Dep.ParentPkg()->ID] = true; - List += string(Dep.ParentPkg().Name()) + " "; + List += Dep.ParentPkg().FullName(true) + " "; //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()); + _error->Error(_("Package %s has no installation candidate"),Pkg.FullName(true).c_str()); return false; } @@ -1210,7 +1199,7 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, { if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false) ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"), - Pkg.Name()); + Pkg.FullName(true).c_str()); else Cache.SetReInstall(Pkg,true); } @@ -1218,7 +1207,7 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, { if (AllowFail == true) ioprintf(c1out,_("%s is already the newest version.\n"), - Pkg.Name()); + Pkg.FullName(true).c_str()); } } else @@ -1247,15 +1236,15 @@ bool TryToChangeVer(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, { if (IsRel == true) return _error->Error(_("Release '%s' for '%s' was not found"), - VerTag,Pkg.Name()); + VerTag,Pkg.FullName(true).c_str()); return _error->Error(_("Version '%s' for '%s' was not found"), - VerTag,Pkg.Name()); + VerTag,Pkg.FullName(true).c_str()); } if (strcmp(VerTag,Ver.VerStr()) != 0) { ioprintf(c1out,_("Selected version %s (%s) for %s\n"), - Ver.VerStr(),Ver.RelStr().c_str(),Pkg.Name()); + Ver.VerStr(),Ver.RelStr().c_str(),Pkg.FullName(true).c_str()); } Cache.SetCandidateVersion(Ver); @@ -1511,7 +1500,7 @@ bool DoAutomaticRemove(CacheFile &Cache) { if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install()) if(Debug) - std::cout << "We could delete %s" << Pkg.Name() << std::endl; + std::cout << "We could delete %s" << Pkg.FullName(true).c_str() << std::endl; if (doAutoRemove) { @@ -1530,7 +1519,7 @@ bool DoAutomaticRemove(CacheFile &Cache) // we don't need to fill the strings if we don't need them if (smallList == false) { - autoremovelist += string(Pkg.Name()) + " "; + autoremovelist += Pkg.FullName(true) + " "; autoremoveversions += string(Cache[Pkg].CandVersion) + "\n"; } } @@ -1804,7 +1793,7 @@ bool DoInstall(CommandLine &CmdL) _config->FindB("APT::Get::Download-Only",false) == false) { ioprintf(c1out,_("%s set to manually installed.\n"), - Pkg.Name()); + Pkg.FullName(true).c_str()); Cache->MarkAuto(Pkg,false); AutoMarkChanged++; } @@ -1873,7 +1862,7 @@ bool DoInstall(CommandLine &CmdL) break; if (*J == 0) { - List += string(I.Name()) + " "; + List += I.FullName(true) + " "; VersionsList += string(Cache[I].CandVersion) + "\n"; } } @@ -1909,7 +1898,7 @@ bool DoInstall(CommandLine &CmdL) for(;;) { /* Skip if package is installed already, or is about to be */ - string target = string(Start.TargetPkg().Name()) + " "; + string target = Start.TargetPkg().FullName(true) + " "; if ((*Start.TargetPkg()).SelectedState == pkgCache::State::Install || Cache[Start.TargetPkg()].Install()) @@ -2559,7 +2548,7 @@ bool DoBuildDep(CommandLine &CmdL) for (; Prv.end() != true; Prv++) { if (_config->FindB("Debug::BuildDeps",false) == true) - cout << " Checking provider " << Prv.OwnerPkg().Name() << endl; + cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl; if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false) break; @@ -2600,7 +2589,7 @@ bool DoBuildDep(CommandLine &CmdL) if (Prv.end() == false) { if (_config->FindB("Debug::BuildDeps",false) == true) - cout << " Is provided by installed package " << Prv.OwnerPkg().Name() << endl; + cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl; skipAlternatives = hasAlternatives; continue; } @@ -2625,7 +2614,7 @@ bool DoBuildDep(CommandLine &CmdL) return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"), Last->BuildDepType((*D).Type), Src.c_str(), - Pkg.Name()); + Pkg.FullName(true).c_str()); } } @@ -2674,7 +2663,6 @@ bool DoBuildDep(CommandLine &CmdL) return true; } /*}}}*/ - // DoMoo - Never Ask, Never Tell /*{{{*/ // --------------------------------------------------------------------- /* */ -- cgit v1.2.3 From 6cd9fbd763298816e5d010703ceb9ffad0c235c9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Mar 2010 10:59:37 +0100 Subject: * cmdline/apt-get.cc: - add a --only-upgrade flag to install command (Closes: #572259) That is NOT what is requested in e.g. #74067 - this is a very simple flag which behaves orthogonal to --no-upgrade not a full-blown upgrade option for a single package instead of the whole package set. --- cmdline/apt-get.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 5a814e255..b35e16b92 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1098,7 +1098,17 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, Pkg.Name()); return true; } - + + // Ignore request for install if package would be new + if (_config->FindB("APT::Get::Only-Upgrade", false) == true && + Pkg->CurrentVer == 0) + { + if (AllowFail == true) + ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\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) @@ -1779,6 +1789,7 @@ bool DoInstall(CommandLine &CmdL) Cache[Pkg].Install() == false && (Cache[Pkg].Flags & pkgCache::Flag::Auto) && _config->FindB("APT::Get::ReInstall",false) == false && + _config->FindB("APT::Get::Only-Upgrade",false) == false && _config->FindB("APT::Get::Download-Only",false) == false) { ioprintf(c1out,_("%s set to manually installed.\n"), @@ -2821,6 +2832,7 @@ int main(int argc,const char *argv[]) /*{{{*/ {0,"fix-missing","APT::Get::Fix-Missing",0}, {0,"ignore-hold","APT::Ignore-Hold",0}, {0,"upgrade","APT::Get::upgrade",0}, + {0,"only-upgrade","APT::Get::Only-Upgrade",0}, {0,"force-yes","APT::Get::force-yes",0}, {0,"print-uris","APT::Get::Print-URIs",0}, {0,"diff-only","APT::Get::Diff-Only",0}, -- cgit v1.2.3 From 3a4477a4241bcfbc9db541cf34cc75c1f1111b78 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Mar 2010 11:08:13 +0100 Subject: * cmdline/apt-get.cc - fix memory leaks in error conditions in DoSource() --- cmdline/apt-get.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index b35e16b92..849401b0c 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2299,6 +2299,7 @@ bool DoSource(CommandLine &CmdL) { for (unsigned I = 0; I != J; I++) ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str()); + delete[] Dsc; return true; } @@ -2309,6 +2310,7 @@ bool DoSource(CommandLine &CmdL) for (; I != Fetcher.UriEnd(); I++) cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; + delete[] Dsc; return true; } @@ -2334,6 +2336,7 @@ bool DoSource(CommandLine &CmdL) if (_config->FindB("APT::Get::Download-only",false) == true) { c1out << _("Download complete and in download only mode") << endl; + delete[] Dsc; return true; } @@ -2395,7 +2398,8 @@ bool DoSource(CommandLine &CmdL) _exit(0); } - + delete[] Dsc; + // Wait for the subprocess int Status = 0; while (waitpid(Process,&Status,0) != Process) -- cgit v1.2.3 From 7a511e5d959f59ec6062a84b3a1ae372ff4f8e86 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 26 Mar 2010 17:25:04 +0100 Subject: * cmdline/apt-get.cc, apt-pkg/cdrom.cc: - fix memory leaks in error conditions in DoSource() --- cmdline/apt-get.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index ea236676b..0bc8fc571 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2315,6 +2315,7 @@ bool DoSource(CommandLine &CmdL) { for (unsigned I = 0; I != J; I++) ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str()); + delete[] Dsc; return true; } @@ -2325,6 +2326,7 @@ bool DoSource(CommandLine &CmdL) for (; I != Fetcher.UriEnd(); I++) cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; + delete[] Dsc; return true; } @@ -2350,6 +2352,7 @@ bool DoSource(CommandLine &CmdL) if (_config->FindB("APT::Get::Download-only",false) == true) { c1out << _("Download complete and in download only mode") << endl; + delete[] Dsc; return true; } @@ -2411,7 +2414,8 @@ bool DoSource(CommandLine &CmdL) _exit(0); } - + delete[] Dsc; + // Wait for the subprocess int Status = 0; while (waitpid(Process,&Status,0) != Process) -- cgit v1.2.3 From e84adb76c87f419ed5bad8f7d08a4132de2bc406 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 30 Mar 2010 17:47:19 +0200 Subject: try version match in FindSrc first exact than fuzzy (LP: #551178) --- cmdline/apt-get.cc | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 7875ae20f..5af2dca04 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1291,12 +1291,26 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, { if(VerTag.empty() == false || DefRel.empty() == false) { + bool fuzzy = false; // we have a default release, try to locate the pkg. we do it like // this because GetCandidateVer() will not "downgrade", that means // "apt-get source -t stable apt" won't work on a unstable system - for (pkgCache::VerIterator Ver = Pkg.VersionList(); - Ver.end() == false; Ver++) + for (pkgCache::VerIterator Ver = Pkg.VersionList();; Ver++) { + // try first only exact matches, later fuzzy matches + if (Ver.end() == true) + { + if (fuzzy == true) + break; + fuzzy = true; + Ver = Pkg.VersionList(); + } + // We match against a concrete version (or a part of this version) + if (VerTag.empty() == false && + (fuzzy == true || Cache.VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match + (fuzzy == false || strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0)) // fuzzy match + continue; + for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; VF++) { @@ -1309,10 +1323,6 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver) continue; - // We match against a concrete version (or a part of this version) - if (VerTag.empty() == false && strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0) - continue; - // or we match against a release if(VerTag.empty() == false || (VF.File().Archive() != 0 && VF.File().Archive() == DefRel) || @@ -1323,10 +1333,9 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, // no SourcePkg name, so it is the "binary" name if (Src.empty() == true) Src = TmpSrc; - // no Version, so we try the Version of the SourcePkg - - // and after that the version of the binary package - if (VerTag.empty() == true) - VerTag = Parse.SourceVer(); + // the Version we have is possibly fuzzy or includes binUploads, + // so we use the Version of the SourcePkg (empty if same as package) + VerTag = Parse.SourceVer(); if (VerTag.empty() == true) VerTag = Ver.VerStr(); break; @@ -1390,7 +1399,8 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, const string Ver = Parse->Version(); // Ignore all versions which doesn't fit - if (VerTag.empty() == false && strncmp(VerTag.c_str(), Ver.c_str(), VerTag.size()) != 0) + if (VerTag.empty() == false && + Cache.VS().CmpVersion(VerTag, Ver) != 0) // exact match continue; // Newer version or an exact match? Save the hit -- cgit v1.2.3 From a4787a959bbed2e16f6017c8e3238ae9cf98bc69 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 31 Mar 2010 22:00:36 +0200 Subject: cherry pick -r 1983..1984 lp:~donkult/apt/sid --- cmdline/apt-get.cc | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 0bc8fc571..5de3fb036 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1270,12 +1270,26 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, { if(VerTag.empty() == false || DefRel.empty() == false) { + bool fuzzy = false; // we have a default release, try to locate the pkg. we do it like // this because GetCandidateVer() will not "downgrade", that means // "apt-get source -t stable apt" won't work on a unstable system - for (pkgCache::VerIterator Ver = Pkg.VersionList(); - Ver.end() == false; Ver++) + for (pkgCache::VerIterator Ver = Pkg.VersionList();; Ver++) { + // try first only exact matches, later fuzzy matches + if (Ver.end() == true) + { + if (fuzzy == true) + break; + fuzzy = true; + Ver = Pkg.VersionList(); + } + // We match against a concrete version (or a part of this version) + if (VerTag.empty() == false && + (fuzzy == true || Cache.VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match + (fuzzy == false || strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0)) // fuzzy match + continue; + for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; VF++) { @@ -1288,10 +1302,6 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver) continue; - // We match against a concrete version (or a part of this version) - if (VerTag.empty() == false && strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0) - continue; - // or we match against a release if(VerTag.empty() == false || (VF.File().Archive() != 0 && VF.File().Archive() == DefRel) || @@ -1302,10 +1312,9 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, // no SourcePkg name, so it is the "binary" name if (Src.empty() == true) Src = TmpSrc; - // no Version, so we try the Version of the SourcePkg - - // and after that the version of the binary package - if (VerTag.empty() == true) - VerTag = Parse.SourceVer(); + // the Version we have is possibly fuzzy or includes binUploads, + // so we use the Version of the SourcePkg (empty if same as package) + VerTag = Parse.SourceVer(); if (VerTag.empty() == true) VerTag = Ver.VerStr(); break; @@ -1371,7 +1380,8 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, const string Ver = Parse->Version(); // Ignore all versions which doesn't fit - if (VerTag.empty() == false && strncmp(VerTag.c_str(), Ver.c_str(), VerTag.size()) != 0) + if (VerTag.empty() == false && + Cache.VS().CmpVersion(VerTag, Ver) != 0) // exact match continue; // Newer version or an exact match? Save the hit -- cgit v1.2.3 From 1cd1c398d18b78f4aa9d882a5de5385f4538e0be Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 7 Apr 2010 16:38:18 +0200 Subject: * apt-pkg/contrib/fileutl.cc: - add a parent-guarded "mkdir -p" as CreateDirectory() * apt-pkg/acquire.{cc,h}: - add a delayed constructor with Setup() for success reporting - check for and create directories in Setup if needed instead of error out unfriendly in the Constructor (Closes: #523920, #525783) - optional handle a lock file in Setup() * cmdline/apt-get.cc: - remove the lock file handling and let Acquire take care of it instead --- cmdline/apt-get.cc | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 62f712c39..416d316da 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -811,20 +811,13 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, pkgRecords Recs(Cache); if (_error->PendingError() == true) return false; - - // Lock the archive directory - FileFd Lock; - if (_config->FindB("Debug::NoLocking",false) == false && - _config->FindB("APT::Get::Print-URIs") == false) - { - Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock")); - if (_error->PendingError() == true) - return _error->Error(_("Unable to lock the download directory")); - } - + // Create the download object + pkgAcquire Fetcher; AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); - pkgAcquire Fetcher(&Stat); + if (Fetcher.Setup(&Stat, _config->FindB("APT::Get::Print-URIs", false) + ? "" : _config->FindDir("Dir::Cache::Archives")) == false) + return false; // Read the source list pkgSourceList List; @@ -1442,15 +1435,6 @@ bool DoUpdate(CommandLine &CmdL) 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 progress AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); @@ -1458,7 +1442,9 @@ bool DoUpdate(CommandLine &CmdL) if (_config->FindB("APT::Get::Print-URIs") == true) { // get a fetcher - pkgAcquire Fetcher(&Stat); + pkgAcquire Fetcher; + if (Fetcher.Setup(&Stat) == false) + return false; // Populate it with the source selection and get all Indexes // (GetAll=true) @@ -2207,7 +2193,9 @@ bool DoSource(CommandLine &CmdL) // Create the download object AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); - pkgAcquire Fetcher(&Stat); + pkgAcquire Fetcher; + if (Fetcher.Setup(&Stat) == false) + return false; DscFile *Dsc = new DscFile[CmdL.FileSize()]; @@ -2464,7 +2452,9 @@ bool DoBuildDep(CommandLine &CmdL) // Create the download object AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); - pkgAcquire Fetcher(&Stat); + pkgAcquire Fetcher; + if (Fetcher.Setup(&Stat) == false) + return false; unsigned J = 0; for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) -- cgit v1.2.3 From 259f688a29728604d7930662e9743619982706ab Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 8 Apr 2010 20:57:01 +0200 Subject: * cmdline/apt-get.cc: - fix crash when pkg.VersionList() is empty --- cmdline/apt-get.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 62f712c39..cd450b27a 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1304,6 +1304,10 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, break; fuzzy = true; Ver = Pkg.VersionList(); + // exit right away from the Pkg.VersionList() loop if we + // don't have any versions + if (Ver.end() == true) + break; } // We match against a concrete version (or a part of this version) if (VerTag.empty() == false && -- cgit v1.2.3 From b1fd12d41f9be5d5f33e4768761ed28f87953082 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 8 Apr 2010 21:14:03 +0200 Subject: * cmdline/apt-get.cc: - fix crash when pkg.VersionList() is empty (LP: #556056) --- cmdline/apt-get.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 5de3fb036..b379dc82f 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1283,6 +1283,10 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, break; fuzzy = true; Ver = Pkg.VersionList(); + // exit right away from the Pkg.VersionList() loop if we + // don't have any versions + if (Ver.end() == true) + break; } // We match against a concrete version (or a part of this version) if (VerTag.empty() == false && -- cgit v1.2.3 From a722b2c5c935768efbdd5b23eed7ce32ccd60908 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 9 Apr 2010 15:38:48 +0200 Subject: * apt-pkg/acquire-item.cc: - Acquire::ForceHash to force method for expected hash - display MD5Sum in --print-uris if not forced to use another method instead of displaying the strongest available (Closes: #576420) --- cmdline/apt-get.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 416d316da..7c42e672d 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -815,8 +815,14 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, // Create the download object pkgAcquire Fetcher; AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); - if (Fetcher.Setup(&Stat, _config->FindB("APT::Get::Print-URIs", false) - ? "" : _config->FindDir("Dir::Cache::Archives")) == false) + if (_config->FindB("APT::Get::Print-URIs", false) == 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; // Read the source list @@ -1441,6 +1447,9 @@ bool DoUpdate(CommandLine &CmdL) // Just print out the uris an exit if the --print-uris flag was used if (_config->FindB("APT::Get::Print-URIs") == true) { + // force a hashsum for compatibility reasons + _config->CndSet("Acquire::ForceHash", "md5sum"); + // get a fetcher pkgAcquire Fetcher; if (Fetcher.Setup(&Stat) == false) -- cgit v1.2.3 From 3d5a34b22a83eb4bf9b1407e13240b8e2a333d5f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 13 Apr 2010 09:28:57 +0200 Subject: regex for package names executed on Grp- not PkgIterator --- cmdline/apt-get.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 7c42e672d..52cbce945 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1772,11 +1772,14 @@ bool DoInstall(CommandLine &CmdL) // Run over the matches bool Hit = false; - for (Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) { - if (regexec(&Pattern,Pkg.Name(),0,0,0) != 0) + if (regexec(&Pattern,Grp.Name(),0,0,0) != 0) continue; - + Pkg = Grp.FindPkg("native"); + if (unlikely(Pkg.end() == true)) + continue; + ioprintf(c1out,_("Note, selecting %s for regex '%s'\n"), Pkg.Name(),S); -- cgit v1.2.3 From b564740226100331f1aba8a1e35a57e5483361f7 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 21 Apr 2010 13:14:40 +0200 Subject: replace backticks with single quote in broken packages message. Thanks to Jari Aalto for spotting & patching! (Closes: #577168) --- cmdline/apt-get.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 52cbce945..9d67a82f8 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -692,7 +692,7 @@ bool CacheFile::CheckDeps(bool AllowBroken) } else { - c1out << _("You might want to run `apt-get -f install' to correct these.") << endl; + c1out << _("You might want to run 'apt-get -f install' to correct these.") << endl; ShowBroken(c1out,*this,true); return _error->Error(_("Unmet dependencies. Try using -f.")); @@ -1826,7 +1826,7 @@ bool DoInstall(CommandLine &CmdL) packages */ if (BrokenFix == true && Cache->BrokenCount() != 0) { - c1out << _("You might want to run `apt-get -f install' to correct these:") << endl; + c1out << _("You might want to run 'apt-get -f install' to correct these:") << endl; ShowBroken(c1out,Cache,false); return _error->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).")); -- cgit v1.2.3 From ca964703dd3442724c0ccac0ade717042ca8fce5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 23 Apr 2010 17:19:57 +0200 Subject: * cmdline/apt-cache.cc: - align Installed and Candidate Version in policy so they can be compared easier, thanks Ralf Gesellensetter for the pointer! (Closes: #578657) --- cmdline/apt-cache.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 07b95e3ca..b0034bf6d 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1585,6 +1585,14 @@ bool Policy(CommandLine &CmdL) } string const myArch = _config->Find("APT::Architecture"); + char const * const msgInstalled = _(" Installed: "); + char const * const msgCandidate = _(" Candidate: "); + short const InstalledLessCandidate = + mbstowcs(NULL, msgInstalled, 0) - mbstowcs(NULL, msgCandidate, 0); + short const deepInstalled = + (InstalledLessCandidate < 0 ? (InstalledLessCandidate*-1) : 0) - 1; + short const deepCandidate = + (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; // Print out detailed information for each package for (const char **I = CmdL.FileList + 1; *I != 0; I++) @@ -1604,14 +1612,14 @@ bool Policy(CommandLine &CmdL) cout << Pkg.FullName(true) << ":" << endl; // Installed version - cout << _(" Installed: "); + cout << msgInstalled << OutputInDepth(deepInstalled, " "); if (Pkg->CurrentVer == 0) cout << _("(none)") << endl; else cout << Pkg.CurrentVer().VerStr() << endl; // Candidate Version - cout << _(" Candidate: "); + cout << msgCandidate << OutputInDepth(deepCandidate, " "); pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg); if (V.end() == true) cout << _("(none)") << endl; -- cgit v1.2.3 From 3b796dfc90d6ca9d42077bddd38665b0b93a2266 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 24 Apr 2010 10:49:48 +0200 Subject: show non-candidates as fallback for virtual packages (Closes: #578385) --- cmdline/apt-get.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 9d67a82f8..672f64c68 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1147,20 +1147,27 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, Pkg.FullName(true).c_str()); pkgCache::PrvIterator I = Pkg.ProvidesList(); + unsigned short provider = 0; for (; I.end() == false; I++) { pkgCache::PkgIterator Pkg = I.OwnerPkg(); if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) { + c1out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr(); if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) - c1out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr() << - _(" [Installed]") << endl; - else - c1out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr() << endl; - } + c1out << _(" [Installed]"); + c1out << endl; + ++provider; + } } - c1out << _("You should explicitly select one to install.") << endl; + // if we found no candidate which provide this package, show non-candidates + if (provider == 0) + for (I = Pkg.ProvidesList(); I.end() == false; I++) + c1out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr() + << _(" [Not candidate version]") << endl; + else + c1out << _("You should explicitly select one to install.") << endl; } else { -- cgit v1.2.3 From 08bd372d9dd5e4a56176ec08bf6e7870ecd41b32 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 24 Apr 2010 13:15:33 +0200 Subject: set also "all" to this version for pseudo packages in TryToChangeVer --- cmdline/apt-get.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 672f64c68..b43164c2f 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1264,6 +1264,11 @@ bool TryToChangeVer(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, } Cache.SetCandidateVersion(Ver); + + // Set the all package to the same candidate + if (Ver.Pseudo() == true) + Cache.SetCandidateVersion(Match.Find(Pkg.Group().FindPkg("all"))); + return true; } /*}}}*/ -- cgit v1.2.3 From 173ae2a460b905b18911f42964fd38dbac2959d6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 4 May 2010 12:54:52 +0200 Subject: use GroupCount for package names in stats and add a package struct line --- cmdline/apt-cache.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index b0034bf6d..b981e2fa7 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -242,7 +242,9 @@ bool DumpPackage(CommandLine &CmdL) bool Stats(CommandLine &Cmd) { pkgCache &Cache = *GCache; - cout << _("Total package names: ") << Cache.Head().PackageCount << " (" << + cout << _("Total package names: ") << Cache.Head().GroupCount << " (" << + SizeToStr(Cache.Head().GroupCount*Cache.Head().GroupSz) << ')' << endl + << _("Total package structures: ") << Cache.Head().PackageCount << " (" << SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl; int Normal = 0; -- cgit v1.2.3 From d63a1458427692a6f98274e76020e0f803408d81 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 4 May 2010 17:52:36 +0200 Subject: cmdline/apt-get.cc: Add apt-get markauto, showauto and unmarkauto commands. --- cmdline/apt-get.cc | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ cmdline/apt-mark | 3 ++- 2 files changed, 62 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 26c731978..8f9faf158 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2013,6 +2013,60 @@ bool DoInstall(CommandLine &CmdL) return InstallPackages(Cache,false); } + +/* show automatically installed packages. */ +bool DoShowAuto(CommandLine &CmdL) +{ + OpProgress progress; + pkgCacheFile Cache; + if (Cache.Open(progress, false) == false) + return false; + + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) + if (Cache[P].Flags & pkgCache::Flag::Auto) + ioprintf(c1out,_("%s\n"), P.Name()); + return true; +} + +/* mark packages as automatically/manually installed. */ +bool DoMarkAuto(CommandLine &CmdL) +{ + bool Action = true; + int AutoMarkChanged = 0; + OpTextProgress progress; + CacheFile Cache; + if (Cache.Open() == false) + return false; + + if (strcasecmp(CmdL.FileList[0],"markauto") == 0) + Action = true; + else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0) + Action = false; + + for (const char **I = CmdL.FileList + 1; *I != 0; I++) + { + const char *S = *I; + // Locate the package + pkgCache::PkgIterator Pkg = Cache->FindPkg(S); + if (Pkg.end() == true) { + return _error->Error(_("Couldn't find package %s"),S); + } + else + { + if (!Action) + ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name()); + else + ioprintf(c1out,_("%s set to automatically installed.\n"), + Pkg.Name()); + + Cache->MarkAuto(Pkg,Action); + AutoMarkChanged++; + } + } + if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false)) + return Cache->writeStateFile(NULL); + return false; +} /*}}}*/ // DoDistUpgrade - Automatic smart upgrader /*{{{*/ // --------------------------------------------------------------------- @@ -2798,6 +2852,9 @@ bool ShowHelp(CommandLine &CmdL) " clean - Erase downloaded archive files\n" " autoclean - Erase old downloaded archive files\n" " check - Verify that there are no broken dependencies\n" + " markauto - Mark the given packages as automatically installed\n" + " unmarkauto - Mark the given packages as manually installed\n" + " showauto - Display a list of automatically installed packages\n" "\n" "Options:\n" " -h This help text.\n" @@ -2904,6 +2961,9 @@ int main(int argc,const char *argv[]) /*{{{*/ {"purge",&DoInstall}, {"autoremove",&DoInstall}, {"purge",&DoInstall}, + {"showauto",&DoShowAuto}, + {"markauto",&DoMarkAuto}, + {"unmarkauto",&DoMarkAuto}, {"dist-upgrade",&DoDistUpgrade}, {"dselect-upgrade",&DoDSelectUpgrade}, {"build-dep",&DoBuildDep}, diff --git a/cmdline/apt-mark b/cmdline/apt-mark index 12768b708..c64d4356c 100755 --- a/cmdline/apt-mark +++ b/cmdline/apt-mark @@ -8,7 +8,7 @@ import os.path try: import apt_pkg except ImportError: - print "Error importing apt_pkg, is python-apt installed?" + print >> sys.stderr, "Error importing apt_pkg, is python-apt installed?" sys.exit(1) actions = { "markauto" : 1, @@ -68,6 +68,7 @@ if __name__ == "__main__": # option parsing parser = OptionParser() parser.usage = "%prog [options] {markauto|unmarkauto} packages..." + parser.epilog = "apt-mark is deprecated, use apt-get markauto/unmarkauto." parser.add_option("-f", "--file", action="store", type="string", dest="filename", help="read/write a different file") -- cgit v1.2.3 From 827d04d3b2ed62d4e666698e639af6fbb3199581 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 4 May 2010 19:44:37 +0200 Subject: rerun dpkg-source in source if --fix-broken is given (Closes: #576752) --- cmdline/apt-get.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index b43164c2f..6a3c91a59 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2380,6 +2380,7 @@ bool DoSource(CommandLine &CmdL) if (Process == 0) { + bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false); for (unsigned I = 0; I != J; I++) { string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str()); @@ -2392,7 +2393,7 @@ bool DoSource(CommandLine &CmdL) // See if the package is already unpacked struct stat Stat; - if (stat(Dir.c_str(),&Stat) == 0 && + if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 && S_ISDIR(Stat.st_mode) != 0) { ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"), -- cgit v1.2.3 From 6007c1d41d5aae7ae22fee89824175f925b9e680 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 4 May 2010 21:28:24 +0200 Subject: Move the showauto command to apt-cache and sort output. * cmdline/apt-cache.cc: - Add a showauto command to apt-cache. - Add apt-get markauto and unmarkauto commands. --- cmdline/apt-cache.cc | 27 +++++++++++++++++++++++++++ cmdline/apt-get.cc | 16 ---------------- 2 files changed, 27 insertions(+), 16 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index b981e2fa7..10dbf44d2 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -14,7 +14,9 @@ /*}}}*/ // Include Files /*{{{*/ #include +#include #include +#include #include #include #include @@ -1406,6 +1408,29 @@ bool Search(CommandLine &CmdL) return _error->Error("Write to stdout failed"); return true; } + + +/* show automatically installed packages (sorted) */ +bool ShowAuto(CommandLine &CmdL) +{ + OpProgress op; + pkgDepCache DepCache(GCache); + DepCache.Init(&op); + + std::vector packages; + packages.reserve(GCache->HeaderP->PackageCount / 3); + + for (pkgCache::PkgIterator P = GCache->PkgBegin(); P.end() == false; P++) + if (DepCache[P].Flags & pkgCache::Flag::Auto) + packages.push_back(P.Name()); + + std::sort(packages.begin(), packages.end()); + + for (vector::iterator I = packages.begin(); I != packages.end(); I++) + cout << *I << "\n"; + + return true; +} /*}}}*/ // ShowPackage - Dump the package record to the screen /*{{{*/ // --------------------------------------------------------------------- @@ -1777,6 +1802,7 @@ bool ShowHelp(CommandLine &Cmd) " unmet - Show unmet dependencies\n" " search - Search the package list for a regex pattern\n" " show - Show a readable record for the package\n" + " showauto - Display a list of automatically installed packages\n" " depends - Show raw dependency information for a package\n" " rdepends - Show reverse dependency information for a package\n" " pkgnames - List the names of all packages in the system\n" @@ -1841,6 +1867,7 @@ int main(int argc,const char *argv[]) /*{{{*/ {"xvcg",&XVcg}, {"show",&ShowPackage}, {"pkgnames",&ShowPkgNames}, + {"showauto",&ShowAuto}, {"policy",&Policy}, {"madison",&Madison}, {0,0}}; diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 8f9faf158..03239dabe 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2014,20 +2014,6 @@ bool DoInstall(CommandLine &CmdL) return InstallPackages(Cache,false); } -/* show automatically installed packages. */ -bool DoShowAuto(CommandLine &CmdL) -{ - OpProgress progress; - pkgCacheFile Cache; - if (Cache.Open(progress, false) == false) - return false; - - for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) - if (Cache[P].Flags & pkgCache::Flag::Auto) - ioprintf(c1out,_("%s\n"), P.Name()); - return true; -} - /* mark packages as automatically/manually installed. */ bool DoMarkAuto(CommandLine &CmdL) { @@ -2854,7 +2840,6 @@ bool ShowHelp(CommandLine &CmdL) " check - Verify that there are no broken dependencies\n" " markauto - Mark the given packages as automatically installed\n" " unmarkauto - Mark the given packages as manually installed\n" - " showauto - Display a list of automatically installed packages\n" "\n" "Options:\n" " -h This help text.\n" @@ -2961,7 +2946,6 @@ int main(int argc,const char *argv[]) /*{{{*/ {"purge",&DoInstall}, {"autoremove",&DoInstall}, {"purge",&DoInstall}, - {"showauto",&DoShowAuto}, {"markauto",&DoMarkAuto}, {"unmarkauto",&DoMarkAuto}, {"dist-upgrade",&DoDistUpgrade}, -- cgit v1.2.3 From 2d847a5919828ab26dd3f3c5993497b95df9051b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 6 May 2010 12:31:55 +0200 Subject: don't suggest held packages as they are installed (Closes: #578135) --- cmdline/apt-get.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 6a3c91a59..de8c7aeaf 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1932,9 +1932,10 @@ bool DoInstall(CommandLine &CmdL) { /* Skip if package is installed already, or is about to be */ string target = Start.TargetPkg().FullName(true) + " "; - - if ((*Start.TargetPkg()).SelectedState == pkgCache::State::Install - || Cache[Start.TargetPkg()].Install()) + pkgCache::PkgIterator const TarPkg = Start.TargetPkg(); + if (TarPkg->SelectedState == pkgCache::State::Install || + TarPkg->SelectedState == pkgCache::State::Hold || + Cache[Start.TargetPkg()].Install()) { foundInstalledInOrGroup=true; break; -- cgit v1.2.3 From 8545b536e3459a06fa007e2c307a77188e5de4b1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 14 May 2010 12:12:23 +0200 Subject: handle multiple --{tar,diff,dsc}-only options correctly --- cmdline/apt-get.cc | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 00da0855f..dd5ef1743 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2271,6 +2271,14 @@ bool DoSource(CommandLine &CmdL) // insert all downloaded uris into this set to avoid downloading them // twice set queued; + + // Diff only mode only fetches .diff files + bool const diffOnly = _config->FindB("APT::Get::Diff-Only", false); + // Tar only mode only fetches .tar files + bool const tarOnly = _config->FindB("APT::Get::Tar-Only", false); + // Dsc only mode only fetches .dsc files + bool const dscOnly = _config->FindB("APT::Get::Dsc-Only", false); + // Load the requestd sources into the fetcher unsigned J = 0; for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) @@ -2297,21 +2305,17 @@ bool DoSource(CommandLine &CmdL) Dsc[J].Version = Last->Version(); Dsc[J].Dsc = flNotDir(I->Path); } - - // Diff only mode only fetches .diff files - if (_config->FindB("APT::Get::Diff-Only",false) == true && - I->Type != "diff") - continue; - - // Tar only mode only fetches .tar files - if (_config->FindB("APT::Get::Tar-Only",false) == true && - I->Type != "tar") - continue; - // Dsc only mode only fetches .dsc files - if (_config->FindB("APT::Get::Dsc-Only",false) == true && - I->Type != "dsc") - continue; + // Handle the only options so that multiple can be used at once + if (diffOnly == true || tarOnly == true || dscOnly == true) + { + if ((diffOnly == true && I->Type == "diff") || + (tarOnly == true && I->Type == "tar") || + (dscOnly == true && I->Type == "dsc")) + ; // Fine, we want this file downloaded + else + continue; + } // don't download the same uri twice (should this be moved to // the fetcher interface itself?) -- cgit v1.2.3 From 642ebc1a04c9c7915474c57f1143a9389ee6636a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 24 May 2010 20:10:11 +0200 Subject: - show at the end of the install process a list of disappeared packages * apt-pkg/packagemanager.h: - export info about disappeared packages with GetDisappearedPackages() --- cmdline/apt-get.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index dd5ef1743..44235e358 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1044,7 +1044,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, if (Res == pkgPackageManager::Failed || _error->PendingError() == true) return false; if (Res == pkgPackageManager::Completed) - return true; + break; // Reload the fetcher object and loop again for media swapping Fetcher.Shutdown(); @@ -1052,7 +1052,24 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, return false; _system->Lock(); - } + } + + std::set const disappearedPkgs = PM->GetDisappearedPackages(); + if (disappearedPkgs.empty() == true) + return true; + + string disappear; + for (std::set::const_iterator d = disappearedPkgs.begin(); + d != disappearedPkgs.end(); ++d) + disappear.append(*d).append(" "); + + ShowList(c1out, P_("The following package disappeared from your system as\n" + "all files have been overwritten by other packages:", + "The following packages disappeared from your system as\n" + "all files have been overwritten by other packages:", disappearedPkgs.size()), disappear, ""); + c0out << _("Note: This is done automatic and on purpose by dpkg.") << std::endl; + + return true; } /*}}}*/ // TryToInstall - Try to install a single package /*{{{*/ -- cgit v1.2.3 From ffee1c2bed4accfe25b2ac9e9f0ab9a0ebae9b5b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 30 May 2010 23:12:41 +0200 Subject: move regex magic from apt-get to new FromRegEx method --- cmdline/apt-get.cc | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 44235e358..1cffd6730 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -40,7 +40,8 @@ #include #include #include - +#include + #include #include @@ -1780,51 +1781,24 @@ bool DoInstall(CommandLine &CmdL) Packages++; if (Pkg.end() == true) { - // Check if the name is a regex - const char *I; - for (I = S; *I != 0; I++) - if (*I == '?' || *I == '*' || *I == '|' || - *I == '[' || *I == '^' || *I == '$') - break; - if (*I == 0) + APT::PackageSet pkgset = APT::PackageSet::FromRegEx(Cache, S, c1out); + if (pkgset.empty() == true) return _error->Error(_("Couldn't find package %s"),S); // Regexs must always be confirmed ExpectedInst += 1000; - - // Compile the regex pattern - regex_t Pattern; - int Res; - if ((Res = regcomp(&Pattern,S,REG_EXTENDED | REG_ICASE | - REG_NOSUB)) != 0) - { - char Error[300]; - regerror(Res,&Pattern,Error,sizeof(Error)); - return _error->Error(_("Regex compilation error - %s"),Error); - } - - // Run over the matches + bool Hit = false; - for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { - if (regexec(&Pattern,Grp.Name(),0,0,0) != 0) - continue; - Pkg = Grp.FindPkg("native"); - if (unlikely(Pkg.end() == true)) - continue; - - ioprintf(c1out,_("Note, selecting %s for regex '%s'\n"), - Pkg.Name(),S); - if (VerTag != 0) if (TryToChangeVer(Pkg,Cache,VerTag,VerIsRel) == false) return false; - + Hit |= TryToInstall(Pkg,Cache,Fix,Remove,BrokenFix, ExpectedInst,false); } - regfree(&Pattern); - + if (Hit == false) return _error->Error(_("Couldn't find package %s"),S); } -- cgit v1.2.3 From 78c325968642255fd2325003f19729b617477666 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 00:28:14 +0200 Subject: move cmdline parsing from apt-cache to new FromCommandLine method --- cmdline/apt-cache.cc | 80 ++++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 59 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 10dbf44d2..95f185b4f 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -175,15 +176,10 @@ bool UnMet(CommandLine &CmdL) bool DumpPackage(CommandLine &CmdL) { pkgCache &Cache = *GCache; - for (const char **I = CmdL.FileList + 1; *I != 0; I++) - { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + { cout << "Package: " << Pkg.FullName(true) << endl; cout << "Versions: " << endl; for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++) @@ -545,18 +541,11 @@ bool Depends(CommandLine &CmdL) pkgCache &Cache = *GCache; SPtrArray Colours = new unsigned[Cache.Head().PackageCount]; memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); - - for (const char **I = CmdL.FileList + 1; *I != 0; I++) - { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } + + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; - } - + bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); bool Installed = _config->FindB("APT::Cache::Installed",false); bool Important = _config->FindB("APT::Cache::Important",false); @@ -639,18 +628,11 @@ bool RDepends(CommandLine &CmdL) pkgCache &Cache = *GCache; SPtrArray Colours = new unsigned[Cache.Head().PackageCount]; memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); - - for (const char **I = CmdL.FileList + 1; *I != 0; I++) - { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } + + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; - } - + bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); bool Installed = _config->FindB("APT::Cache::Installed",false); bool DidSomething; @@ -1440,23 +1422,9 @@ bool ShowPackage(CommandLine &CmdL) pkgCache &Cache = *GCache; pkgDepCache::Policy Plcy; - unsigned found = 0; - - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { - // FIXME: Handle the case in which pkgname name:arch is not found - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == true) - { - Pkg = Cache.FindPkg(*I, "any"); - if (Pkg.end() == true) { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } - } - - ++found; - // Find the proper version to use. if (_config->FindB("APT::Cache::AllVersions","true") == true) { @@ -1477,7 +1445,7 @@ bool ShowPackage(CommandLine &CmdL) } } - if (found > 0) + if (pkgset.empty() == false) return true; return _error->Error(_("No packages found")); } @@ -1622,15 +1590,10 @@ bool Policy(CommandLine &CmdL) (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; // Print out detailed information for each package - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator I = pkgset.begin(); I != pkgset.end(); ++I) { - pkgCache::GrpIterator Grp = Cache.FindGrp(*I); - pkgCache::PkgIterator Pkg = Grp.FindPkg("any"); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } + pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); for (; Pkg.end() != true; Pkg = Grp.NextPkg(Pkg)) { if (strcmp(Pkg.Arch(),"all") == 0) @@ -1708,10 +1671,9 @@ bool Madison(CommandLine &CmdL) if (_error->PendingError() == true) _error->Discard(); - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { - pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); - if (Pkg.end() == false) { for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; V++) @@ -1746,7 +1708,7 @@ bool Madison(CommandLine &CmdL) SrcRecs.Restart(); pkgSrcRecords::Parser *SrcParser; - while ((SrcParser = SrcRecs.Find(*I,false)) != 0) + while ((SrcParser = SrcRecs.Find(Pkg.Name(),false)) != 0) { // Maybe support Release info here too eventually cout << setw(10) << SrcParser->Package() << " | " -- cgit v1.2.3 From 4c265635a8417b857a3a8f537c74313d5533da9b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 12:58:20 +0200 Subject: =?UTF-8?q?i=20managed=20to=20commit=20broken=20code=E2=80=A6=20wh?= =?UTF-8?q?ich=20(at=20least=20in=20my=20mind)=20worked=20yesterday.=20Str?= =?UTF-8?q?ange=E2=80=A6=20anyway=20only=20small=20fixes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmdline/apt-cache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 95f185b4f..943a001a8 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1595,7 +1595,7 @@ bool Policy(CommandLine &CmdL) { pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); - for (; Pkg.end() != true; Pkg = Grp.NextPkg(Pkg)) { + for (; Pkg.end() != true; Pkg = I.Group().NextPkg(Pkg)) { if (strcmp(Pkg.Arch(),"all") == 0) continue; -- cgit v1.2.3 From d5cc17d6c2ba4e29e800e489d5f3b3cf4a405543 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 20:02:41 +0200 Subject: * cmdline/apt-cache.cc: - make the search multiarch compatible by using GrpIterator instead --- cmdline/apt-cache.cc | 77 +++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 37 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 943a001a8..d8e14617a 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1272,15 +1272,15 @@ struct ExDescFile bool Search(CommandLine &CmdL) { pkgCache &Cache = *GCache; - bool ShowFull = _config->FindB("APT::Cache::ShowFull",false); - bool NamesOnly = _config->FindB("APT::Cache::NamesOnly",false); - unsigned NumPatterns = CmdL.FileSize() -1; + bool const ShowFull = _config->FindB("APT::Cache::ShowFull",false); + bool const NamesOnly = _config->FindB("APT::Cache::NamesOnly",false); + unsigned int const NumPatterns = CmdL.FileSize() -1; pkgDepCache::Policy Plcy; // Make sure there is at least one argument if (NumPatterns < 1) - return _error->Error(_("You must give exactly one pattern")); + return _error->Error(_("You must give at least one search pattern")); // Compile the regex pattern regex_t *Patterns = new regex_t[NumPatterns]; @@ -1296,8 +1296,6 @@ bool Search(CommandLine &CmdL) } } - // Create the text record parser - pkgRecords Recs(Cache); if (_error->PendingError() == true) { for (unsigned I = 0; I != NumPatterns; I++) @@ -1305,70 +1303,75 @@ bool Search(CommandLine &CmdL) return false; } - ExDescFile *DFList = new ExDescFile[Cache.HeaderP->PackageCount+1]; - memset(DFList,0,sizeof(*DFList)*Cache.HeaderP->PackageCount+1); + ExDescFile *DFList = new ExDescFile[Cache.HeaderP->GroupCount+1]; + memset(DFList,0,sizeof(*DFList)*Cache.HeaderP->GroupCount+1); // Map versions that we want to write out onto the VerList array. - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + for (pkgCache::GrpIterator G = Cache.GrpBegin(); G.end() == false; ++G) { - DFList[P->ID].NameMatch = NumPatterns != 0; + if (DFList[G->ID].NameMatch == true) + continue; + + DFList[G->ID].NameMatch = true; for (unsigned I = 0; I != NumPatterns; I++) { - if (regexec(&Patterns[I],P.Name(),0,0,0) == 0) - DFList[P->ID].NameMatch &= true; - else - DFList[P->ID].NameMatch = false; + if (regexec(&Patterns[I],G.Name(),0,0,0) == 0) + continue; + DFList[G->ID].NameMatch = false; + break; } // Doing names only, drop any that dont match.. - if (NamesOnly == true && DFList[P->ID].NameMatch == false) + if (NamesOnly == true && DFList[G->ID].NameMatch == false) continue; - // Find the proper version to use. + // Find the proper version to use + pkgCache::PkgIterator P = G.FindPreferredPkg(); + if (P.end() == true) + continue; pkgCache::VerIterator V = Plcy.GetCandidateVer(P); if (V.end() == false) - DFList[P->ID].Df = V.DescriptionList().FileList(); - } - - // Include all the packages that provide matching names too - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) - { - if (DFList[P->ID].NameMatch == false) + DFList[G->ID].Df = V.DescriptionList().FileList(); + + if (DFList[G->ID].NameMatch == false) continue; + // Include all the packages that provide matching names too for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++) { pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg()); - if (V.end() == false) - { - DFList[Prv.OwnerPkg()->ID].Df = V.DescriptionList().FileList(); - DFList[Prv.OwnerPkg()->ID].NameMatch = true; - } + if (V.end() == true) + continue; + + unsigned long id = Prv.OwnerPkg().Group()->ID; + DFList[id].Df = V.DescriptionList().FileList(); + DFList[id].NameMatch = true; } } - LocalitySort(&DFList->Df,Cache.HeaderP->PackageCount,sizeof(*DFList)); + LocalitySort(&DFList->Df,Cache.HeaderP->GroupCount,sizeof(*DFList)); + // Create the text record parser + pkgRecords Recs(Cache); // Iterate over all the version records and check them for (ExDescFile *J = DFList; J->Df != 0; J++) { pkgRecords::Parser &P = Recs.Lookup(pkgCache::DescFileIterator(Cache,J->Df)); - bool Match = true; - if (J->NameMatch == false) + if (J->NameMatch == false && NamesOnly == false) { - string LongDesc = P.LongDesc(); - Match = NumPatterns != 0; + string const LongDesc = P.LongDesc(); + J->NameMatch = true; for (unsigned I = 0; I != NumPatterns; I++) { if (regexec(&Patterns[I],LongDesc.c_str(),0,0,0) == 0) - Match &= true; - else - Match = false; + continue; + J->NameMatch = false; + break; } } - if (Match == true) + if (J->NameMatch == true) { if (ShowFull == true) { -- cgit v1.2.3 From 7959c5eda83bd6d69876942566cf47d74fc76530 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 31 May 2010 21:00:09 +0200 Subject: rename packageset into cacheset while it is not too late --- cmdline/apt-cache.cc | 2 +- cmdline/apt-get.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index d8e14617a..891b10873 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 1cffd6730..9894747f4 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include -- cgit v1.2.3 From 164fed49362b28c0264c293a14a06d167e32b76f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 2 Jun 2010 21:43:55 +0200 Subject: cmdline/apt-report-mirror-failure: port to latest python-apt --- cmdline/apt-report-mirror-failure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure index ef77d4954..e8ffdc2c7 100755 --- a/cmdline/apt-report-mirror-failure +++ b/cmdline/apt-report-mirror-failure @@ -5,7 +5,7 @@ import urllib import apt_pkg apt_pkg.init() -url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures", "") +url = apt_pkg.Config.find("Acquire::Mirror::ReportFailures", "") #"http://people.ubuntu.com:9000/mirror-failure") #"http://localhost:9000/mirror-failure") if not url: -- cgit v1.2.3 From 3a882565a943644dcf7287c9673fb07f617fb851 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 3 Jun 2010 10:48:19 +0200 Subject: * cmdline/apt-get.cc: - use unsigned long long instead of double to store values it gets --- cmdline/apt-get.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 44235e358..661ca6147 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -837,9 +837,9 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, return false; // Display statistics - double FetchBytes = Fetcher.FetchNeeded(); - double FetchPBytes = Fetcher.PartialPresent(); - double DebBytes = Fetcher.TotalNeeded(); + unsigned long long FetchBytes = Fetcher.FetchNeeded(); + unsigned long long FetchPBytes = Fetcher.PartialPresent(); + unsigned long long DebBytes = Fetcher.TotalNeeded(); if (DebBytes != Cache->DebSize()) { c0out << DebBytes << ',' << Cache->DebSize() << endl; @@ -2362,9 +2362,9 @@ bool DoSource(CommandLine &CmdL) } // Display statistics - double FetchBytes = Fetcher.FetchNeeded(); - double FetchPBytes = Fetcher.PartialPresent(); - double DebBytes = Fetcher.TotalNeeded(); + unsigned long long FetchBytes = Fetcher.FetchNeeded(); + unsigned long long FetchPBytes = Fetcher.PartialPresent(); + unsigned long long DebBytes = Fetcher.TotalNeeded(); // Check for enough free space struct statvfs Buf; -- cgit v1.2.3 From ea4b220b1b17b270fc1a05e454439c32589548b7 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 4 Jun 2010 14:51:21 +0200 Subject: Switch away from the now deprecated methods for Cache building --- cmdline/apt-extracttemplates.cc | 3 +-- cmdline/apt-get.cc | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc index 21ef1a050..07bc0c25d 100644 --- a/cmdline/apt-extracttemplates.cc +++ b/cmdline/apt-extracttemplates.cc @@ -296,8 +296,7 @@ bool Go(CommandLine &CmdL) MMap *Map = 0; pkgSourceList List; List.ReadMainList(); - OpProgress Prog; - pkgMakeStatusCache(List,Prog,&Map,true); + pkgCacheGenerator::MakeStatusCache(List,NULL,&Map,true); if (Map == 0) return false; DebFile::Cache = new pkgCache(Map); diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 9894747f4..c70dd56ac 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -91,14 +91,14 @@ class CacheFile : public pkgCacheFile bool BuildCaches(bool WithLock = true) { OpTextProgress Prog(*_config); - if (pkgCacheFile::BuildCaches(Prog,WithLock) == false) + if (pkgCacheFile::BuildCaches(&Prog,WithLock) == false) return false; return true; } bool Open(bool WithLock = true) { OpTextProgress Prog(*_config); - if (pkgCacheFile::Open(Prog,WithLock) == false) + if (pkgCacheFile::Open(&Prog,WithLock) == false) return false; Sort(); -- cgit v1.2.3 From d9eb210edda5515ca467eb234dd58b60d43c4513 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 10:04:48 +0200 Subject: use pkgCacheFile and the new CacheSets all over the place --- cmdline/apt-cache.cc | 399 +++++++++++++++++++++++++-------------------------- 1 file changed, 194 insertions(+), 205 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 891b10873..227fda4be 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -46,9 +46,6 @@ using namespace std; -pkgCache *GCache = 0; -pkgSourceList *SrcList = 0; - // LocalitySort - Sort a version list by package file locality /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -86,10 +83,13 @@ void LocalitySort(pkgCache::DescFile **begin, /* */ bool UnMet(CommandLine &CmdL) { - pkgCache &Cache = *GCache; - bool Important = _config->FindB("APT::Cache::Important",false); - - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + bool const Important = _config->FindB("APT::Cache::Important",false); + + pkgCacheFile CacheFile; + if (unlikely(CacheFile.GetPkgCache() == NULL)) + return false; + + for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; P++) { for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) { @@ -174,9 +174,9 @@ bool UnMet(CommandLine &CmdL) // --------------------------------------------------------------------- /* */ bool DumpPackage(CommandLine &CmdL) -{ - pkgCache &Cache = *GCache; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); +{ + pkgCacheFile CacheFile; + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { @@ -239,18 +239,22 @@ bool DumpPackage(CommandLine &CmdL) /* */ bool Stats(CommandLine &Cmd) { - pkgCache &Cache = *GCache; - cout << _("Total package names: ") << Cache.Head().GroupCount << " (" << - SizeToStr(Cache.Head().GroupCount*Cache.Head().GroupSz) << ')' << endl - << _("Total package structures: ") << Cache.Head().PackageCount << " (" << - SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl; + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + + cout << _("Total package names: ") << Cache->Head().GroupCount << " (" << + SizeToStr(Cache->Head().GroupCount*Cache->Head().GroupSz) << ')' << endl + << _("Total package structures: ") << Cache->Head().PackageCount << " (" << + SizeToStr(Cache->Head().PackageCount*Cache->Head().PackageSz) << ')' << endl; int Normal = 0; int Virtual = 0; int NVirt = 0; int DVirt = 0; int Missing = 0; - pkgCache::PkgIterator I = Cache.PkgBegin(); + pkgCache::PkgIterator I = Cache->PkgBegin(); for (;I.end() != true; I++) { if (I->VersionList != 0 && I->ProvidesList == 0) @@ -288,33 +292,33 @@ bool Stats(CommandLine &Cmd) cout << _(" Mixed virtual packages: ") << NVirt << endl; cout << _(" Missing: ") << Missing << endl; - cout << _("Total distinct versions: ") << Cache.Head().VersionCount << " (" << - SizeToStr(Cache.Head().VersionCount*Cache.Head().VersionSz) << ')' << endl; - cout << _("Total distinct descriptions: ") << Cache.Head().DescriptionCount << " (" << - SizeToStr(Cache.Head().DescriptionCount*Cache.Head().DescriptionSz) << ')' << endl; - cout << _("Total dependencies: ") << Cache.Head().DependsCount << " (" << - SizeToStr(Cache.Head().DependsCount*Cache.Head().DependencySz) << ')' << endl; + cout << _("Total distinct versions: ") << Cache->Head().VersionCount << " (" << + SizeToStr(Cache->Head().VersionCount*Cache->Head().VersionSz) << ')' << endl; + cout << _("Total distinct descriptions: ") << Cache->Head().DescriptionCount << " (" << + SizeToStr(Cache->Head().DescriptionCount*Cache->Head().DescriptionSz) << ')' << endl; + cout << _("Total dependencies: ") << Cache->Head().DependsCount << " (" << + SizeToStr(Cache->Head().DependsCount*Cache->Head().DependencySz) << ')' << endl; - cout << _("Total ver/file relations: ") << Cache.Head().VerFileCount << " (" << - SizeToStr(Cache.Head().VerFileCount*Cache.Head().VerFileSz) << ')' << endl; - cout << _("Total Desc/File relations: ") << Cache.Head().DescFileCount << " (" << - SizeToStr(Cache.Head().DescFileCount*Cache.Head().DescFileSz) << ')' << endl; - cout << _("Total Provides mappings: ") << Cache.Head().ProvidesCount << " (" << - SizeToStr(Cache.Head().ProvidesCount*Cache.Head().ProvidesSz) << ')' << endl; + cout << _("Total ver/file relations: ") << Cache->Head().VerFileCount << " (" << + SizeToStr(Cache->Head().VerFileCount*Cache->Head().VerFileSz) << ')' << endl; + cout << _("Total Desc/File relations: ") << Cache->Head().DescFileCount << " (" << + SizeToStr(Cache->Head().DescFileCount*Cache->Head().DescFileSz) << ')' << endl; + cout << _("Total Provides mappings: ") << Cache->Head().ProvidesCount << " (" << + SizeToStr(Cache->Head().ProvidesCount*Cache->Head().ProvidesSz) << ')' << endl; // String list stats unsigned long Size = 0; unsigned long Count = 0; - for (pkgCache::StringItem *I = Cache.StringItemP + Cache.Head().StringList; - I!= Cache.StringItemP; I = Cache.StringItemP + I->NextItem) + for (pkgCache::StringItem *I = Cache->StringItemP + Cache->Head().StringList; + I!= Cache->StringItemP; I = Cache->StringItemP + I->NextItem) { Count++; - Size += strlen(Cache.StrP + I->String) + 1; + Size += strlen(Cache->StrP + I->String) + 1; } cout << _("Total globbed strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl; unsigned long DepVerSize = 0; - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) { for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) { @@ -329,15 +333,15 @@ bool Stats(CommandLine &Cmd) unsigned long Slack = 0; for (int I = 0; I != 7; I++) - Slack += Cache.Head().Pools[I].ItemSize*Cache.Head().Pools[I].Count; + Slack += Cache->Head().Pools[I].ItemSize*Cache->Head().Pools[I].Count; cout << _("Total slack space: ") << SizeToStr(Slack) << endl; unsigned long Total = 0; - Total = Slack + Size + Cache.Head().DependsCount*Cache.Head().DependencySz + - Cache.Head().VersionCount*Cache.Head().VersionSz + - Cache.Head().PackageCount*Cache.Head().PackageSz + - Cache.Head().VerFileCount*Cache.Head().VerFileSz + - Cache.Head().ProvidesCount*Cache.Head().ProvidesSz; + Total = Slack + Size + Cache->Head().DependsCount*Cache->Head().DependencySz + + Cache->Head().VersionCount*Cache->Head().VersionSz + + Cache->Head().PackageCount*Cache->Head().PackageSz + + Cache->Head().VerFileCount*Cache->Head().VerFileSz + + Cache->Head().ProvidesCount*Cache->Head().ProvidesSz; cout << _("Total space accounted for: ") << SizeToStr(Total) << endl; return true; @@ -348,10 +352,14 @@ bool Stats(CommandLine &Cmd) /* This is worthless except fer debugging things */ bool Dump(CommandLine &Cmd) { - pkgCache &Cache = *GCache; - cout << "Using Versioning System: " << Cache.VS->Label << endl; + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + + cout << "Using Versioning System: " << Cache->VS->Label << endl; - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) { cout << "Package: " << P.FullName(true) << endl; for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) @@ -370,7 +378,7 @@ bool Dump(CommandLine &Cmd) } } - for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++) + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; F++) { cout << "File: " << F.FileName() << endl; cout << " Type: " << F.IndexType() << endl; @@ -396,18 +404,17 @@ bool Dump(CommandLine &Cmd) make this run really fast, perhaps I went a little overboard.. */ bool DumpAvail(CommandLine &Cmd) { - pkgCache &Cache = *GCache; - - pkgPolicy Plcy(&Cache); - if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false) + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL || CacheFile.BuildPolicy() == false)) return false; - - unsigned long Count = Cache.HeaderP->PackageCount+1; + + unsigned long Count = Cache->HeaderP->PackageCount+1; pkgCache::VerFile **VFList = new pkgCache::VerFile *[Count]; memset(VFList,0,sizeof(*VFList)*Count); // Map versions that we want to write out onto the VerList array. - for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) { if (P->VersionList == 0) continue; @@ -415,7 +422,7 @@ bool DumpAvail(CommandLine &Cmd) /* Find the proper version to use. If the policy says there are no possible selections we return the installed version, if available.. This prevents dselect from making it obsolete. */ - pkgCache::VerIterator V = Plcy.GetCandidateVer(P); + pkgCache::VerIterator V = CacheFile.GetPolicy()->GetCandidateVer(P); if (V.end() == true) { if (P->CurrentVer == 0) @@ -460,10 +467,10 @@ bool DumpAvail(CommandLine &Cmd) LocalitySort(VFList,Count,sizeof(*VFList)); // Iterate over all the package files and write them out. - char *Buffer = new char[Cache.HeaderP->MaxVerFileSize+10]; + char *Buffer = new char[Cache->HeaderP->MaxVerFileSize+10]; for (pkgCache::VerFile **J = VFList; *J != 0;) { - pkgCache::PkgFileIterator File(Cache,(*J)->File + Cache.PkgFileP); + pkgCache::PkgFileIterator File(*Cache,(*J)->File + Cache->PkgFileP); if (File.IsOk() == false) { _error->Error(_("Package file %s is out of sync."),File.FileName()); @@ -482,7 +489,7 @@ bool DumpAvail(CommandLine &Cmd) unsigned long Pos = 0; for (; *J != 0; J++) { - if ((*J)->File + Cache.PkgFileP != File) + if ((*J)->File + Cache->PkgFileP != File) break; const pkgCache::VerFile &VF = **J; @@ -538,11 +545,15 @@ bool DumpAvail(CommandLine &Cmd) /* */ bool Depends(CommandLine &CmdL) { - pkgCache &Cache = *GCache; - SPtrArray Colours = new unsigned[Cache.Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; + memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); + + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; @@ -553,7 +564,7 @@ bool Depends(CommandLine &CmdL) do { DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Colours[Pkg->ID] != 1) continue; @@ -600,11 +611,11 @@ bool Depends(CommandLine &CmdL) // Display all solutions SPtrArray List = D.AllTargets(); - pkgPrioSortList(Cache,List); + pkgPrioSortList(*Cache,List); for (pkgCache::Version **I = List; *I != 0; I++) { - pkgCache::VerIterator V(Cache,*I); - if (V != Cache.VerP + V.ParentPkg()->VersionList || + pkgCache::VerIterator V(*Cache,*I); + if (V != Cache->VerP + V.ParentPkg()->VersionList || V->ParentPkg == D->Package) continue; cout << " " << V.ParentPkg().FullName(true) << endl; @@ -625,11 +636,15 @@ bool Depends(CommandLine &CmdL) /* */ bool RDepends(CommandLine &CmdL) { - pkgCache &Cache = *GCache; - SPtrArray Colours = new unsigned[Cache.Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount); + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; + memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); + + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; @@ -639,7 +654,7 @@ bool RDepends(CommandLine &CmdL) do { DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Colours[Pkg->ID] != 1) continue; @@ -681,11 +696,11 @@ bool RDepends(CommandLine &CmdL) // Display all solutions SPtrArray List = D.AllTargets(); - pkgPrioSortList(Cache,List); + pkgPrioSortList(*Cache,List); for (pkgCache::Version **I = List; *I != 0; I++) { - pkgCache::VerIterator V(Cache,*I); - if (V != Cache.VerP + V.ParentPkg()->VersionList || + pkgCache::VerIterator V(*Cache,*I); + if (V != Cache->VerP + V.ParentPkg()->VersionList || V->ParentPkg == D->Package) continue; cout << " " << V.ParentPkg().FullName(true) << endl; @@ -707,7 +722,11 @@ bool RDepends(CommandLine &CmdL) bool XVcg(CommandLine &CmdL) { - pkgCache &Cache = *GCache; + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false); /* Normal packages are boxes @@ -724,21 +743,21 @@ bool XVcg(CommandLine &CmdL) 0 = None */ enum States {None=0, ToShow, ToShowNR, DoneNR, Done}; enum TheFlags {ForceNR=(1<<0)}; - unsigned char *Show = new unsigned char[Cache.Head().PackageCount]; - unsigned char *Flags = new unsigned char[Cache.Head().PackageCount]; - unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount]; + unsigned char *Show = new unsigned char[Cache->Head().PackageCount]; + unsigned char *Flags = new unsigned char[Cache->Head().PackageCount]; + unsigned char *ShapeMap = new unsigned char[Cache->Head().PackageCount]; // Show everything if no arguments given if (CmdL.FileList[1] == 0) - for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) + for (unsigned long I = 0; I != Cache->Head().PackageCount; I++) Show[I] = ToShow; else - for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) + for (unsigned long I = 0; I != Cache->Head().PackageCount; I++) Show[I] = None; - memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount); + memset(Flags,0,sizeof(*Flags)*Cache->Head().PackageCount); // Map the shapes - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Pkg->VersionList == 0) { @@ -777,7 +796,7 @@ bool XVcg(CommandLine &CmdL) } // Locate the package - pkgCache::PkgIterator Pkg = Cache.FindPkg(P); + pkgCache::PkgIterator Pkg = Cache->FindPkg(P); if (Pkg.end() == true) { _error->Warning(_("Unable to locate package %s"),*I); @@ -798,7 +817,7 @@ bool XVcg(CommandLine &CmdL) while (Act == true) { Act = false; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { // See we need to show this package if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR) @@ -833,7 +852,7 @@ bool XVcg(CommandLine &CmdL) for (pkgCache::VerIterator I = DPkg.VersionList(); I.end() == false && Hit == false; I++) { - if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) + if (Cache->VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) Hit = true; } @@ -841,7 +860,7 @@ bool XVcg(CommandLine &CmdL) for (pkgCache::PrvIterator I = DPkg.ProvidesList(); I.end() == false && Hit == false; I++) { - if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) + if (Cache->VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) Hit = true; } @@ -902,7 +921,7 @@ bool XVcg(CommandLine &CmdL) /* Draw the box colours after the fact since we can not tell what colour they should be until everything is finished drawing */ - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Show[Pkg->ID] < DoneNR) continue; @@ -931,7 +950,11 @@ bool XVcg(CommandLine &CmdL) http://www.research.att.com/sw/tools/graphviz/ */ bool Dotty(CommandLine &CmdL) { - pkgCache &Cache = *GCache; + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false); /* Normal packages are boxes @@ -948,21 +971,21 @@ bool Dotty(CommandLine &CmdL) 0 = None */ enum States {None=0, ToShow, ToShowNR, DoneNR, Done}; enum TheFlags {ForceNR=(1<<0)}; - unsigned char *Show = new unsigned char[Cache.Head().PackageCount]; - unsigned char *Flags = new unsigned char[Cache.Head().PackageCount]; - unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount]; + unsigned char *Show = new unsigned char[Cache->Head().PackageCount]; + unsigned char *Flags = new unsigned char[Cache->Head().PackageCount]; + unsigned char *ShapeMap = new unsigned char[Cache->Head().PackageCount]; // Show everything if no arguments given if (CmdL.FileList[1] == 0) - for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) + for (unsigned long I = 0; I != Cache->Head().PackageCount; I++) Show[I] = ToShow; else - for (unsigned long I = 0; I != Cache.Head().PackageCount; I++) + for (unsigned long I = 0; I != Cache->Head().PackageCount; I++) Show[I] = None; - memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount); + memset(Flags,0,sizeof(*Flags)*Cache->Head().PackageCount); // Map the shapes - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Pkg->VersionList == 0) { @@ -1001,7 +1024,7 @@ bool Dotty(CommandLine &CmdL) } // Locate the package - pkgCache::PkgIterator Pkg = Cache.FindPkg(P); + pkgCache::PkgIterator Pkg = Cache->FindPkg(P); if (Pkg.end() == true) { _error->Warning(_("Unable to locate package %s"),*I); @@ -1022,7 +1045,7 @@ bool Dotty(CommandLine &CmdL) while (Act == true) { Act = false; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { // See we need to show this package if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR) @@ -1055,7 +1078,7 @@ bool Dotty(CommandLine &CmdL) for (pkgCache::VerIterator I = DPkg.VersionList(); I.end() == false && Hit == false; I++) { - if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) + if (Cache->VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true) Hit = true; } @@ -1063,7 +1086,7 @@ bool Dotty(CommandLine &CmdL) for (pkgCache::PrvIterator I = DPkg.ProvidesList(); I.end() == false && Hit == false; I++) { - if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) + if (Cache->VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false) Hit = true; } @@ -1117,7 +1140,7 @@ bool Dotty(CommandLine &CmdL) /* Draw the box colours after the fact since we can not tell what colour they should be until everything is finished drawing */ - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) + for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) { if (Show[Pkg->ID] < DoneNR) continue; @@ -1191,8 +1214,12 @@ bool DoAdd(CommandLine &CmdL) // --------------------------------------------------------------------- /* This displays the package record from the proper package index file. It is not used by DumpAvail for performance reasons. */ -bool DisplayRecord(pkgCache::VerIterator V) +bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V) { + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + // Find an appropriate file pkgCache::VerFileIterator Vf = V.FileList(); for (; Vf.end() == false; Vf++) @@ -1211,7 +1238,7 @@ bool DisplayRecord(pkgCache::VerIterator V) return false; // Read the record - unsigned char *Buffer = new unsigned char[GCache->HeaderP->MaxVerFileSize+1]; + unsigned char *Buffer = new unsigned char[Cache->HeaderP->MaxVerFileSize+1]; Buffer[V.FileList()->Size] = '\n'; if (PkgF.Seek(V.FileList()->Offset) == false || PkgF.Read(Buffer,V.FileList()->Size) == false) @@ -1231,7 +1258,7 @@ bool DisplayRecord(pkgCache::VerIterator V) } // Show the right description - pkgRecords Recs(*GCache); + pkgRecords Recs(*Cache); pkgCache::DescIterator Desc = V.TranslatedDescription(); pkgRecords::Parser &P = Recs.Lookup(Desc.FileList()); cout << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc(); @@ -1271,13 +1298,16 @@ struct ExDescFile /* This searches the package names and package descriptions for a pattern */ bool Search(CommandLine &CmdL) { - pkgCache &Cache = *GCache; bool const ShowFull = _config->FindB("APT::Cache::ShowFull",false); bool const NamesOnly = _config->FindB("APT::Cache::NamesOnly",false); unsigned int const NumPatterns = CmdL.FileSize() -1; - pkgDepCache::Policy Plcy; - + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + pkgDepCache::Policy *Plcy = CacheFile.GetPolicy(); + if (unlikely(Cache == NULL || Plcy == NULL)) + return false; + // Make sure there is at least one argument if (NumPatterns < 1) return _error->Error(_("You must give at least one search pattern")); @@ -1303,11 +1333,11 @@ bool Search(CommandLine &CmdL) return false; } - ExDescFile *DFList = new ExDescFile[Cache.HeaderP->GroupCount+1]; - memset(DFList,0,sizeof(*DFList)*Cache.HeaderP->GroupCount+1); + ExDescFile *DFList = new ExDescFile[Cache->HeaderP->GroupCount+1]; + memset(DFList,0,sizeof(*DFList)*Cache->HeaderP->GroupCount+1); // Map versions that we want to write out onto the VerList array. - for (pkgCache::GrpIterator G = Cache.GrpBegin(); G.end() == false; ++G) + for (pkgCache::GrpIterator G = Cache->GrpBegin(); G.end() == false; ++G) { if (DFList[G->ID].NameMatch == true) continue; @@ -1329,7 +1359,7 @@ bool Search(CommandLine &CmdL) pkgCache::PkgIterator P = G.FindPreferredPkg(); if (P.end() == true) continue; - pkgCache::VerIterator V = Plcy.GetCandidateVer(P); + pkgCache::VerIterator V = Plcy->GetCandidateVer(P); if (V.end() == false) DFList[G->ID].Df = V.DescriptionList().FileList(); @@ -1339,7 +1369,7 @@ bool Search(CommandLine &CmdL) // Include all the packages that provide matching names too for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++) { - pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg()); + pkgCache::VerIterator V = Plcy->GetCandidateVer(Prv.OwnerPkg()); if (V.end() == true) continue; @@ -1349,14 +1379,14 @@ bool Search(CommandLine &CmdL) } } - LocalitySort(&DFList->Df,Cache.HeaderP->GroupCount,sizeof(*DFList)); + LocalitySort(&DFList->Df,Cache->HeaderP->GroupCount,sizeof(*DFList)); // Create the text record parser - pkgRecords Recs(Cache); + pkgRecords Recs(*Cache); // Iterate over all the version records and check them for (ExDescFile *J = DFList; J->Df != 0; J++) { - pkgRecords::Parser &P = Recs.Lookup(pkgCache::DescFileIterator(Cache,J->Df)); + pkgRecords::Parser &P = Recs.Lookup(pkgCache::DescFileIterator(*Cache,J->Df)); if (J->NameMatch == false && NamesOnly == false) { @@ -1398,15 +1428,17 @@ bool Search(CommandLine &CmdL) /* show automatically installed packages (sorted) */ bool ShowAuto(CommandLine &CmdL) { - OpProgress op; - pkgDepCache DepCache(GCache); - DepCache.Init(&op); + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + pkgDepCache *DepCache = CacheFile.GetDepCache(); + if (unlikely(Cache == NULL || DepCache == NULL)) + return false; std::vector packages; - packages.reserve(GCache->HeaderP->PackageCount / 3); + packages.reserve(Cache->HeaderP->PackageCount / 3); - for (pkgCache::PkgIterator P = GCache->PkgBegin(); P.end() == false; P++) - if (DepCache[P].Flags & pkgCache::Flag::Auto) + for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; P++) + if ((*DepCache)[P].Flags & pkgCache::Flag::Auto) packages.push_back(P.Name()); std::sort(packages.begin(), packages.end()); @@ -1421,34 +1453,16 @@ bool ShowAuto(CommandLine &CmdL) // --------------------------------------------------------------------- /* */ bool ShowPackage(CommandLine &CmdL) -{ - pkgCache &Cache = *GCache; - pkgDepCache::Policy Plcy; - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - { - // Find the proper version to use. - if (_config->FindB("APT::Cache::AllVersions","true") == true) - { - pkgCache::VerIterator V; - for (V = Pkg.VersionList(); V.end() == false; V++) - { - if (DisplayRecord(V) == false) - return false; - } - } - else - { - pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg); - if (V.end() == true || V.FileList().end() == true) - continue; - if (DisplayRecord(V) == false) - return false; - } - } - - if (pkgset.empty() == false) +{ + pkgCacheFile CacheFile; + APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? + APT::VersionSet::ALL : APT::VersionSet::INSTALLED; + APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList, select); + for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) + if (DisplayRecord(CacheFile, Ver) == false) + return false; + + if (verset.empty() == false) return true; return _error->Error(_("No packages found")); } @@ -1458,8 +1472,10 @@ bool ShowPackage(CommandLine &CmdL) /* This does a prefix match on the first argument */ bool ShowPkgNames(CommandLine &CmdL) { - pkgCache &Cache = *GCache; - pkgCache::GrpIterator I = Cache.GrpBegin(); + pkgCacheFile CacheFile; + if (unlikely(CacheFile.BuildCaches(NULL, false) == false)) + return false; + pkgCache::GrpIterator I = CacheFile.GetPkgCache()->GrpBegin(); bool const All = _config->FindB("APT::Cache::AllNames","false"); if (CmdL.FileList[1] != 0) @@ -1495,11 +1511,13 @@ bool ShowPkgNames(CommandLine &CmdL) /* */ bool ShowSrcPackage(CommandLine &CmdL) { - pkgSourceList List; - List.ReadMainList(); - + pkgCacheFile CacheFile; + pkgSourceList *List = CacheFile.GetSourceList(); + if (unlikely(List == NULL)) + return false; + // Create the text record parsers - pkgSrcRecords SrcRecs(List); + pkgSrcRecords SrcRecs(*List); if (_error->PendingError() == true) return false; @@ -1530,19 +1548,18 @@ bool ShowSrcPackage(CommandLine &CmdL) /* */ bool Policy(CommandLine &CmdL) { - if (SrcList == 0) - return _error->Error("Generate must be enabled for this function"); - - pkgCache &Cache = *GCache; - pkgPolicy Plcy(&Cache); - if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false) + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + pkgPolicy *Plcy = CacheFile.GetPolicy(); + pkgSourceList *SrcList = CacheFile.GetSourceList(); + if (unlikely(Cache == NULL || Plcy == NULL || SrcList == NULL)) return false; - + // Print out all of the package files if (CmdL.FileList[1] == 0) { cout << _("Package files:") << endl; - for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++) + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; F++) { // Locate the associated index files so we can derive a description pkgIndexFile *Indx; @@ -1551,7 +1568,7 @@ bool Policy(CommandLine &CmdL) return _error->Error(_("Cache is out of sync, can't x-ref a package file")); printf("%4i %s\n", - Plcy.GetPriority(F),Indx->Describe(true).c_str()); + Plcy->GetPriority(F),Indx->Describe(true).c_str()); // Print the reference information for the package string Str = F.RelStr(); @@ -1563,16 +1580,16 @@ bool Policy(CommandLine &CmdL) // Show any packages have explicit pins cout << _("Pinned packages:") << endl; - pkgCache::PkgIterator I = Cache.PkgBegin(); + pkgCache::PkgIterator I = Cache->PkgBegin(); for (;I.end() != true; I++) { - if (Plcy.GetPriority(I) == 0) + if (Plcy->GetPriority(I) == 0) continue; // Print the package name and the version we are forcing to cout << " " << I.FullName(true) << " -> "; - pkgCache::VerIterator V = Plcy.GetMatch(I); + pkgCache::VerIterator V = Plcy->GetMatch(I); if (V.end() == true) cout << _("(not found)") << endl; else @@ -1593,7 +1610,7 @@ bool Policy(CommandLine &CmdL) (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; // Print out detailed information for each package - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator I = pkgset.begin(); I != pkgset.end(); ++I) { pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); @@ -1613,17 +1630,17 @@ bool Policy(CommandLine &CmdL) // Candidate Version cout << msgCandidate << OutputInDepth(deepCandidate, " "); - pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg); + pkgCache::VerIterator V = Plcy->GetCandidateVer(Pkg); if (V.end() == true) cout << _("(none)") << endl; else cout << V.VerStr() << endl; // Pinned version - if (Plcy.GetPriority(Pkg) != 0) + if (Plcy->GetPriority(Pkg) != 0) { cout << _(" Package pin: "); - V = Plcy.GetMatch(Pkg); + V = Plcy->GetMatch(Pkg); if (V.end() == true) cout << _("(not found)") << endl; else @@ -1638,7 +1655,7 @@ bool Policy(CommandLine &CmdL) cout << " *** " << V.VerStr(); else cout << " " << V.VerStr(); - cout << " " << Plcy.GetPriority(Pkg) << endl; + cout << " " << Plcy->GetPriority(Pkg) << endl; for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++) { // Locate the associated index files so we can derive a description @@ -1646,7 +1663,7 @@ bool Policy(CommandLine &CmdL) if (SrcList->FindIndex(VF.File(),Indx) == false && _system->FindIndex(VF.File(),Indx) == false) return _error->Error(_("Cache is out of sync, can't x-ref a package file")); - printf(" %4i %s\n",Plcy.GetPriority(VF.File()), + printf(" %4i %s\n",Plcy->GetPriority(VF.File()), Indx->Describe(true).c_str()); } } @@ -1661,12 +1678,11 @@ bool Policy(CommandLine &CmdL) /* */ bool Madison(CommandLine &CmdL) { - if (SrcList == 0) - return _error->Error("Generate must be enabled for this function"); - - SrcList->ReadMainList(); + pkgCacheFile CacheFile; + pkgSourceList *SrcList = CacheFile.GetSourceList(); - pkgCache &Cache = *GCache; + if (SrcList == 0) + return false; // Create the src text record parsers and ignore errors about missing // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords @@ -1674,7 +1690,7 @@ bool Madison(CommandLine &CmdL) if (_error->PendingError() == true) _error->Discard(); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(Cache, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (Pkg.end() == false) @@ -1729,11 +1745,9 @@ bool Madison(CommandLine &CmdL) bool GenCaches(CommandLine &Cmd) { OpTextProgress Progress(*_config); - - pkgSourceList List; - if (List.ReadMainList() == false) - return false; - return pkgMakeStatusCache(List,Progress); + + pkgCacheFile CacheFile; + return CacheFile.BuildCaches(&Progress, true); } /*}}}*/ // ShowHelp - Show a help screen /*{{{*/ @@ -1865,35 +1879,10 @@ int main(int argc,const char *argv[]) /*{{{*/ if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1) _config->Set("quiet","1"); +// if (_config->FindB("APT::Cache::Generate",true) == false) if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false) - { - MMap *Map = 0; - if (_config->FindB("APT::Cache::Generate",true) == false) - { - Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"), - FileFd::ReadOnly),MMap::Public|MMap::ReadOnly); - } - else - { - // Open the cache file - SrcList = new pkgSourceList; - SrcList->ReadMainList(); + CmdL.DispatchArg(CmdsB); - // Generate it and map it - OpProgress Prog; - pkgMakeStatusCache(*SrcList,Prog,&Map,true); - } - - if (_error->PendingError() == false) - { - pkgCache Cache(Map); - GCache = &Cache; - if (_error->PendingError() == false) - CmdL.DispatchArg(CmdsB); - } - delete Map; - } - // Print any errors or warnings found during parsing if (_error->empty() == false) { -- cgit v1.2.3 From 0588779fb2139b70f369ccac20fcc0f3a3e9ed47 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 10:17:10 +0200 Subject: Add a option to apt-cache policy to additionally init the DepCache before starting to get the package informations. This is useful e.g. for debugging the MultiArchKiller. --- cmdline/apt-cache.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 227fda4be..b0e705108 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1555,6 +1555,12 @@ bool Policy(CommandLine &CmdL) if (unlikely(Cache == NULL || Plcy == NULL || SrcList == NULL)) return false; + /* Should the MultiArchKiller be run to see which pseudo packages for an + arch all package are currently installed? Activating it gives a speed + penality for no real gain beside enhanced debugging, so in general no. */ + if (_config->FindB("APT::Cache::Policy::DepCache", false) == true) + CacheFile.GetDepCache(); + // Print out all of the package files if (CmdL.FileList[1] == 0) { -- cgit v1.2.3 From f44a05ff641523ab8eae84166e9b1a9dcf1b366f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 12:54:30 +0200 Subject: add --target-release option (Closes: #115520) --- cmdline/apt-cache.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index b0e705108..005721ddf 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1831,6 +1831,8 @@ int main(int argc,const char *argv[]) /*{{{*/ {'n',"names-only","APT::Cache::NamesOnly",0}, {0,"all-names","APT::Cache::AllNames",0}, {0,"recurse","APT::Cache::RecurseDepends",0}, + {'t',"target-release","APT::Default-Release",CommandLine::HasArg}, + {'t',"default-release","APT::Default-Release",CommandLine::HasArg}, {'c',"config-file",0,CommandLine::ConfigFile}, {'o',"option",0,CommandLine::ArbItem}, {0,"installed","APT::Cache::Installed",0}, -- cgit v1.2.3 From 9f1f17ccd4f84c23410ae62911c85f5836c3b503 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 13:09:18 +0200 Subject: Don't increase the commandline parameter in the library but in the application to be really generic. --- cmdline/apt-cache.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 005721ddf..e3876d5e0 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -176,7 +176,7 @@ bool UnMet(CommandLine &CmdL) bool DumpPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { @@ -553,7 +553,7 @@ bool Depends(CommandLine &CmdL) SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; @@ -644,7 +644,7 @@ bool RDepends(CommandLine &CmdL) SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; @@ -1457,7 +1457,7 @@ bool ShowPackage(CommandLine &CmdL) pkgCacheFile CacheFile; APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? APT::VersionSet::ALL : APT::VersionSet::INSTALLED; - APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList, select); + APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select); for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) if (DisplayRecord(CacheFile, Ver) == false) return false; @@ -1616,7 +1616,7 @@ bool Policy(CommandLine &CmdL) (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; // Print out detailed information for each package - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); for (APT::PackageSet::const_iterator I = pkgset.begin(); I != pkgset.end(); ++I) { pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); @@ -1696,7 +1696,7 @@ bool Madison(CommandLine &CmdL) if (_error->PendingError() == true) _error->Discard(); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (Pkg.end() == false) -- cgit v1.2.3 From 292f5b8770a0f10d8a19204dc4a914437d861662 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 13:42:04 +0200 Subject: apt-cache show --no-all-versions should issues the Candidate --- cmdline/apt-cache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index e3876d5e0..b782c70af 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1456,7 +1456,7 @@ bool ShowPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? - APT::VersionSet::ALL : APT::VersionSet::INSTALLED; + APT::VersionSet::ALL : APT::VersionSet::CANDIDATE; APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select); for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) if (DisplayRecord(CacheFile, Ver) == false) -- cgit v1.2.3 From 6ebaae9a5d794ce69d17e419c109fc185925541c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 16:59:45 +0200 Subject: accept package versions in the unmet command --- cmdline/apt-cache.cc | 57 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 23 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index b782c70af..ef074280e 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -81,18 +81,8 @@ void LocalitySort(pkgCache::DescFile **begin, // UnMet - Show unmet dependencies /*{{{*/ // --------------------------------------------------------------------- /* */ -bool UnMet(CommandLine &CmdL) +bool ShowUnMet(pkgCache::VerIterator const &V, bool const &Important) { - bool const Important = _config->FindB("APT::Cache::Important",false); - - pkgCacheFile CacheFile; - if (unlikely(CacheFile.GetPkgCache() == NULL)) - return false; - - for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; P++) - { - for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++) - { bool Header = false; for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;) { @@ -100,20 +90,19 @@ bool UnMet(CommandLine &CmdL) pkgCache::DepIterator Start; pkgCache::DepIterator End; D.GlobOr(Start,End); - - // Skip conflicts and replaces - if (End->Type != pkgCache::Dep::PreDepends && - End->Type != pkgCache::Dep::Depends && - End->Type != pkgCache::Dep::Suggests && - End->Type != pkgCache::Dep::Recommends) - continue; // Important deps only if (Important == true) if (End->Type != pkgCache::Dep::PreDepends && End->Type != pkgCache::Dep::Depends) continue; - + + // Skip conflicts and replaces + if (End->Type == pkgCache::Dep::DpkgBreaks || + End->Type == pkgCache::Dep::Replaces || + End->Type == pkgCache::Dep::Conflicts) + continue; + // Verify the or group bool OK = false; pkgCache::DepIterator RealStart = Start; @@ -142,7 +131,7 @@ bool UnMet(CommandLine &CmdL) // Oops, it failed.. if (Header == false) ioprintf(cout,_("Package %s version %s has an unmet dep:\n"), - P.FullName(true).c_str(),V.VerStr()); + V.ParentPkg().FullName(true).c_str(),V.VerStr()); Header = true; // Print out the dep type @@ -164,9 +153,31 @@ bool UnMet(CommandLine &CmdL) while (1); cout << endl; - } - } - } + } + return true; +} +bool UnMet(CommandLine &CmdL) +{ + bool const Important = _config->FindB("APT::Cache::Important",false); + + pkgCacheFile CacheFile; + if (unlikely(CacheFile.GetPkgCache() == NULL)) + return false; + + if (CmdL.FileSize() <= 1) + { + for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; P++) + for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V) + if (ShowUnMet(V, Important) == false) + return false; + } + else + { + APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + for (APT::VersionSet::iterator V = verset.begin(); V != verset.end(); ++V) + if (ShowUnMet(V, Important) == false) + return false; + } return true; } /*}}}*/ -- cgit v1.2.3 From 07c279d93f0b61e96c9caf8139accd0289feab56 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 19:14:32 +0200 Subject: do not fail if an unrelated error is pending in DisplayRecord() --- cmdline/apt-cache.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index ef074280e..de4288c5a 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1243,11 +1243,11 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V) pkgCache::PkgFileIterator I = Vf.File(); if (I.IsOk() == false) return _error->Error(_("Package file %s is out of sync."),I.FileName()); - - FileFd PkgF(I.FileName(),FileFd::ReadOnly); - if (_error->PendingError() == true) + + FileFd PkgF; + if (PkgF.Open(I.FileName(), FileFd::ReadOnly) == false) return false; - + // Read the record unsigned char *Buffer = new unsigned char[Cache->HeaderP->MaxVerFileSize+1]; Buffer[V.FileList()->Size] = '\n'; -- cgit v1.2.3 From 3c9772456931842dee211444086c15dd2e5f9a29 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 6 Jun 2010 21:49:28 +0200 Subject: use the GroupedFromCommandLine() method in the dotty and xvcg command to get all the funky features in less lines --- cmdline/apt-cache.cc | 84 ++++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 56 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index de4288c5a..7cb95b3f8 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -787,38 +787,24 @@ bool XVcg(CommandLine &CmdL) ShapeMap[Pkg->ID] = 3; } } - + // Load the list of packages from the command line into the show list - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + std::list mods; + mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX)); + mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX)); + std::map pkgsets = + APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0); + + for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin(); + Pkg != pkgsets[0].end(); ++Pkg) + Show[Pkg->ID] = ToShow; + for (APT::PackageSet::const_iterator Pkg = pkgsets[1].begin(); + Pkg != pkgsets[1].end(); ++Pkg) { - // Process per-package flags - string P = *I; - bool Force = false; - if (P.length() > 3) - { - if (P.end()[-1] == '^') - { - Force = true; - P.erase(P.end()-1); - } - - if (P.end()[-1] == ',') - P.erase(P.end()-1); - } - - // Locate the package - pkgCache::PkgIterator Pkg = Cache->FindPkg(P); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } Show[Pkg->ID] = ToShow; - - if (Force == true) - Flags[Pkg->ID] |= ForceNR; + Flags[Pkg->ID] |= ForceNR; } - + // Little header cout << "graph: { title: \"packages\"" << endl << "xmax: 700 ymax: 700 x: 30 y: 30" << endl << @@ -1015,38 +1001,24 @@ bool Dotty(CommandLine &CmdL) ShapeMap[Pkg->ID] = 3; } } - + // Load the list of packages from the command line into the show list - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + std::list mods; + mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX)); + mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX)); + std::map pkgsets = + APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0); + + for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin(); + Pkg != pkgsets[0].end(); ++Pkg) + Show[Pkg->ID] = ToShow; + for (APT::PackageSet::const_iterator Pkg = pkgsets[1].begin(); + Pkg != pkgsets[1].end(); ++Pkg) { - // Process per-package flags - string P = *I; - bool Force = false; - if (P.length() > 3) - { - if (P.end()[-1] == '^') - { - Force = true; - P.erase(P.end()-1); - } - - if (P.end()[-1] == ',') - P.erase(P.end()-1); - } - - // Locate the package - pkgCache::PkgIterator Pkg = Cache->FindPkg(P); - if (Pkg.end() == true) - { - _error->Warning(_("Unable to locate package %s"),*I); - continue; - } Show[Pkg->ID] = ToShow; - - if (Force == true) - Flags[Pkg->ID] |= ForceNR; + Flags[Pkg->ID] |= ForceNR; } - + // Little header printf("digraph packages {\n"); printf("concentrate=true;\n"); -- cgit v1.2.3 From d8276801a1c84582a85ed9ea1f2eb4e66e052e6b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 15 Jun 2010 20:46:09 +0200 Subject: * cmdline/cacheset.cc: - doesn't include it in the library for now as it is too volatile --- cmdline/cacheset.cc | 330 ++++++++++++++++++++++++++++++++++++++++++++++++++++ cmdline/cacheset.h | 274 +++++++++++++++++++++++++++++++++++++++++++ cmdline/makefile | 4 +- 3 files changed, 606 insertions(+), 2 deletions(-) create mode 100644 cmdline/cacheset.cc create mode 100644 cmdline/cacheset.h (limited to 'cmdline') diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc new file mode 100644 index 000000000..fde52168a --- /dev/null +++ b/cmdline/cacheset.cc @@ -0,0 +1,330 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + Simple wrapper around a std::set to provide a similar interface to + a set of cache structures as to the complete set of all structures + in the pkgCache. Currently only Package is supported. + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include +#include +#include +#include +#include + +#include + +#include + +#include + /*}}}*/ +namespace APT { +// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ +PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out) { + PackageSet pkgset; + std::string arch = "native"; + static const char * const isregex = ".?+*|[^$"; + + if (pattern.find_first_of(isregex) == std::string::npos) + return pkgset; + + size_t archfound = pattern.find_last_of(':'); + if (archfound != std::string::npos) { + arch = pattern.substr(archfound+1); + if (arch.find_first_of(isregex) == std::string::npos) + pattern.erase(archfound); + else + arch = "native"; + } + + regex_t Pattern; + int Res; + if ((Res = regcomp(&Pattern, pattern.c_str() , REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0) { + char Error[300]; + regerror(Res, &Pattern, Error, sizeof(Error)); + _error->Error(_("Regex compilation error - %s"), Error); + return pkgset; + } + + for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) + { + if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) + continue; + pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); + if (Pkg.end() == true) { + if (archfound == std::string::npos) { + std::vector archs = APT::Configuration::getArchitectures(); + for (std::vector::const_iterator a = archs.begin(); + a != archs.end() && Pkg.end() != true; ++a) + Pkg = Grp.FindPkg(*a); + } + if (Pkg.end() == true) + continue; + } + + ioprintf(out, _("Note, selecting %s for regex '%s'\n"), + Pkg.FullName(true).c_str(), pattern.c_str()); + + pkgset.insert(Pkg); + } + + regfree(&Pattern); + + return pkgset; +} + /*}}}*/ +// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ +std::map PackageSet::GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, std::ostream &out) { + std::map pkgsets; + for (const char **I = cmdline; *I != 0; ++I) { + unsigned short modID = fallback; + std::string str = *I; + for (std::list::const_iterator mod = mods.begin(); + mod != mods.end(); ++mod) { + size_t const alength = strlen(mod->Alias); + switch(mod->Pos) { + case PackageSet::Modifier::POSTFIX: + if (str.compare(str.length() - alength, alength, + mod->Alias, 0, alength) != 0) + continue; + str.erase(str.length() - alength); + modID = mod->ID; + break; + case PackageSet::Modifier::PREFIX: + continue; + case PackageSet::Modifier::NONE: + continue; + } + break; + } + PackageSet pset = PackageSet::FromString(Cache, str, out); + pkgsets[modID].insert(pset.begin(), pset.end()); + } + return pkgsets; +} + /*}}}*/ +// FromCommandLine - Return all packages specified on commandline /*{{{*/ +PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out) { + PackageSet pkgset; + for (const char **I = cmdline; *I != 0; ++I) { + PackageSet pset = FromString(Cache, *I, out); + pkgset.insert(pset.begin(), pset.end()); + } + return pkgset; +} + /*}}}*/ +// FromString - Return all packages matching a specific string /*{{{*/ +PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, std::ostream &out) { + std::string pkg = str; + size_t archfound = pkg.find_last_of(':'); + std::string arch; + if (archfound != std::string::npos) { + arch = pkg.substr(archfound+1); + pkg.erase(archfound); + } + + pkgCache::PkgIterator Pkg; + if (arch.empty() == true) { + pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); + if (Grp.end() == false) + Pkg = Grp.FindPreferredPkg(); + } else + Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch); + + if (Pkg.end() == false) { + PackageSet pkgset; + pkgset.insert(Pkg); + return pkgset; + } + PackageSet regex = FromRegEx(Cache, str, out); + if (regex.empty() == true) + _error->Warning(_("Unable to locate package %s"), str.c_str()); + return regex; +} + /*}}}*/ +// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ +std::map VersionSet::GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, std::ostream &out) { + std::map versets; + for (const char **I = cmdline; *I != 0; ++I) { + unsigned short modID = fallback; + VersionSet::Version select = VersionSet::NEWEST; + std::string str = *I; + for (std::list::const_iterator mod = mods.begin(); + mod != mods.end(); ++mod) { + if (modID == fallback && mod->ID == fallback) + select = mod->SelectVersion; + size_t const alength = strlen(mod->Alias); + switch(mod->Pos) { + case VersionSet::Modifier::POSTFIX: + if (str.compare(str.length() - alength, alength, + mod->Alias, 0, alength) != 0) + continue; + str.erase(str.length() - alength); + modID = mod->ID; + select = mod->SelectVersion; + break; + case VersionSet::Modifier::PREFIX: + continue; + case VersionSet::Modifier::NONE: + continue; + } + break; + } + VersionSet vset = VersionSet::FromString(Cache, str, select , out); + versets[modID].insert(vset.begin(), vset.end()); + } + return versets; +} + /*}}}*/ +// FromCommandLine - Return all versions specified on commandline /*{{{*/ +APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback, std::ostream &out) { + VersionSet verset; + for (const char **I = cmdline; *I != 0; ++I) { + VersionSet vset = VersionSet::FromString(Cache, *I, fallback, out); + verset.insert(vset.begin(), vset.end()); + } + return verset; +} + /*}}}*/ +// FromString - Returns all versions spedcified by a string /*{{{*/ +APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, + APT::VersionSet::Version const &fallback, std::ostream &out) { + std::string ver; + bool verIsRel = false; + size_t const vertag = pkg.find_last_of("/="); + if (vertag != string::npos) { + ver = pkg.substr(vertag+1); + verIsRel = (pkg[vertag] == '/'); + pkg.erase(vertag); + } + PackageSet pkgset = PackageSet::FromString(Cache, pkg.c_str(), out); + VersionSet verset; + for (PackageSet::const_iterator P = pkgset.begin(); + P != pkgset.end(); ++P) { + if (vertag == string::npos) { + AddSelectedVersion(Cache, verset, P, fallback); + continue; + } + pkgCache::VerIterator V; + if (ver == "installed") + V = getInstalledVer(Cache, P); + else if (ver == "candidate") + V = getCandidateVer(Cache, P); + else { + pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : + pkgVersionMatch::Version)); + V = Match.Find(P); + if (V.end() == true) { + if (verIsRel == true) + _error->Error(_("Release '%s' for '%s' was not found"), + ver.c_str(), P.FullName(true).c_str()); + else + _error->Error(_("Version '%s' for '%s' was not found"), + ver.c_str(), P.FullName(true).c_str()); + continue; + } + } + if (V.end() == true) + continue; + if (ver == V.VerStr()) + ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"), + V.VerStr(), V.RelStr().c_str(), P.FullName(true).c_str()); + verset.insert(V); + } + return verset; +} + /*}}}*/ +// AddSelectedVersion - add version from package based on fallback /*{{{*/ +bool VersionSet::AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, + pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, + bool const &AllowError) { + pkgCache::VerIterator V; + switch(fallback) { + case VersionSet::ALL: + if (P->VersionList != 0) + for (V = P.VersionList(); V.end() != true; ++V) + verset.insert(V); + else if (AllowError == false) + return _error->Error(_("Can't select versions from package '%s' as it purely virtual"), P.FullName(true).c_str()); + else + return false; + break; + case VersionSet::CANDANDINST: + verset.insert(getInstalledVer(Cache, P, AllowError)); + verset.insert(getCandidateVer(Cache, P, AllowError)); + break; + case VersionSet::CANDIDATE: + verset.insert(getCandidateVer(Cache, P, AllowError)); + break; + case VersionSet::INSTALLED: + verset.insert(getInstalledVer(Cache, P, AllowError)); + break; + case VersionSet::CANDINST: + V = getCandidateVer(Cache, P, true); + if (V.end() == true) + V = getInstalledVer(Cache, P, true); + if (V.end() == false) + verset.insert(V); + else if (AllowError == false) + return _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), P.FullName(true).c_str()); + else + return false; + break; + case VersionSet::INSTCAND: + V = getInstalledVer(Cache, P, true); + if (V.end() == true) + V = getCandidateVer(Cache, P, true); + if (V.end() == false) + verset.insert(V); + else if (AllowError == false) + return _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), P.FullName(true).c_str()); + else + return false; + break; + case VersionSet::NEWEST: + if (P->VersionList != 0) + verset.insert(P.VersionList()); + else if (AllowError == false) + return _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), P.FullName(true).c_str()); + else + return false; + break; + } + return true; +} + /*}}}*/ +// getCandidateVer - Returns the candidate version of the given package /*{{{*/ +pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError) { + pkgCache::VerIterator Cand; + if (Cache.IsDepCacheBuilt() == true) + Cand = Cache[Pkg].CandidateVerIter(Cache); + else { + if (unlikely(Cache.BuildPolicy() == false)) + return pkgCache::VerIterator(*Cache); + Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); + } + if (AllowError == false && Cand.end() == true) + _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); + return Cand; +} + /*}}}*/ +// getInstalledVer - Returns the installed version of the given package /*{{{*/ +pkgCache::VerIterator VersionSet::getInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError) { + if (AllowError == false && Pkg->CurrentVer == 0) + _error->Error(_("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); + return Pkg.CurrentVer(); +} + /*}}}*/ +} diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h new file mode 100644 index 000000000..2bc268380 --- /dev/null +++ b/cmdline/cacheset.h @@ -0,0 +1,274 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/** \file cacheset.h + Wrappers around std::set to have set::iterators which behave + similar to the Iterators of the cache structures. + + Provides also a few helper methods which work with these sets */ + /*}}}*/ +#ifndef APT_CACHESET_H +#define APT_CACHESET_H +// Include Files /*{{{*/ +#include +#include +#include +#include +#include +#include + +#include +#include + /*}}}*/ +namespace APT { +class PackageSet : public std::set { /*{{{*/ +/** \class APT::PackageSet + + Simple wrapper around a std::set to provide a similar interface to + a set of packages as to the complete set of all packages in the + pkgCache. */ +public: /*{{{*/ + /** \brief smell like a pkgCache::PkgIterator */ + class const_iterator : public std::set::const_iterator { + public: + const_iterator(std::set::const_iterator x) : + std::set::const_iterator(x) {} + + operator pkgCache::PkgIterator(void) { return **this; } + + inline const char *Name() const {return (**this).Name(); } + inline std::string FullName(bool const &Pretty) const { return (**this).FullName(Pretty); } + inline std::string FullName() const { return (**this).FullName(); } + inline const char *Section() const {return (**this).Section(); } + inline bool Purge() const {return (**this).Purge(); } + inline const char *Arch() const {return (**this).Arch(); } + inline pkgCache::GrpIterator Group() const { return (**this).Group(); } + inline pkgCache::VerIterator VersionList() const { return (**this).VersionList(); } + inline pkgCache::VerIterator CurrentVer() const { return (**this).CurrentVer(); } + inline pkgCache::DepIterator RevDependsList() const { return (**this).RevDependsList(); } + inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); } + inline pkgCache::PkgIterator::OkState State() const { return (**this).State(); } + inline const char *CandVersion() const { return (**this).CandVersion(); } + inline const char *CurVersion() const { return (**this).CurVersion(); } + inline pkgCache *Cache() const { return (**this).Cache(); }; + inline unsigned long Index() const {return (**this).Index();}; + // we have only valid iterators here + inline bool end() const { return false; }; + + friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } + + inline pkgCache::Package const * operator->() const { + return &***this; + }; + }; + // 103. set::iterator is required to be modifiable, but this allows modification of keys + typedef APT::PackageSet::const_iterator iterator; + + using std::set::insert; + inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; + + /** \brief returns all packages in the cache whose name matchs a given pattern + + A simple helper responsible for executing a regular expression on all + package names in the cache. Optional it prints a a notice about the + packages chosen cause of the given package. + \param Cache the packages are in + \param pattern regular expression for package names + \param out stream to print the notice to */ + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromRegEx(Cache, pattern, out); + } + + /** \brief returns all packages specified by a string + + \param Cache the packages are in + \param string String the package name(s) should be extracted from + \param out stream to print various notices to */ + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, std::ostream &out); + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromString(Cache, string, out); + } + + /** \brief returns all packages specified on the commandline + + Get all package names from the commandline and executes regex's if needed. + No special package command is supported, just plain names. + \param Cache the packages are in + \param cmdline Command line the package names should be extracted from + \param out stream to print various notices to */ + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out); + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromCommandLine(Cache, cmdline, out); + } + + struct Modifier { + enum Position { NONE, PREFIX, POSTFIX }; + unsigned short ID; + const char * const Alias; + Position Pos; + Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; + }; + + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, std::ostream &out); + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, + mods, fallback, out); + } + /*}}}*/ +}; /*}}}*/ +class VersionSet : public std::set { /*{{{*/ +/** \class APT::VersionSet + + Simple wrapper around a std::set to provide a similar interface to + a set of versions as to the complete set of all versions in the + pkgCache. */ +public: /*{{{*/ + /** \brief smell like a pkgCache::VerIterator */ + class const_iterator : public std::set::const_iterator { + public: + const_iterator(std::set::const_iterator x) : + std::set::const_iterator(x) {} + + operator pkgCache::VerIterator(void) { return **this; } + + inline pkgCache *Cache() const { return (**this).Cache(); }; + inline unsigned long Index() const {return (**this).Index();}; + // we have only valid iterators here + inline bool end() const { return false; }; + + inline pkgCache::Version const * operator->() const { + return &***this; + }; + + inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); }; + inline const char *VerStr() const { return (**this).VerStr(); }; + inline const char *Section() const { return (**this).Section(); }; + inline const char *Arch() const { return (**this).Arch(); }; + inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); }; + inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); }; + inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); }; + inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); }; + inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); }; + inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }; + inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); }; + inline bool Downloadable() const { return (**this).Downloadable(); }; + inline const char *PriorityType() const { return (**this).PriorityType(); }; + inline string RelStr() const { return (**this).RelStr(); }; + inline bool Automatic() const { return (**this).Automatic(); }; + inline bool Pseudo() const { return (**this).Pseudo(); }; + inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); }; + }; + // 103. set::iterator is required to be modifiable, but this allows modification of keys + typedef APT::VersionSet::const_iterator iterator; + + using std::set::insert; + inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set::insert(V); }; + + /** \brief specifies which version(s) will be returned if non is given */ + enum Version { + /** All versions */ + ALL, + /** Candidate and installed version */ + CANDANDINST, + /** Candidate version */ + CANDIDATE, + /** Installed version */ + INSTALLED, + /** Candidate or if non installed version */ + CANDINST, + /** Installed or if non candidate version */ + INSTCAND, + /** Newest version */ + NEWEST + }; + + /** \brief returns all versions specified on the commandline + + Get all versions from the commandline, uses given default version if + non specifically requested and executes regex's if needed on names. + \param Cache the packages and versions are in + \param cmdline Command line the versions should be extracted from + \param out stream to print various notices to */ + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback, std::ostream &out); + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, out); + } + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { + return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); + } + + static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, + APT::VersionSet::Version const &fallback, std::ostream &out); + static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, + APT::VersionSet::Version const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::VersionSet::FromString(Cache, pkg, fallback, out); + } + static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg) { + return APT::VersionSet::FromString(Cache, pkg, CANDINST); + } + + struct Modifier { + enum Position { NONE, PREFIX, POSTFIX }; + unsigned short ID; + const char * const Alias; + Position Pos; + VersionSet::Version SelectVersion; + Modifier (unsigned short const &id, const char * const alias, Position const &pos, + VersionSet::Version const &select) : ID(id), Alias(alias), Pos(pos), + SelectVersion(select) {}; + }; + + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, std::ostream &out); + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::VersionSet::GroupedFromCommandLine(Cache, cmdline, + mods, fallback, out); + } + /*}}}*/ +protected: /*{{{*/ + + /** \brief returns the candidate version of the package + + \param Cache to be used to query for information + \param Pkg we want the candidate version from this package + \param AllowError add an error to the stack if not */ + static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + + /** \brief returns the installed version of the package + + \param Cache to be used to query for information + \param Pkg we want the installed version from this package + \param AllowError add an error to the stack if not */ + static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + + + static bool AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, + pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, + bool const &AllowError = false); + + /*}}}*/ +}; /*}}}*/ +} +#endif diff --git a/cmdline/makefile b/cmdline/makefile index 917ccc96a..4ffe49ee0 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -9,14 +9,14 @@ include ../buildlib/defaults.mak PROGRAM=apt-cache SLIBS = -lapt-pkg $(INTLLIBS) LIB_MAKES = apt-pkg/makefile -SOURCE = apt-cache.cc +SOURCE = apt-cache.cc cacheset.cc include $(PROGRAM_H) # The apt-get program PROGRAM=apt-get SLIBS = -lapt-pkg -lutil $(INTLLIBS) LIB_MAKES = apt-pkg/makefile -SOURCE = apt-get.cc acqprogress.cc +SOURCE = apt-get.cc acqprogress.cc cacheset.cc include $(PROGRAM_H) # The apt-config program -- cgit v1.2.3 From dc0f01f7cbe2ed8ae6a1d2dbc0e00c19bb04679d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 19 Jun 2010 11:49:38 +0200 Subject: get packages by task^ with FromTask() --- cmdline/cacheset.cc | 76 ++++++++++++++++++++++++++++++++++++++++++++++++----- cmdline/cacheset.h | 20 ++++++++++++-- 2 files changed, 87 insertions(+), 9 deletions(-) (limited to 'cmdline') diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index fde52168a..55ab26780 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -11,27 +11,83 @@ // Include Files /*{{{*/ #include #include -#include #include #include #include +#include "cacheset.h" + #include #include /*}}}*/ namespace APT { +// FromTask - Return all packages in the cache from a specific task /*{{{*/ +PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, std::ostream &out) { + PackageSet pkgset; + if (Cache.BuildCaches() == false || Cache.BuildDepCache() == false) + return pkgset; + + size_t archfound = pattern.find_last_of(':'); + std::string arch = "native"; + if (archfound != std::string::npos) { + arch = pattern.substr(archfound+1); + pattern.erase(archfound); + } + + if (pattern[pattern.length() -1] != '^') + return pkgset; + pattern.erase(pattern.length()-1); + + // get the records + pkgRecords Recs(Cache); + + // build regexp for the task + regex_t Pattern; + char S[300]; + snprintf(S, sizeof(S), "^Task:.*[, ]%s([, ]|$)", pattern.c_str()); + if(regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0) { + _error->Error("Failed to compile task regexp"); + return pkgset; + } + + for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) { + pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); + if (Pkg.end() == true) + continue; + pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache); + if(ver.end() == true) + continue; + + pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); + const char *start, *end; + parser.GetRec(start,end); + unsigned int const length = end - start; + char buf[length]; + strncpy(buf, start, length); + buf[length-1] = '\0'; + if (regexec(&Pattern, buf, 0, 0, 0) == 0) + pkgset.insert(Pkg); + } + + if (pkgset.empty() == true) + _error->Error(_("Couldn't find task %s"), pattern.c_str()); + + regfree(&Pattern); + return pkgset; +} + /*}}}*/ // FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out) { PackageSet pkgset; - std::string arch = "native"; static const char * const isregex = ".?+*|[^$"; if (pattern.find_first_of(isregex) == std::string::npos) return pkgset; size_t archfound = pattern.find_last_of(':'); + std::string arch = "native"; if (archfound != std::string::npos) { arch = pattern.substr(archfound+1); if (arch.find_first_of(isregex) == std::string::npos) @@ -142,10 +198,16 @@ PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, s pkgset.insert(Pkg); return pkgset; } - PackageSet regex = FromRegEx(Cache, str, out); - if (regex.empty() == true) - _error->Warning(_("Unable to locate package %s"), str.c_str()); - return regex; + PackageSet pset = FromTask(Cache, str, out); + if (pset.empty() == false) + return pset; + + pset = FromRegEx(Cache, str, out); + if (pset.empty() == false) + return pset; + + _error->Warning(_("Unable to locate package %s"), str.c_str()); + return pset; } /*}}}*/ // GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ @@ -236,7 +298,7 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, } if (V.end() == true) continue; - if (ver == V.VerStr()) + if (ver != V.VerStr()) ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"), V.VerStr(), V.RelStr().c_str(), P.FullName(true).c_str()); verset.insert(V); diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 2bc268380..64a72e758 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -28,7 +28,7 @@ class PackageSet : public std::set { /*{{{*/ pkgCache. */ public: /*{{{*/ /** \brief smell like a pkgCache::PkgIterator */ - class const_iterator : public std::set::const_iterator { + class const_iterator : public std::set::const_iterator {/*{{{*/ public: const_iterator(std::set::const_iterator x) : std::set::const_iterator(x) {} @@ -62,10 +62,25 @@ public: /*{{{*/ }; // 103. set::iterator is required to be modifiable, but this allows modification of keys typedef APT::PackageSet::const_iterator iterator; + /*}}}*/ using std::set::insert; inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; + /** \brief returns all packages in the cache who belong to the given task + + A simple helper responsible for search for all members of a task + in the cache. Optional it prints a a notice about the + packages chosen cause of the given task. + \param Cache the packages are in + \param pattern name of the task + \param out stream to print the notice to */ + static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromTask(Cache, pattern, out); + } + /** \brief returns all packages in the cache whose name matchs a given pattern A simple helper responsible for executing a regular expression on all @@ -134,7 +149,7 @@ class VersionSet : public std::set { /*{{{*/ pkgCache. */ public: /*{{{*/ /** \brief smell like a pkgCache::VerIterator */ - class const_iterator : public std::set::const_iterator { + class const_iterator : public std::set::const_iterator {/*{{{*/ public: const_iterator(std::set::const_iterator x) : std::set::const_iterator(x) {} @@ -168,6 +183,7 @@ public: /*{{{*/ inline bool Pseudo() const { return (**this).Pseudo(); }; inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); }; }; + /*}}}*/ // 103. set::iterator is required to be modifiable, but this allows modification of keys typedef APT::VersionSet::const_iterator iterator; -- cgit v1.2.3 From 313678129b6f8ad37216db0b4e7679059ab37e56 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 19 Jun 2010 14:16:40 +0200 Subject: * cmdline/apt-get.cc: - use the cachsets in the install commands --- cmdline/apt-cache.cc | 3 +- cmdline/apt-get.cc | 249 ++++++++++----------------------------------------- 2 files changed, 49 insertions(+), 203 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 7cb95b3f8..2332a0f13 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -29,7 +29,8 @@ #include #include #include -#include + +#include "cacheset.h" #include #include diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 0ada46c73..c081ca130 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -40,12 +40,12 @@ #include #include #include -#include #include #include #include "acqprogress.h" +#include "cacheset.h" #include #include @@ -1252,41 +1252,6 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, if ((State.InstBroken() == true || State.InstPolicyBroken() == 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.FullName(true).c_str()); - return _error->Error(_("Version '%s' for '%s' was not found"), - VerTag,Pkg.FullName(true).c_str()); - } - - if (strcmp(VerTag,Ver.VerStr()) != 0) - { - ioprintf(c1out,_("Selected version %s (%s) for %s\n"), - Ver.VerStr(),Ver.RelStr().c_str(),Pkg.FullName(true).c_str()); - } - - Cache.SetCandidateVersion(Ver); - - // Set the all package to the same candidate - if (Ver.Pseudo() == true) - Cache.SetCandidateVersion(Match.Find(Pkg.Group().FindPkg("all"))); - return true; } /*}}}*/ @@ -1624,61 +1589,6 @@ bool DoUpgrade(CommandLine &CmdL) return InstallPackages(Cache,true); } /*}}}*/ -// DoInstallTask - Install task from the command line /*{{{*/ -// --------------------------------------------------------------------- -/* Install named task */ -bool TryInstallTask(pkgDepCache &Cache, pkgProblemResolver &Fix, - bool BrokenFix, - unsigned int& ExpectedInst, - const char *taskname, - bool Remove) -{ - const char *start, *end; - pkgCache::PkgIterator Pkg; - char buf[64*1024]; - regex_t Pattern; - - // get the records - pkgRecords Recs(Cache); - - // build regexp for the task - char S[300]; - snprintf(S, sizeof(S), "^Task:.*[, ]%s([, ]|$)", taskname); - if(regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0) - return _error->Error("Failed to compile task regexp"); - - bool found = false; - bool res = true; - - // two runs, first ignore dependencies, second install any missing - for(int IgnoreBroken=1; IgnoreBroken >= 0; IgnoreBroken--) - { - for (Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) - { - pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache); - if(ver.end()) - continue; - pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); - parser.GetRec(start,end); - strncpy(buf, start, end-start); - buf[end-start] = 0x0; - if (regexec(&Pattern,buf,0,0,0) != 0) - continue; - res &= TryToInstall(Pkg,Cache,Fix,Remove,IgnoreBroken,ExpectedInst); - found = true; - } - } - - // now let the problem resolver deal with any issues - Fix.Resolve(true); - - if(!found) - _error->Error(_("Couldn't find task %s"),taskname); - - regfree(&Pattern); - return res; -} - /*}}}*/ // DoInstall - Install packages from the command line /*{{{*/ // --------------------------------------------------------------------- /* Install named packages */ @@ -1696,138 +1606,73 @@ bool DoInstall(CommandLine &CmdL) unsigned int AutoMarkChanged = 0; unsigned int ExpectedInst = 0; - unsigned int Packages = 0; pkgProblemResolver Fix(Cache); - - bool DefRemove = false; + + unsigned short fallback = 0; if (strcasecmp(CmdL.FileList[0],"remove") == 0) - DefRemove = true; + fallback = 1; else if (strcasecmp(CmdL.FileList[0], "purge") == 0) { _config->Set("APT::Get::Purge", true); - DefRemove = true; + fallback = 1; } else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0) { _config->Set("APT::Get::AutomaticRemove", "true"); - DefRemove = true; + fallback = 1; } // new scope for the ActionGroup { + // TODO: Howto get an ExpectedInst count ? pkgDepCache::ActionGroup group(Cache); - for (const char **I = CmdL.FileList + 1; *I != 0; I++) - { - // Duplicate the string - unsigned int Length = strlen(*I); - char S[300]; - if (Length >= sizeof(S)) - continue; - strcpy(S,*I); - - // See if we are removing and special indicators.. - bool Remove = DefRemove; - char *VerTag = 0; - bool VerIsRel = false; + std::list mods; + mods.push_back(APT::VersionSet::Modifier(0, "+", + APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDINST)); + mods.push_back(APT::VersionSet::Modifier(1, "-", + APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::INSTCAND)); + std::map verset = APT::VersionSet::GroupedFromCommandLine(Cache, + CmdL.FileList + 1, mods, fallback, c0out); - // this is a task! - if (Length >= 1 && S[Length - 1] == '^') - { - S[--Length] = 0; - // tasks must always be confirmed - ExpectedInst += 1000; - // see if we can install it - TryInstallTask(Cache, Fix, BrokenFix, ExpectedInst, S, Remove); - continue; - } + if (_error->PendingError() == true) + return false; - while (Cache->FindPkg(S).end() == true) + for (APT::VersionSet::const_iterator Ver = verset[0].begin(); + Ver != verset[0].end(); ++Ver) + { + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + Cache->SetCandidateVersion(Ver); + + if (TryToInstall(Pkg, Cache, Fix, false, 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 (Cache[Pkg].Install() == false && + (Cache[Pkg].Flags & pkgCache::Flag::Auto) && + _config->FindB("APT::Get::ReInstall",false) == false && + _config->FindB("APT::Get::Only-Upgrade",false) == false && + _config->FindB("APT::Get::Download-Only",false) == false) { - // Handle an optional end tag indicating what to do - if (Length >= 1 && S[Length - 1] == '-') - { - Remove = true; - S[--Length] = 0; - continue; - } - - if (Length >= 1 && S[Length - 1] == '+') - { - Remove = false; - S[--Length] = 0; - continue; - } - - char *Slash = strchr(S,'='); - if (Slash != 0) - { - VerIsRel = false; - *Slash = 0; - VerTag = Slash + 1; - } - - Slash = strchr(S,'/'); - if (Slash != 0) - { - VerIsRel = true; - *Slash = 0; - VerTag = Slash + 1; - } - - break; + ioprintf(c1out,_("%s set to manually installed.\n"), + Pkg.FullName(true).c_str()); + Cache->MarkAuto(Pkg,false); + AutoMarkChanged++; } - - // Locate the package - pkgCache::PkgIterator Pkg = Cache->FindPkg(S); - Packages++; - if (Pkg.end() == true) - { - APT::PackageSet pkgset = APT::PackageSet::FromRegEx(Cache, S, c1out); - if (pkgset.empty() == true) - return _error->Error(_("Couldn't find package %s"),S); - - // Regexs must always be confirmed - ExpectedInst += 1000; - - bool Hit = false; - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - { - if (VerTag != 0) - if (TryToChangeVer(Pkg,Cache,VerTag,VerIsRel) == false) - return false; + } - Hit |= TryToInstall(Pkg,Cache,Fix,Remove,BrokenFix, - ExpectedInst,false); - } + for (APT::VersionSet::const_iterator Ver = verset[1].begin(); + Ver != verset[1].end(); ++Ver) + { + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - if (Hit == false) - return _error->Error(_("Couldn't find package %s"),S); - } - else - { - if (VerTag != 0) - if (TryToChangeVer(Pkg,Cache,VerTag,VerIsRel) == false) - 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) && - _config->FindB("APT::Get::ReInstall",false) == false && - _config->FindB("APT::Get::Only-Upgrade",false) == false && - _config->FindB("APT::Get::Download-Only",false) == false) - { - ioprintf(c1out,_("%s set to manually installed.\n"), - Pkg.FullName(true).c_str()); - Cache->MarkAuto(Pkg,false); - AutoMarkChanged++; - } - } + if (TryToInstall(Pkg, Cache, Fix, true, BrokenFix, ExpectedInst) == false) + return false; } + if (_error->PendingError() == true) + return false; + /* If we are in the Broken fixing mode we do not attempt to fix the problems. This is if the user invoked install without -f and gave packages */ -- cgit v1.2.3 From 70e706adf75ed319d931a220ce27db2b981093f5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 22 Jun 2010 18:01:11 +0200 Subject: =?UTF-8?q?Use=20an=20abstract=20helper=20for=20error=20handling?= =?UTF-8?q?=20and=20output=20instead=20of=20doing=20this=20directly=20in?= =?UTF-8?q?=20the=20CacheSets.=20With=20this=20method=20an=20application?= =?UTF-8?q?=20like=20apt-get=20can=20change=20the=20behavior=20of=20the=20?= =?UTF-8?q?CacheSets=20to=20his=20liking.=20It=20can=20for=20example=20eas?= =?UTF-8?q?ily=20keep=20track=20of=20how=20packages=20were=20added=20to=20?= =?UTF-8?q?the=20set:=20by=20names=20or=20with=20regex's=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmdline/apt-get.cc | 79 ++++++++++++++++------- cmdline/cacheset.cc | 179 ++++++++++++++++++++++++++++++++++------------------ cmdline/cacheset.h | 104 ++++++++++++++++++++---------- 3 files changed, 244 insertions(+), 118 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index c081ca130..6a7d7a448 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1079,7 +1079,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, 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) + bool AllowFail = true) { /* This is a pure virtual package and there is a single available candidate providing it. */ @@ -1244,9 +1244,7 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, Pkg.FullName(true).c_str()); } } - else - ExpectedInst++; - + // Install it with autoinstalling enabled (if we not respect the minial // required deps or the policy) if ((State.InstBroken() == true || State.InstPolicyBroken() == true) && BrokenFix == false) @@ -1589,6 +1587,41 @@ bool DoUpgrade(CommandLine &CmdL) return InstallPackages(Cache,true); } /*}}}*/ +// CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/ +class CacheSetHelperAPTGet : public APT::CacheSetHelper { + /** \brief stream message should be printed to */ + std::ostream &out; + /** \brief were things like Task or RegEx used to select packages? */ + bool explicitlyNamed; + +public: + CacheSetHelperAPTGet(std::ostream &out) : APT::CacheSetHelper(true), out(out) { + explicitlyNamed = true; + } + + virtual void showTaskSelection(APT::PackageSet const &pkgset, string const &pattern) { + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + ioprintf(out, _("Note, selecting %s for task '%s'\n"), + Pkg.FullName(true).c_str(), pattern.c_str()); + explicitlyNamed = false; + } + virtual void showRegExSelection(APT::PackageSet const &pkgset, string const &pattern) { + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + ioprintf(out, _("Note, selecting %s for regex '%s'\n"), + Pkg.FullName(true).c_str(), pattern.c_str()); + explicitlyNamed = false; + } + 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()); + } + + inline bool allPkgNamedExplicitly() const { return explicitlyNamed; } + +}; + /*}}}*/ // DoInstall - Install packages from the command line /*{{{*/ // --------------------------------------------------------------------- /* Install named packages */ @@ -1605,7 +1638,6 @@ bool DoInstall(CommandLine &CmdL) BrokenFix = true; unsigned int AutoMarkChanged = 0; - unsigned int ExpectedInst = 0; pkgProblemResolver Fix(Cache); unsigned short fallback = 0; @@ -1621,28 +1653,29 @@ bool DoInstall(CommandLine &CmdL) _config->Set("APT::Get::AutomaticRemove", "true"); fallback = 1; } - // new scope for the ActionGroup - { - // TODO: Howto get an ExpectedInst count ? - pkgDepCache::ActionGroup group(Cache); - std::list mods; - mods.push_back(APT::VersionSet::Modifier(0, "+", + + std::list mods; + mods.push_back(APT::VersionSet::Modifier(0, "+", APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDINST)); - mods.push_back(APT::VersionSet::Modifier(1, "-", + mods.push_back(APT::VersionSet::Modifier(1, "-", APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::INSTCAND)); - std::map verset = APT::VersionSet::GroupedFromCommandLine(Cache, - CmdL.FileList + 1, mods, fallback, c0out); + CacheSetHelperAPTGet helper(c0out); + std::map verset = APT::VersionSet::GroupedFromCommandLine(Cache, + CmdL.FileList + 1, mods, fallback, helper); - if (_error->PendingError() == true) - return false; + if (_error->PendingError() == true) + return false; + // new scope for the ActionGroup + { + pkgDepCache::ActionGroup group(Cache); for (APT::VersionSet::const_iterator Ver = verset[0].begin(); Ver != verset[0].end(); ++Ver) { pkgCache::PkgIterator Pkg = Ver.ParentPkg(); Cache->SetCandidateVersion(Ver); - if (TryToInstall(Pkg, Cache, Fix, false, BrokenFix, ExpectedInst) == false) + if (TryToInstall(Pkg, Cache, Fix, false, BrokenFix) == false) return false; // see if we need to fix the auto-mark flag @@ -1666,7 +1699,7 @@ bool DoInstall(CommandLine &CmdL) { pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - if (TryToInstall(Pkg, Cache, Fix, true, BrokenFix, ExpectedInst) == false) + if (TryToInstall(Pkg, Cache, Fix, true, BrokenFix) == false) return false; } @@ -1719,7 +1752,7 @@ bool DoInstall(CommandLine &CmdL) /* Print out a list of packages that are going to be installed extra to what the user asked */ - if (Cache->InstCount() != ExpectedInst) + if (Cache->InstCount() != verset[0].size()) { string List; string VersionsList; @@ -1845,7 +1878,8 @@ bool DoInstall(CommandLine &CmdL) Cache->writeStateFile(NULL); // See if we need to prompt - if (Cache->InstCount() == ExpectedInst && Cache->DelCount() == 0) + // FIXME: check if really the packages in the set are going to be installed + if (Cache->InstCount() == verset[0].size() && Cache->DelCount() == 0) return InstallPackages(Cache,false,false); return InstallPackages(Cache,false); @@ -2429,7 +2463,6 @@ bool DoBuildDep(CommandLine &CmdL) } // Install the requested packages - unsigned int ExpectedInst = 0; vector ::iterator D; pkgProblemResolver Fix(Cache); bool skipAlternatives = false; // skip remaining alternatives in an or group @@ -2460,7 +2493,7 @@ bool DoBuildDep(CommandLine &CmdL) */ if (IV.end() == false && Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) - TryToInstall(Pkg,Cache,Fix,true,false,ExpectedInst); + TryToInstall(Pkg,Cache,Fix,true,false); } else // BuildDep || BuildDepIndep { @@ -2576,7 +2609,7 @@ bool DoBuildDep(CommandLine &CmdL) if (_config->FindB("Debug::BuildDeps",false) == true) cout << " Trying to install " << (*D).Package << endl; - if (TryToInstall(Pkg,Cache,Fix,false,false,ExpectedInst) == true) + if (TryToInstall(Pkg,Cache,Fix,false,false) == true) { // We successfully installed something; skip remaining alternatives skipAlternatives = hasAlternatives; diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index 55ab26780..88a98fdbe 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -24,7 +24,7 @@ /*}}}*/ namespace APT { // FromTask - Return all packages in the cache from a specific task /*{{{*/ -PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, std::ostream &out) { +PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { PackageSet pkgset; if (Cache.BuildCaches() == false || Cache.BuildDepCache() == false) return pkgset; @@ -67,19 +67,22 @@ PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, std::o char buf[length]; strncpy(buf, start, length); buf[length-1] = '\0'; - if (regexec(&Pattern, buf, 0, 0, 0) == 0) - pkgset.insert(Pkg); + if (regexec(&Pattern, buf, 0, 0, 0) != 0) + continue; + + pkgset.insert(Pkg); } + regfree(&Pattern); if (pkgset.empty() == true) - _error->Error(_("Couldn't find task %s"), pattern.c_str()); + return helper.canNotFindTask(Cache, pattern); - regfree(&Pattern); + helper.showTaskSelection(pkgset, pattern); return pkgset; } /*}}}*/ // FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ -PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out) { +PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { PackageSet pkgset; static const char * const isregex = ".?+*|[^$"; @@ -121,14 +124,14 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, std:: continue; } - ioprintf(out, _("Note, selecting %s for regex '%s'\n"), - Pkg.FullName(true).c_str(), pattern.c_str()); - pkgset.insert(Pkg); } - regfree(&Pattern); + if (pkgset.empty() == true) + return helper.canNotFindRegEx(Cache, pattern); + + helper.showRegExSelection(pkgset, pattern); return pkgset; } /*}}}*/ @@ -136,7 +139,7 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, std:: std::map PackageSet::GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, - unsigned short const &fallback, std::ostream &out) { + unsigned short const &fallback, CacheSetHelper &helper) { std::map pkgsets; for (const char **I = cmdline; *I != 0; ++I) { unsigned short modID = fallback; @@ -159,24 +162,23 @@ std::map PackageSet::GroupedFromCommandLine( } break; } - PackageSet pset = PackageSet::FromString(Cache, str, out); - pkgsets[modID].insert(pset.begin(), pset.end()); + pkgsets[modID].insert(PackageSet::FromString(Cache, str, helper)); } return pkgsets; } /*}}}*/ // FromCommandLine - Return all packages specified on commandline /*{{{*/ -PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out) { +PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { PackageSet pkgset; for (const char **I = cmdline; *I != 0; ++I) { - PackageSet pset = FromString(Cache, *I, out); + PackageSet pset = FromString(Cache, *I, helper); pkgset.insert(pset.begin(), pset.end()); } return pkgset; } /*}}}*/ // FromString - Return all packages matching a specific string /*{{{*/ -PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, std::ostream &out) { +PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) { std::string pkg = str; size_t archfound = pkg.find_last_of(':'); std::string arch; @@ -198,23 +200,22 @@ PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, s pkgset.insert(Pkg); return pkgset; } - PackageSet pset = FromTask(Cache, str, out); + PackageSet pset = FromTask(Cache, str, helper); if (pset.empty() == false) return pset; - pset = FromRegEx(Cache, str, out); + pset = FromRegEx(Cache, str, helper); if (pset.empty() == false) return pset; - _error->Warning(_("Unable to locate package %s"), str.c_str()); - return pset; + return helper.canNotFindPackage(Cache, str); } /*}}}*/ // GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ std::map VersionSet::GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, - unsigned short const &fallback, std::ostream &out) { + unsigned short const &fallback, CacheSetHelper &helper) { std::map versets; for (const char **I = cmdline; *I != 0; ++I) { unsigned short modID = fallback; @@ -241,18 +242,17 @@ std::map VersionSet::GroupedFromCommandLine( } break; } - VersionSet vset = VersionSet::FromString(Cache, str, select , out); - versets[modID].insert(vset.begin(), vset.end()); + versets[modID].insert(VersionSet::FromString(Cache, str, select , helper)); } return versets; } /*}}}*/ // FromCommandLine - Return all versions specified on commandline /*{{{*/ APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - APT::VersionSet::Version const &fallback, std::ostream &out) { + APT::VersionSet::Version const &fallback, CacheSetHelper &helper) { VersionSet verset; for (const char **I = cmdline; *I != 0; ++I) { - VersionSet vset = VersionSet::FromString(Cache, *I, fallback, out); + VersionSet vset = VersionSet::FromString(Cache, *I, fallback, helper); verset.insert(vset.begin(), vset.end()); } return verset; @@ -260,7 +260,7 @@ APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cm /*}}}*/ // FromString - Returns all versions spedcified by a string /*{{{*/ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, std::ostream &out) { + APT::VersionSet::Version const &fallback, CacheSetHelper &helper) { std::string ver; bool verIsRel = false; size_t const vertag = pkg.find_last_of("/="); @@ -269,19 +269,19 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, verIsRel = (pkg[vertag] == '/'); pkg.erase(vertag); } - PackageSet pkgset = PackageSet::FromString(Cache, pkg.c_str(), out); + PackageSet pkgset = PackageSet::FromString(Cache, pkg.c_str(), helper); VersionSet verset; for (PackageSet::const_iterator P = pkgset.begin(); P != pkgset.end(); ++P) { if (vertag == string::npos) { - AddSelectedVersion(Cache, verset, P, fallback); + AddSelectedVersion(Cache, verset, P, fallback, helper); continue; } pkgCache::VerIterator V; if (ver == "installed") - V = getInstalledVer(Cache, P); + V = getInstalledVer(Cache, P, helper); else if (ver == "candidate") - V = getCandidateVer(Cache, P); + V = getCandidateVer(Cache, P, helper); else { pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : pkgVersionMatch::Version)); @@ -298,76 +298,70 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, } if (V.end() == true) continue; - if (ver != V.VerStr()) - ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"), - V.VerStr(), V.RelStr().c_str(), P.FullName(true).c_str()); + helper.showSelectedVersion(P, V, ver, verIsRel); verset.insert(V); } return verset; } /*}}}*/ // AddSelectedVersion - add version from package based on fallback /*{{{*/ -bool VersionSet::AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, +void VersionSet::AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, - bool const &AllowError) { + CacheSetHelper &helper) { pkgCache::VerIterator V; + bool showErrors; switch(fallback) { case VersionSet::ALL: if (P->VersionList != 0) for (V = P.VersionList(); V.end() != true; ++V) verset.insert(V); - else if (AllowError == false) - return _error->Error(_("Can't select versions from package '%s' as it purely virtual"), P.FullName(true).c_str()); else - return false; + verset.insert(helper.canNotFindAllVer(Cache, P)); break; case VersionSet::CANDANDINST: - verset.insert(getInstalledVer(Cache, P, AllowError)); - verset.insert(getCandidateVer(Cache, P, AllowError)); + verset.insert(getInstalledVer(Cache, P, helper)); + verset.insert(getCandidateVer(Cache, P, helper)); break; case VersionSet::CANDIDATE: - verset.insert(getCandidateVer(Cache, P, AllowError)); + verset.insert(getCandidateVer(Cache, P, helper)); break; case VersionSet::INSTALLED: - verset.insert(getInstalledVer(Cache, P, AllowError)); + verset.insert(getInstalledVer(Cache, P, helper)); break; case VersionSet::CANDINST: - V = getCandidateVer(Cache, P, true); + showErrors = helper.showErrors(false); + V = getCandidateVer(Cache, P, helper); if (V.end() == true) - V = getInstalledVer(Cache, P, true); + V = getInstalledVer(Cache, P, helper); + helper.showErrors(showErrors); if (V.end() == false) verset.insert(V); - else if (AllowError == false) - return _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), P.FullName(true).c_str()); else - return false; + verset.insert(helper.canNotFindInstCandVer(Cache, P)); break; case VersionSet::INSTCAND: - V = getInstalledVer(Cache, P, true); + showErrors = helper.showErrors(false); + V = getInstalledVer(Cache, P, helper); if (V.end() == true) - V = getCandidateVer(Cache, P, true); + V = getCandidateVer(Cache, P, helper); + helper.showErrors(showErrors); if (V.end() == false) verset.insert(V); - else if (AllowError == false) - return _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), P.FullName(true).c_str()); else - return false; + verset.insert(helper.canNotFindInstCandVer(Cache, P)); break; case VersionSet::NEWEST: if (P->VersionList != 0) verset.insert(P.VersionList()); - else if (AllowError == false) - return _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), P.FullName(true).c_str()); else - return false; + verset.insert(helper.canNotFindNewestVer(Cache, P)); break; } - return true; } /*}}}*/ // getCandidateVer - Returns the candidate version of the given package /*{{{*/ pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, bool const &AllowError) { + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { pkgCache::VerIterator Cand; if (Cache.IsDepCacheBuilt() == true) Cand = Cache[Pkg].CandidateVerIter(Cache); @@ -376,17 +370,78 @@ pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, return pkgCache::VerIterator(*Cache); Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); } - if (AllowError == false && Cand.end() == true) - _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); + if (Cand.end() == true) + return helper.canNotFindCandidateVer(Cache, Pkg); return Cand; } /*}}}*/ // getInstalledVer - Returns the installed version of the given package /*{{{*/ pkgCache::VerIterator VersionSet::getInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, bool const &AllowError) { - if (AllowError == false && Pkg->CurrentVer == 0) - _error->Error(_("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { + if (Pkg->CurrentVer == 0) + return helper.canNotFindInstalledVer(Cache, Pkg); return Pkg.CurrentVer(); } /*}}}*/ +// canNotFindTask - handle the case no package is found for a task /*{{{*/ +PackageSet CacheSetHelper::canNotFindTask(pkgCacheFile &Cache, std::string pattern) { + if (ShowError == true) + _error->Error(_("Couldn't find task '%s'"), pattern.c_str()); + return PackageSet(); +} + /*}}}*/ +// canNotFindRegEx - handle the case no package is found by a regex /*{{{*/ +PackageSet CacheSetHelper::canNotFindRegEx(pkgCacheFile &Cache, std::string pattern) { + if (ShowError == true) + _error->Error(_("Couldn't find any package by regex '%s'"), pattern.c_str()); + return PackageSet(); +} + /*}}}*/ +// canNotFindPackage - handle the case no package is found from a string/*{{{*/ +PackageSet CacheSetHelper::canNotFindPackage(pkgCacheFile &Cache, std::string const &str) { + if (ShowError == true) + _error->Error(_("Unable to locate package %s"), str.c_str()); + return PackageSet(); +} + /*}}}*/ +// canNotFindAllVer /*{{{*/ +VersionSet CacheSetHelper::canNotFindAllVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select versions from package '%s' as it purely virtual"), Pkg.FullName(true).c_str()); + return VersionSet(); +} + /*}}}*/ +// canNotFindInstCandVer /*{{{*/ +VersionSet CacheSetHelper::canNotFindInstCandVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); + return VersionSet(); +} + /*}}}*/ +// canNotFindNewestVer /*{{{*/ +pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(*Cache); +} + /*}}}*/ +// canNotFindCandidateVer /*{{{*/ +pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(*Cache); +} + /*}}}*/ +// canNotFindInstalledVer /*{{{*/ +pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(*Cache); +} + /*}}}*/ } diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 64a72e758..9c9491020 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -20,6 +20,45 @@ #include /*}}}*/ namespace APT { +class PackageSet; +class VersionSet; +class CacheSetHelper { /*{{{*/ +/** \class APT::CacheSetHelper + Simple base class with a lot of virtual methods which can be overridden + to alter the behavior or the output of the CacheSets. + + This helper is passed around by the static methods in the CacheSets and + used every time they hit an error condition or something could be + printed out. +*/ +public: /*{{{*/ + CacheSetHelper(bool const &ShowError = true) : ShowError(ShowError) {}; + virtual ~CacheSetHelper() {}; + + virtual void showTaskSelection(PackageSet const &pkgset, string const &pattern) {}; + virtual void showRegExSelection(PackageSet const &pkgset, string const &pattern) {}; + virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, + string const &ver, bool const &verIsRel) {}; + + virtual PackageSet canNotFindTask(pkgCacheFile &Cache, std::string pattern); + virtual PackageSet canNotFindRegEx(pkgCacheFile &Cache, std::string pattern); + virtual PackageSet canNotFindPackage(pkgCacheFile &Cache, std::string const &str); + virtual VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + virtual VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + + bool showErrors() const { return ShowError; }; + bool showErrors(bool const &newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }; + /*}}}*/ +protected: + bool ShowError; +}; /*}}}*/ class PackageSet : public std::set { /*{{{*/ /** \class APT::PackageSet @@ -66,6 +105,7 @@ public: /*{{{*/ using std::set::insert; inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; + inline void insert(PackageSet const &pkgset) { insert(pkgset.begin(), pkgset.end()); }; /** \brief returns all packages in the cache who belong to the given task @@ -75,10 +115,10 @@ public: /*{{{*/ \param Cache the packages are in \param pattern name of the task \param out stream to print the notice to */ - static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromTask(Cache, pattern, out); + CacheSetHelper helper; + return APT::PackageSet::FromTask(Cache, pattern, helper); } /** \brief returns all packages in the cache whose name matchs a given pattern @@ -89,10 +129,10 @@ public: /*{{{*/ \param Cache the packages are in \param pattern regular expression for package names \param out stream to print the notice to */ - static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromRegEx(Cache, pattern, out); + CacheSetHelper helper; + return APT::PackageSet::FromRegEx(Cache, pattern, helper); } /** \brief returns all packages specified by a string @@ -100,10 +140,10 @@ public: /*{{{*/ \param Cache the packages are in \param string String the package name(s) should be extracted from \param out stream to print various notices to */ - static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, std::ostream &out); + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromString(Cache, string, out); + CacheSetHelper helper; + return APT::PackageSet::FromString(Cache, string, helper); } /** \brief returns all packages specified on the commandline @@ -113,10 +153,10 @@ public: /*{{{*/ \param Cache the packages are in \param cmdline Command line the package names should be extracted from \param out stream to print various notices to */ - static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out); + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromCommandLine(Cache, cmdline, out); + CacheSetHelper helper; + return APT::PackageSet::FromCommandLine(Cache, cmdline, helper); } struct Modifier { @@ -130,14 +170,14 @@ public: /*{{{*/ static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, - unsigned short const &fallback, std::ostream &out); + unsigned short const &fallback, CacheSetHelper &helper); static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, unsigned short const &fallback) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); + CacheSetHelper helper; return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, - mods, fallback, out); + mods, fallback, helper); } /*}}}*/ }; /*}}}*/ @@ -189,6 +229,7 @@ public: /*{{{*/ using std::set::insert; inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set::insert(V); }; + inline void insert(VersionSet const &verset) { insert(verset.begin(), verset.end()); }; /** \brief specifies which version(s) will be returned if non is given */ enum Version { @@ -216,22 +257,22 @@ public: /*{{{*/ \param cmdline Command line the versions should be extracted from \param out stream to print various notices to */ static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - APT::VersionSet::Version const &fallback, std::ostream &out); + APT::VersionSet::Version const &fallback, CacheSetHelper &helper); static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, APT::VersionSet::Version const &fallback) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, out); + CacheSetHelper helper; + return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, helper); } static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); } static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, std::ostream &out); + APT::VersionSet::Version const &fallback, CacheSetHelper &helper); static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, APT::VersionSet::Version const &fallback) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::VersionSet::FromString(Cache, pkg, fallback, out); + CacheSetHelper helper; + return APT::VersionSet::FromString(Cache, pkg, fallback, helper); } static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg) { return APT::VersionSet::FromString(Cache, pkg, CANDINST); @@ -251,14 +292,14 @@ public: /*{{{*/ static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, - unsigned short const &fallback, std::ostream &out); + unsigned short const &fallback, CacheSetHelper &helper); static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, unsigned short const &fallback) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); + CacheSetHelper helper; return APT::VersionSet::GroupedFromCommandLine(Cache, cmdline, - mods, fallback, out); + mods, fallback, helper); } /*}}}*/ protected: /*{{{*/ @@ -266,23 +307,20 @@ protected: /*{{{*/ /** \brief returns the candidate version of the package \param Cache to be used to query for information - \param Pkg we want the candidate version from this package - \param AllowError add an error to the stack if not */ + \param Pkg we want the candidate version from this package */ static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); /** \brief returns the installed version of the package \param Cache to be used to query for information - \param Pkg we want the installed version from this package - \param AllowError add an error to the stack if not */ + \param Pkg we want the installed version from this package */ static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); - + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); - static bool AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, + static void AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, - bool const &AllowError = false); + CacheSetHelper &helper); /*}}}*/ }; /*}}}*/ -- cgit v1.2.3 From c4fc2fd7fa0fc63fd8cd6bc9b73492e6baf0222a Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Thu, 24 Jun 2010 21:27:27 +0200 Subject: Switch FileFd to not transparently gunzip, since that breaks code which expects the compressed contents to stay (such as the copy backend, or when using file:// repositories. Instead, introduce a new ReadOnlyGzip mode and use that where needed --- cmdline/apt-cache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 3f68579cc..2b47184f9 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1220,7 +1220,7 @@ bool DisplayRecord(pkgCache::VerIterator V) if (I.IsOk() == false) return _error->Error(_("Package file %s is out of sync."),I.FileName()); - FileFd PkgF(I.FileName(),FileFd::ReadOnly); + FileFd PkgF(I.FileName(),FileFd::ReadOnlyGzip); if (_error->PendingError() == true) return false; -- cgit v1.2.3 From 65beb5720f82845bf175e0cd80f070da21838827 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 25 Jun 2010 20:11:11 +0200 Subject: print all messages if the application is in an interactive run --- cmdline/apt-cache.cc | 12 +++++------- cmdline/apt-cdrom.cc | 12 +++++------- cmdline/apt-get.cc | 12 +++++------- 3 files changed, 15 insertions(+), 21 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 2332a0f13..a4ec63eed 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1876,13 +1876,11 @@ int main(int argc,const char *argv[]) /*{{{*/ CmdL.DispatchArg(CmdsB); // Print any errors or warnings found during parsing - if (_error->empty() == false) - { - bool Errors = _error->PendingError(); + bool const Errors = _error->PendingError(); + if (_config->FindI("quiet",0) > 0) _error->DumpErrors(); - return Errors == true?100:0; - } - - return 0; + else + _error->DumpErrors(GlobalError::DEBUG); + return Errors == true ? 100 : 0; } /*}}}*/ diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index 8b9eacae6..da2ffa390 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -273,13 +273,11 @@ int main(int argc,const char *argv[]) /*{{{*/ CmdL.DispatchArg(Cmds); // Print any errors or warnings found during parsing - if (_error->empty() == false) - { - bool Errors = _error->PendingError(); + bool const Errors = _error->PendingError(); + if (_config->FindI("quiet",0) > 0) _error->DumpErrors(); - return Errors == true?100:0; - } - - return 0; + else + _error->DumpErrors(GlobalError::DEBUG); + return Errors == true ? 100 : 0; } /*}}}*/ diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 6a7d7a448..605eedb0f 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2920,13 +2920,11 @@ int main(int argc,const char *argv[]) /*{{{*/ CmdL.DispatchArg(Cmds); // Print any errors or warnings found during parsing - if (_error->empty() == false) - { - bool Errors = _error->PendingError(); + bool const Errors = _error->PendingError(); + if (_config->FindI("quiet",0) > 0) _error->DumpErrors(); - return Errors == true?100:0; - } - - return 0; + else + _error->DumpErrors(GlobalError::DEBUG); + return Errors == true ? 100 : 0; } /*}}}*/ -- cgit v1.2.3 From c340d1851242e691e7e0baad18a662d6c7a62bc8 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 26 Jun 2010 19:04:20 +0200 Subject: do not override the user set quiet setting even if the target is not a tty --- cmdline/apt-cache.cc | 2 +- cmdline/apt-cdrom.cc | 2 +- cmdline/apt-get.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index a4ec63eed..a5b3141d7 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1868,7 +1868,7 @@ int main(int argc,const char *argv[]) /*{{{*/ } // Deal with stdout not being a tty - if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1) + if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) _config->Set("quiet","1"); // if (_config->FindB("APT::Cache::Generate",true) == false) diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index da2ffa390..d1268edf9 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -266,7 +266,7 @@ int main(int argc,const char *argv[]) /*{{{*/ return ShowHelp(); // Deal with stdout not being a tty - if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1) + if (isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) _config->Set("quiet","1"); // Match the operation diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 605eedb0f..e3477b6db 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2899,7 +2899,7 @@ int main(int argc,const char *argv[]) /*{{{*/ } // Deal with stdout not being a tty - if (!isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1) + if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) _config->Set("quiet","1"); // Setup the output streams -- cgit v1.2.3 From 320352e00477f3b0cfd12efd736bd08c7908fecc Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 26 Jun 2010 19:22:23 +0200 Subject: give the APT::Cache::Generate option her effect back --- cmdline/apt-cache.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index a5b3141d7..c790559e7 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1871,7 +1871,9 @@ int main(int argc,const char *argv[]) /*{{{*/ if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) _config->Set("quiet","1"); -// if (_config->FindB("APT::Cache::Generate",true) == false) + if (_config->Exists("APT::Cache::Generate") == true) + _config->Set("pkgCacheFile::Generate", _config->FindB("APT::Cache::Generate", true)); + if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false) CmdL.DispatchArg(CmdsB); -- cgit v1.2.3 From 48c39e3246b72802a6f723eef1ce0c30e06be33d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 26 Jun 2010 21:17:34 +0200 Subject: - only print errors if all tries to get a package by string failed * --- cmdline/cacheset.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'cmdline') diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index 88a98fdbe..2b00187d8 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -200,15 +200,21 @@ PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, C pkgset.insert(Pkg); return pkgset; } + + _error->PushToStack(); + PackageSet pset = FromTask(Cache, str, helper); - if (pset.empty() == false) - return pset; + if (pset.empty() == true) { + pset = FromRegEx(Cache, str, helper); + if (pset.empty() == true) + pset = helper.canNotFindPackage(Cache, str); + } - pset = FromRegEx(Cache, str, helper); if (pset.empty() == false) - return pset; - - return helper.canNotFindPackage(Cache, str); + _error->RevertToStack(); + else + _error->MergeWithStack(); + return pset; } /*}}}*/ // GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ -- cgit v1.2.3 From bd631595620ca5b3c53ede4ef46c89399c26c5f3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 28 Jun 2010 22:13:17 +0200 Subject: - factor out code to get a single package FromName() - check in Grouped* first without modifier interpretation --- cmdline/cacheset.cc | 151 ++++++++++++++++++++++++++++++++++------------------ cmdline/cacheset.h | 15 +++++- 2 files changed, 113 insertions(+), 53 deletions(-) (limited to 'cmdline') diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index 2b00187d8..42bc79693 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -25,11 +25,7 @@ namespace APT { // FromTask - Return all packages in the cache from a specific task /*{{{*/ PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { - PackageSet pkgset; - if (Cache.BuildCaches() == false || Cache.BuildDepCache() == false) - return pkgset; - - size_t archfound = pattern.find_last_of(':'); + size_t const archfound = pattern.find_last_of(':'); std::string arch = "native"; if (archfound != std::string::npos) { arch = pattern.substr(archfound+1); @@ -37,9 +33,13 @@ PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, CacheS } if (pattern[pattern.length() -1] != '^') - return pkgset; + return APT::PackageSet(); pattern.erase(pattern.length()-1); + if (unlikely(Cache.GetPkgCache() == 0 || Cache.GetDepCache() == 0)) + return APT::PackageSet(); + + PackageSet pkgset; // get the records pkgRecords Recs(Cache); @@ -83,11 +83,9 @@ PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, CacheS /*}}}*/ // FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { - PackageSet pkgset; static const char * const isregex = ".?+*|[^$"; - if (pattern.find_first_of(isregex) == std::string::npos) - return pkgset; + return PackageSet(); size_t archfound = pattern.find_last_of(':'); std::string arch = "native"; @@ -105,9 +103,13 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, Cache char Error[300]; regerror(Res, &Pattern, Error, sizeof(Error)); _error->Error(_("Regex compilation error - %s"), Error); - return pkgset; + return PackageSet(); } + if (unlikely(Cache.GetPkgCache() == 0)) + return PackageSet(); + + PackageSet pkgset; for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) @@ -135,6 +137,33 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, Cache return pkgset; } /*}}}*/ +// FromName - Returns the package defined by this string /*{{{*/ +pkgCache::PkgIterator PackageSet::FromName(pkgCacheFile &Cache, + std::string const &str, CacheSetHelper &helper) { + std::string pkg = str; + size_t archfound = pkg.find_last_of(':'); + std::string arch; + if (archfound != std::string::npos) { + arch = pkg.substr(archfound+1); + pkg.erase(archfound); + } + + if (Cache.GetPkgCache() == 0) + return pkgCache::PkgIterator(Cache, 0); + + pkgCache::PkgIterator Pkg(Cache, 0); + if (arch.empty() == true) { + pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); + if (Grp.end() == false) + Pkg = Grp.FindPreferredPkg(); + } else + Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch); + + if (Pkg.end() == true) + return helper.canNotFindPkgName(Cache, str); + return Pkg; +} + /*}}}*/ // GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ std::map PackageSet::GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, @@ -144,6 +173,7 @@ std::map PackageSet::GroupedFromCommandLine( for (const char **I = cmdline; *I != 0; ++I) { unsigned short modID = fallback; std::string str = *I; + bool modifierPresent = false; for (std::list::const_iterator mod = mods.begin(); mod != mods.end(); ++mod) { size_t const alength = strlen(mod->Alias); @@ -160,8 +190,18 @@ std::map PackageSet::GroupedFromCommandLine( case PackageSet::Modifier::NONE: continue; } + modifierPresent = true; break; } + if (modifierPresent == true) { + bool const errors = helper.showErrors(false); + pkgCache::PkgIterator Pkg = FromName(Cache, *I, helper); + helper.showErrors(errors); + if (Pkg.end() == false) { + pkgsets[fallback].insert(Pkg); + continue; + } + } pkgsets[modID].insert(PackageSet::FromString(Cache, str, helper)); } return pkgsets; @@ -179,42 +219,26 @@ PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline /*}}}*/ // FromString - Return all packages matching a specific string /*{{{*/ PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) { - std::string pkg = str; - size_t archfound = pkg.find_last_of(':'); - std::string arch; - if (archfound != std::string::npos) { - arch = pkg.substr(archfound+1); - pkg.erase(archfound); - } - - pkgCache::PkgIterator Pkg; - if (arch.empty() == true) { - pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); - if (Grp.end() == false) - Pkg = Grp.FindPreferredPkg(); - } else - Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch); - - if (Pkg.end() == false) { - PackageSet pkgset; - pkgset.insert(Pkg); - return pkgset; - } - _error->PushToStack(); - PackageSet pset = FromTask(Cache, str, helper); - if (pset.empty() == true) { - pset = FromRegEx(Cache, str, helper); - if (pset.empty() == true) - pset = helper.canNotFindPackage(Cache, str); + PackageSet pkgset; + pkgCache::PkgIterator Pkg = FromName(Cache, str, helper); + if (Pkg.end() == false) + pkgset.insert(Pkg); + else { + pkgset = FromTask(Cache, str, helper); + if (pkgset.empty() == true) { + pkgset = FromRegEx(Cache, str, helper); + if (pkgset.empty() == true) + pkgset = helper.canNotFindPackage(Cache, str); + } } - if (pset.empty() == false) + if (pkgset.empty() == false) _error->RevertToStack(); else _error->MergeWithStack(); - return pset; + return pkgset; } /*}}}*/ // GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ @@ -227,6 +251,7 @@ std::map VersionSet::GroupedFromCommandLine( unsigned short modID = fallback; VersionSet::Version select = VersionSet::NEWEST; std::string str = *I; + bool modifierPresent = false; for (std::list::const_iterator mod = mods.begin(); mod != mods.end(); ++mod) { if (modID == fallback && mod->ID == fallback) @@ -246,8 +271,19 @@ std::map VersionSet::GroupedFromCommandLine( case VersionSet::Modifier::NONE: continue; } + modifierPresent = true; break; } + + if (modifierPresent == true) { + bool const errors = helper.showErrors(false); + VersionSet const vset = VersionSet::FromString(Cache, std::string(*I), select, helper, true); + helper.showErrors(errors); + if (vset.empty() == false) { + versets[fallback].insert(vset); + continue; + } + } versets[modID].insert(VersionSet::FromString(Cache, str, select , helper)); } return versets; @@ -257,16 +293,15 @@ std::map VersionSet::GroupedFromCommandLine( APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, APT::VersionSet::Version const &fallback, CacheSetHelper &helper) { VersionSet verset; - for (const char **I = cmdline; *I != 0; ++I) { - VersionSet vset = VersionSet::FromString(Cache, *I, fallback, helper); - verset.insert(vset.begin(), vset.end()); - } + for (const char **I = cmdline; *I != 0; ++I) + verset.insert(VersionSet::FromString(Cache, *I, fallback, helper)); return verset; } /*}}}*/ // FromString - Returns all versions spedcified by a string /*{{{*/ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper) { + APT::VersionSet::Version const &fallback, CacheSetHelper &helper, + bool const &onlyFromName) { std::string ver; bool verIsRel = false; size_t const vertag = pkg.find_last_of("/="); @@ -275,7 +310,13 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, verIsRel = (pkg[vertag] == '/'); pkg.erase(vertag); } - PackageSet pkgset = PackageSet::FromString(Cache, pkg.c_str(), helper); + PackageSet pkgset; + if (onlyFromName == false) + pkgset = PackageSet::FromString(Cache, pkg, helper); + else { + pkgset.insert(PackageSet::FromName(Cache, pkg, helper)); + } + VersionSet verset; for (PackageSet::const_iterator P = pkgset.begin(); P != pkgset.end(); ++P) { @@ -372,8 +413,8 @@ pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, if (Cache.IsDepCacheBuilt() == true) Cand = Cache[Pkg].CandidateVerIter(Cache); else { - if (unlikely(Cache.BuildPolicy() == false)) - return pkgCache::VerIterator(*Cache); + if (unlikely(Cache.GetPolicy() == 0)) + return pkgCache::VerIterator(Cache); Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); } if (Cand.end() == true) @@ -389,6 +430,14 @@ pkgCache::VerIterator VersionSet::getInstalledVer(pkgCacheFile &Cache, return Pkg.CurrentVer(); } /*}}}*/ +// canNotFindPkgName - handle the case no package has this name /*{{{*/ +pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache, + std::string const &str) { + if (ShowError == true) + _error->Error(_("Unable to locate package %s"), str.c_str()); + return pkgCache::PkgIterator(Cache, 0); +} + /*}}}*/ // canNotFindTask - handle the case no package is found for a task /*{{{*/ PackageSet CacheSetHelper::canNotFindTask(pkgCacheFile &Cache, std::string pattern) { if (ShowError == true) @@ -405,8 +454,6 @@ PackageSet CacheSetHelper::canNotFindRegEx(pkgCacheFile &Cache, std::string patt /*}}}*/ // canNotFindPackage - handle the case no package is found from a string/*{{{*/ PackageSet CacheSetHelper::canNotFindPackage(pkgCacheFile &Cache, std::string const &str) { - if (ShowError == true) - _error->Error(_("Unable to locate package %s"), str.c_str()); return PackageSet(); } /*}}}*/ @@ -431,7 +478,7 @@ pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { if (ShowError == true) _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(*Cache); + return pkgCache::VerIterator(Cache); } /*}}}*/ // canNotFindCandidateVer /*{{{*/ @@ -439,7 +486,7 @@ pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache pkgCache::PkgIterator const &Pkg) { if (ShowError == true) _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(*Cache); + return pkgCache::VerIterator(Cache); } /*}}}*/ // canNotFindInstalledVer /*{{{*/ @@ -447,7 +494,7 @@ pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache pkgCache::PkgIterator const &Pkg) { if (ShowError == true) _error->Error(_("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(*Cache); + return pkgCache::VerIterator(Cache); } /*}}}*/ } diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 9c9491020..21c42c511 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -40,6 +40,7 @@ public: /*{{{*/ virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, string const &ver, bool const &verIsRel) {}; + virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); virtual PackageSet canNotFindTask(pkgCacheFile &Cache, std::string pattern); virtual PackageSet canNotFindRegEx(pkgCacheFile &Cache, std::string pattern); virtual PackageSet canNotFindPackage(pkgCacheFile &Cache, std::string const &str); @@ -146,6 +147,17 @@ public: /*{{{*/ return APT::PackageSet::FromString(Cache, string, helper); } + /** \brief returns a package specified by a string + + \param Cache the package is in + \param string String the package name should be extracted from + \param out stream to print various notices to */ + static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); + static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string) { + CacheSetHelper helper; + return APT::PackageSet::FromName(Cache, string, helper); + } + /** \brief returns all packages specified on the commandline Get all package names from the commandline and executes regex's if needed. @@ -268,7 +280,8 @@ public: /*{{{*/ } static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper); + APT::VersionSet::Version const &fallback, CacheSetHelper &helper, + bool const &onlyFromName = false); static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, APT::VersionSet::Version const &fallback) { CacheSetHelper helper; -- cgit v1.2.3 From e67c08344dbb9ecd827658d74121fa9b66b28961 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 29 Jun 2010 17:14:45 +0200 Subject: for install, do all installs first and then the removes and vice versa --- cmdline/apt-get.cc | 92 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 38 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index e3477b6db..7ba0e8e5c 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1640,24 +1640,27 @@ bool DoInstall(CommandLine &CmdL) unsigned int AutoMarkChanged = 0; pkgProblemResolver Fix(Cache); - unsigned short fallback = 0; + static const unsigned short MOD_REMOVE = 1; + static const unsigned short MOD_INSTALL = 2; + + unsigned short fallback = MOD_INSTALL; if (strcasecmp(CmdL.FileList[0],"remove") == 0) - fallback = 1; + fallback = MOD_REMOVE; else if (strcasecmp(CmdL.FileList[0], "purge") == 0) { _config->Set("APT::Get::Purge", true); - fallback = 1; + fallback = MOD_REMOVE; } else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0) { _config->Set("APT::Get::AutomaticRemove", "true"); - fallback = 1; + fallback = MOD_REMOVE; } std::list mods; - mods.push_back(APT::VersionSet::Modifier(0, "+", + mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+", APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDINST)); - mods.push_back(APT::VersionSet::Modifier(1, "-", + mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-", APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::INSTCAND)); CacheSetHelperAPTGet helper(c0out); std::map verset = APT::VersionSet::GroupedFromCommandLine(Cache, @@ -1666,41 +1669,54 @@ bool DoInstall(CommandLine &CmdL) if (_error->PendingError() == true) 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; + } + // new scope for the ActionGroup { pkgDepCache::ActionGroup group(Cache); - for (APT::VersionSet::const_iterator Ver = verset[0].begin(); - Ver != verset[0].end(); ++Ver) - { - pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - Cache->SetCandidateVersion(Ver); - - if (TryToInstall(Pkg, Cache, Fix, false, BrokenFix) == 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 (Cache[Pkg].Install() == false && - (Cache[Pkg].Flags & pkgCache::Flag::Auto) && - _config->FindB("APT::Get::ReInstall",false) == false && - _config->FindB("APT::Get::Only-Upgrade",false) == false && - _config->FindB("APT::Get::Download-Only",false) == false) - { - ioprintf(c1out,_("%s set to manually installed.\n"), - Pkg.FullName(true).c_str()); - Cache->MarkAuto(Pkg,false); - AutoMarkChanged++; - } - } - - for (APT::VersionSet::const_iterator Ver = verset[1].begin(); - Ver != verset[1].end(); ++Ver) + for (unsigned short i = 0; order[i] != 0; ++i) { - pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + if (order[i] == MOD_INSTALL) + for (APT::VersionSet::const_iterator Ver = verset[MOD_INSTALL].begin(); + Ver != verset[MOD_INSTALL].end(); ++Ver) + { + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + Cache->SetCandidateVersion(Ver); + + if (TryToInstall(Pkg, Cache, Fix, false, BrokenFix) == 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 (Cache[Pkg].Install() == false && + (Cache[Pkg].Flags & pkgCache::Flag::Auto) && + _config->FindB("APT::Get::ReInstall",false) == false && + _config->FindB("APT::Get::Only-Upgrade",false) == false && + _config->FindB("APT::Get::Download-Only",false) == false) + { + ioprintf(c1out,_("%s set to manually installed.\n"), + Pkg.FullName(true).c_str()); + Cache->MarkAuto(Pkg,false); + AutoMarkChanged++; + } + } + else if (order[i] == MOD_REMOVE) + for (APT::VersionSet::const_iterator Ver = verset[MOD_REMOVE].begin(); + Ver != verset[MOD_REMOVE].end(); ++Ver) + { + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - if (TryToInstall(Pkg, Cache, Fix, true, BrokenFix) == false) - return false; + if (TryToInstall(Pkg, Cache, Fix, true, BrokenFix) == false) + return false; + } } if (_error->PendingError() == true) @@ -1752,7 +1768,7 @@ bool DoInstall(CommandLine &CmdL) /* Print out a list of packages that are going to be installed extra to what the user asked */ - if (Cache->InstCount() != verset[0].size()) + if (Cache->InstCount() != verset[MOD_INSTALL].size()) { string List; string VersionsList; @@ -1879,7 +1895,7 @@ bool DoInstall(CommandLine &CmdL) // See if we need to prompt // FIXME: check if really the packages in the set are going to be installed - if (Cache->InstCount() == verset[0].size() && Cache->DelCount() == 0) + if (Cache->InstCount() == verset[MOD_INSTALL].size() && Cache->DelCount() == 0) return InstallPackages(Cache,false,false); return InstallPackages(Cache,false); -- cgit v1.2.3 From fb83c1d078b9f5e2e28a828c325dc62dcf060f2b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 29 Jun 2010 19:10:47 +0200 Subject: rename AddSelectedVersion() to a better public FromPackage() --- cmdline/cacheset.cc | 11 ++++++----- cmdline/cacheset.h | 14 +++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'cmdline') diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index 42bc79693..35ef74f9a 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -321,7 +321,7 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, for (PackageSet::const_iterator P = pkgset.begin(); P != pkgset.end(); ++P) { if (vertag == string::npos) { - AddSelectedVersion(Cache, verset, P, fallback, helper); + verset.insert(VersionSet::FromPackage(Cache, P, fallback, helper)); continue; } pkgCache::VerIterator V; @@ -351,10 +351,10 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, return verset; } /*}}}*/ -// AddSelectedVersion - add version from package based on fallback /*{{{*/ -void VersionSet::AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, - pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, - CacheSetHelper &helper) { +// FromPackage - versions from package based on fallback /*{{{*/ +VersionSet VersionSet::FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + VersionSet::Version const &fallback, CacheSetHelper &helper) { + VersionSet verset; pkgCache::VerIterator V; bool showErrors; switch(fallback) { @@ -404,6 +404,7 @@ void VersionSet::AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, verset.insert(helper.canNotFindNewestVer(Cache, P)); break; } + return verset; } /*}}}*/ // getCandidateVer - Returns the candidate version of the given package /*{{{*/ diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 21c42c511..bf863fb39 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -291,6 +291,15 @@ public: /*{{{*/ return APT::VersionSet::FromString(Cache, pkg, CANDINST); } + /** \brief returns all versions specified for the package + + \param Cache the package and versions are in + \param P the package in question + \param fallback the version(s) you want to get + \param helper the helper used for display and error handling */ + static VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + VersionSet::Version const &fallback, CacheSetHelper &helper); + struct Modifier { enum Position { NONE, PREFIX, POSTFIX }; unsigned short ID; @@ -330,11 +339,6 @@ protected: /*{{{*/ \param Pkg we want the installed version from this package */ static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); - - static void AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, - pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, - CacheSetHelper &helper); - /*}}}*/ }; /*}}}*/ } -- cgit v1.2.3 From cf28bcadb301d00f6534fea97ccf1fde63041e7b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 29 Jun 2010 19:21:35 +0200 Subject: if the package has no installed & candidate but is virtual see if only one package provides it - if it is only one use this package instead --- cmdline/apt-get.cc | 86 ++++++++++++++++++++++++++++++----------------------- cmdline/cacheset.cc | 8 +++++ cmdline/cacheset.h | 2 ++ 3 files changed, 59 insertions(+), 37 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 7ba0e8e5c..d3ddcbfe8 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1081,41 +1081,6 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, pkgProblemResolver &Fix,bool Remove,bool BrokenFix, bool AllowFail = true) { - /* This is a pure virtual package and there is a single available - candidate providing it. */ - if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0) - { - pkgCache::PkgIterator Prov; - bool found_one = false; - - for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; P++) - { - pkgCache::VerIterator const PVer = P.OwnerVer(); - pkgCache::PkgIterator const PPkg = PVer.ParentPkg(); - - /* Ignore versions that are not a candidate. */ - if (Cache[PPkg].CandidateVer != PVer) - continue; - - if (found_one == false) - { - Prov = PPkg; - found_one = true; - } - else if (PPkg != Prov) - { - found_one = false; // we found at least two - break; - } - } - - if (found_one == true) - { - ioprintf(c1out,_("Note, selecting %s instead of %s\n"), - Prov.FullName(true).c_str(),Pkg.FullName(true).c_str()); - Pkg = Prov; - } - } // Handle the no-upgrade case if (_config->FindB("APT::Get::upgrade",true) == false && @@ -1601,13 +1566,13 @@ public: virtual void showTaskSelection(APT::PackageSet const &pkgset, string const &pattern) { for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - ioprintf(out, _("Note, selecting %s for task '%s'\n"), + ioprintf(out, _("Note, selecting '%s' for task '%s'\n"), Pkg.FullName(true).c_str(), pattern.c_str()); explicitlyNamed = false; } virtual void showRegExSelection(APT::PackageSet const &pkgset, string const &pattern) { for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - ioprintf(out, _("Note, selecting %s for regex '%s'\n"), + ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"), Pkg.FullName(true).c_str(), pattern.c_str()); explicitlyNamed = false; } @@ -1618,6 +1583,53 @@ public: Ver.VerStr(), Ver.RelStr().c_str(), Pkg.FullName(true).c_str()); } + virtual APT::VersionSet canNotFindCandInstVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + return tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDINST); + } + + virtual APT::VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + return tryVirtualPackage(Cache, Pkg, APT::VersionSet::INSTCAND); + } + + APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, + APT::VersionSet::Version const &select) { + /* This is a pure virtual package and there is a single available + candidate providing it. */ + if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) { + if (select == APT::VersionSet::CANDINST) + return APT::CacheSetHelper::canNotFindCandInstVer(Cache, Pkg); + return APT::CacheSetHelper::canNotFindInstCandVer(Cache, Pkg); + } + + pkgCache::PkgIterator Prov; + bool found_one = false; + for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; ++P) { + pkgCache::VerIterator const PVer = P.OwnerVer(); + pkgCache::PkgIterator const PPkg = PVer.ParentPkg(); + + /* Ignore versions that are not a candidate. */ + if (Cache[PPkg].CandidateVer != PVer) + continue; + + if (found_one == false) { + Prov = PPkg; + found_one = true; + } else if (PPkg != Prov) { + found_one = false; // we found at least two + break; + } + } + + if (found_one == true) { + ioprintf(out, _("Note, selecting '%s' instead of '%s'\n"), + Prov.FullName(true).c_str(), Pkg.FullName(true).c_str()); + return APT::VersionSet::FromPackage(Cache, Prov, select, *this); + } + if (select == APT::VersionSet::CANDINST) + return APT::CacheSetHelper::canNotFindCandInstVer(Cache, Pkg); + return APT::CacheSetHelper::canNotFindInstCandVer(Cache, Pkg); + } + inline bool allPkgNamedExplicitly() const { return explicitlyNamed; } }; diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index 35ef74f9a..cc2860a22 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -474,6 +474,14 @@ VersionSet CacheSetHelper::canNotFindInstCandVer(pkgCacheFile &Cache, return VersionSet(); } /*}}}*/ +// canNotFindInstCandVer /*{{{*/ +VersionSet CacheSetHelper::canNotFindCandInstVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg) { + if (ShowError == true) + _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); + return VersionSet(); +} + /*}}}*/ // canNotFindNewestVer /*{{{*/ pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index bf863fb39..2ca794f28 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -47,6 +47,8 @@ public: /*{{{*/ virtual VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); virtual VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + virtual VersionSet canNotFindCandInstVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, -- cgit v1.2.3 From c8db3fff877f102dc6fb62c4e4c7f700160b68f5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 2 Jul 2010 07:06:53 +0200 Subject: add a ConstructedBy member to the PackageSet which can be used by the e.g. FromString to tell the caller if the string was an exact match or found by regex or task. The two later ones can match packages for which we want to ignore failures in the VersionSet --- cmdline/cacheset.cc | 26 ++++++++++++++++---------- cmdline/cacheset.h | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 17 deletions(-) (limited to 'cmdline') diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index cc2860a22..4d6d6a87c 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -33,13 +33,13 @@ PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, CacheS } if (pattern[pattern.length() -1] != '^') - return APT::PackageSet(); + return APT::PackageSet(TASK); pattern.erase(pattern.length()-1); if (unlikely(Cache.GetPkgCache() == 0 || Cache.GetDepCache() == 0)) - return APT::PackageSet(); + return APT::PackageSet(TASK); - PackageSet pkgset; + PackageSet pkgset(TASK); // get the records pkgRecords Recs(Cache); @@ -85,7 +85,7 @@ PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, CacheS PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { static const char * const isregex = ".?+*|[^$"; if (pattern.find_first_of(isregex) == std::string::npos) - return PackageSet(); + return PackageSet(REGEX); size_t archfound = pattern.find_last_of(':'); std::string arch = "native"; @@ -103,13 +103,13 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, Cache char Error[300]; regerror(Res, &Pattern, Error, sizeof(Error)); _error->Error(_("Regex compilation error - %s"), Error); - return PackageSet(); + return PackageSet(REGEX); } if (unlikely(Cache.GetPkgCache() == 0)) - return PackageSet(); + return PackageSet(REGEX); - PackageSet pkgset; + PackageSet pkgset(REGEX); for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) @@ -318,8 +318,12 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, } VersionSet verset; + bool errors = true; + if (pkgset.getConstructor() != PackageSet::UNKNOWN) + errors = helper.showErrors(false); for (PackageSet::const_iterator P = pkgset.begin(); P != pkgset.end(); ++P) { + helper.canNotFindCandidateVer(Cache, P); if (vertag == string::npos) { verset.insert(VersionSet::FromPackage(Cache, P, fallback, helper)); continue; @@ -348,6 +352,8 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, helper.showSelectedVersion(P, V, ver, verIsRel); verset.insert(V); } + if (pkgset.getConstructor() != PackageSet::UNKNOWN) + helper.showErrors(errors); return verset; } /*}}}*/ @@ -487,7 +493,7 @@ pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { if (ShowError == true) _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache); + return pkgCache::VerIterator(Cache, 0); } /*}}}*/ // canNotFindCandidateVer /*{{{*/ @@ -495,7 +501,7 @@ pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache pkgCache::PkgIterator const &Pkg) { if (ShowError == true) _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache); + return pkgCache::VerIterator(Cache, 0); } /*}}}*/ // canNotFindInstalledVer /*{{{*/ @@ -503,7 +509,7 @@ pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache pkgCache::PkgIterator const &Pkg) { if (ShowError == true) _error->Error(_("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache); + return pkgCache::VerIterator(Cache, 0); } /*}}}*/ } diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 2ca794f28..c8c3dd096 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -117,7 +117,7 @@ public: /*{{{*/ packages chosen cause of the given task. \param Cache the packages are in \param pattern name of the task - \param out stream to print the notice to */ + \param helper responsible for error and message handling */ static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { CacheSetHelper helper; @@ -131,7 +131,7 @@ public: /*{{{*/ packages chosen cause of the given package. \param Cache the packages are in \param pattern regular expression for package names - \param out stream to print the notice to */ + \param helper responsible for error and message handling */ static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { CacheSetHelper helper; @@ -142,7 +142,7 @@ public: /*{{{*/ \param Cache the packages are in \param string String the package name(s) should be extracted from - \param out stream to print various notices to */ + \param helper responsible for error and message handling */ static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { CacheSetHelper helper; @@ -153,7 +153,7 @@ public: /*{{{*/ \param Cache the package is in \param string String the package name should be extracted from - \param out stream to print various notices to */ + \param helper responsible for error and message handling */ static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string) { CacheSetHelper helper; @@ -166,7 +166,7 @@ public: /*{{{*/ No special package command is supported, just plain names. \param Cache the packages are in \param cmdline Command line the package names should be extracted from - \param out stream to print various notices to */ + \param helper responsible for error and message handling */ static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { CacheSetHelper helper; @@ -181,6 +181,17 @@ public: /*{{{*/ Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; }; + /** \brief group packages by a action modifiers + + At some point it is needed to get from the same commandline + different package sets grouped by a modifier. Take + apt-get install apt awesome- + as an example. + \param Cache the packages are in + \param cmdline Command line the package names should be extracted from + \param mods list of modifiers the method should accept + \param fallback the default modifier group for a package + \param helper responsible for error and message handling */ static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, @@ -193,6 +204,15 @@ public: /*{{{*/ return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, mods, fallback, helper); } + + enum Constructor { UNKNOWN, REGEX, TASK }; + Constructor getConstructor() const { return ConstructedBy; }; + + PackageSet() : ConstructedBy(UNKNOWN) {}; + PackageSet(Constructor const &by) : ConstructedBy(by) {}; + /*}}}*/ +private: /*{{{*/ + Constructor ConstructedBy; /*}}}*/ }; /*}}}*/ class VersionSet : public std::set { /*{{{*/ @@ -269,7 +289,7 @@ public: /*{{{*/ non specifically requested and executes regex's if needed on names. \param Cache the packages and versions are in \param cmdline Command line the versions should be extracted from - \param out stream to print various notices to */ + \param helper responsible for error and message handling */ static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, APT::VersionSet::Version const &fallback, CacheSetHelper &helper); static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, @@ -299,8 +319,16 @@ public: /*{{{*/ \param P the package in question \param fallback the version(s) you want to get \param helper the helper used for display and error handling */ - static VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, CacheSetHelper &helper); + static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + APT::VersionSet::Version const &fallback) { + CacheSetHelper helper; + return APT::VersionSet::FromPackage(Cache, P, fallback, helper); + } + static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { + return APT::VersionSet::FromPackage(Cache, P, CANDINST); + } struct Modifier { enum Position { NONE, PREFIX, POSTFIX }; -- cgit v1.2.3 From b8ad551295c70a882b629ee94668e8ea527d1a7d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 3 Jul 2010 20:09:17 +0200 Subject: Refactor TryToInstall to look a bit saner by splitting the Remove and the Virtual packages part out of the loop. The function still exists unchanged as TryToInstallBuildDep through for the BuildDep installation method --- cmdline/apt-get.cc | 229 ++++++++++++++++++++++++++++++++++++++++------------ cmdline/cacheset.cc | 1 - 2 files changed, 177 insertions(+), 53 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index d3ddcbfe8..d17300943 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1073,11 +1073,11 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, return true; } /*}}}*/ -// TryToInstall - Try to install a single package /*{{{*/ +// TryToInstallBuildDep - 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, +bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, pkgProblemResolver &Fix,bool Remove,bool BrokenFix, bool AllowFail = true) { @@ -1552,6 +1552,93 @@ bool DoUpgrade(CommandLine &CmdL) return InstallPackages(Cache,true); } /*}}}*/ +// TryToInstall - Mark a package for installation /*{{{*/ +struct TryToInstall { + pkgCacheFile* Cache; + pkgProblemResolver* Fix; + bool FixBroken; + unsigned long AutoMarkChanged; + + TryToInstall(pkgCacheFile &Cache, pkgProblemResolver &PM, bool const &FixBroken) : Cache(&Cache), Fix(&PM), + FixBroken(FixBroken), AutoMarkChanged(0) {}; + + void operator() (pkgCache::VerIterator const &Ver) { + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + Cache->GetDepCache()->SetCandidateVersion(Ver); + pkgDepCache::StateCache &State = (*Cache)[Pkg]; + + // Handle the no-upgrade case + if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0) + ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"), + Pkg.FullName(true).c_str()); + // Ignore request for install if package would be new + else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0) + ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"), + Pkg.FullName(true).c_str()); + else { + Fix->Clear(Pkg); + Fix->Protect(Pkg); + Cache->GetDepCache()->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.FullName(true).c_str()); + else + Cache->GetDepCache()->SetReInstall(Pkg, true); + } else + ioprintf(c1out,_("%s is already the newest version.\n"), + Pkg.FullName(true).c_str()); + } + + // Install it with autoinstalling enabled (if we not respect the minial + // required deps or the policy) + if ((State.InstBroken() == true || State.InstPolicyBroken() == true) && FixBroken == false) + Cache->GetDepCache()->MarkInstall(Pkg,true); + } + + // see if we need to fix the auto-mark flag + // e.g. apt-get install foo + // where foo is marked automatic + if (State.Install() == false && + (State.Flags & pkgCache::Flag::Auto) && + _config->FindB("APT::Get::ReInstall",false) == false && + _config->FindB("APT::Get::Only-Upgrade",false) == false && + _config->FindB("APT::Get::Download-Only",false) == false) + { + ioprintf(c1out,_("%s set to manually installed.\n"), + Pkg.FullName(true).c_str()); + Cache->GetDepCache()->MarkAuto(Pkg,false); + AutoMarkChanged++; + } + } +}; + /*}}}*/ +// TryToRemove - Mark a package for removal /*{{{*/ +struct TryToRemove { + pkgCacheFile* Cache; + pkgProblemResolver* Fix; + bool FixBroken; + unsigned long AutoMarkChanged; + + TryToRemove(pkgCacheFile &Cache, pkgProblemResolver &PM) : Cache(&Cache), Fix(&PM) {}; + + void operator() (pkgCache::VerIterator const &Ver) + { + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + + Fix->Clear(Pkg); + Fix->Protect(Pkg); + Fix->Remove(Pkg); + + if (Pkg->CurrentVer == 0) + ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.FullName(true).c_str()); + else + Cache->GetDepCache()->MarkDelete(Pkg,_config->FindB("APT::Get::Purge",false)); + } +}; + /*}}}*/ // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/ class CacheSetHelperAPTGet : public APT::CacheSetHelper { /** \brief stream message should be printed to */ @@ -1559,6 +1646,8 @@ class CacheSetHelperAPTGet : public APT::CacheSetHelper { /** \brief were things like Task or RegEx used to select packages? */ bool explicitlyNamed; + APT::PackageSet virtualPkgs; + public: CacheSetHelperAPTGet(std::ostream &out) : APT::CacheSetHelper(true), out(out) { explicitlyNamed = true; @@ -1583,23 +1672,85 @@ public: Ver.VerStr(), Ver.RelStr().c_str(), Pkg.FullName(true).c_str()); } - virtual APT::VersionSet canNotFindCandInstVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - return tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDINST); + void showVirtualPackageErrors(pkgCacheFile &Cache) { + for (APT::PackageSet::const_iterator Pkg = virtualPkgs.begin(); + Pkg != virtualPkgs.end(); ++Pkg) { + if (Pkg->ProvidesList != 0) { + ioprintf(c1out,_("Package %s is a virtual package provided by:\n"), + Pkg.FullName(true).c_str()); + + pkgCache::PrvIterator I = Pkg.ProvidesList(); + unsigned short provider = 0; + for (; I.end() == false; ++I) { + pkgCache::PkgIterator Pkg = I.OwnerPkg(); + + if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) { + out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr(); + if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) + out << _(" [Installed]"); + out << endl; + ++provider; + } + } + // if we found no candidate which provide this package, show non-candidates + if (provider == 0) + for (I = Pkg.ProvidesList(); I.end() == false; I++) + out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr() + << _(" [Not candidate version]") << endl; + else + out << _("You should explicitly select one to install.") << endl; + } else { + ioprintf(out, + _("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.FullName(true).c_str()); + + string List; + string VersionsList; + SPtrArray Seen = new bool[Cache.GetPkgCache()->Head().PackageCount]; + memset(Seen,0,Cache.GetPkgCache()->Head().PackageCount*sizeof(*Seen)); + for (pkgCache::DepIterator Dep = Pkg.RevDependsList(); + Dep.end() == false; Dep++) { + if (Dep->Type != pkgCache::Dep::Replaces) + continue; + if (Seen[Dep.ParentPkg()->ID] == true) + continue; + Seen[Dep.ParentPkg()->ID] = true; + List += Dep.ParentPkg().FullName(true) + " "; + //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ??? + } + ShowList(out,_("However the following packages replace it:"),List,VersionsList); + } + out << std::endl; + } } - virtual APT::VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - return tryVirtualPackage(Cache, Pkg, APT::VersionSet::INSTCAND); + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDIDATE); + if (verset.empty() == false) + return *(verset.begin()); + if (ShowError == true) { + _error->Error(_("Package '%s' has no installation candidate"),Pkg.FullName(true).c_str()); + virtualPkgs.insert(Pkg); + } + return pkgCache::VerIterator(Cache, 0); + } + + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::NEWEST); + if (verset.empty() == false) + return *(verset.begin()); + if (ShowError == true) + ioprintf(out, _("Virtual packages like '%s' can't be removed\n"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(Cache, 0); } APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, APT::VersionSet::Version const &select) { /* This is a pure virtual package and there is a single available candidate providing it. */ - if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) { - if (select == APT::VersionSet::CANDINST) - return APT::CacheSetHelper::canNotFindCandInstVer(Cache, Pkg); - return APT::CacheSetHelper::canNotFindInstCandVer(Cache, Pkg); - } + if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) + return APT::VersionSet(); pkgCache::PkgIterator Prov; bool found_one = false; @@ -1625,9 +1776,7 @@ public: Prov.FullName(true).c_str(), Pkg.FullName(true).c_str()); return APT::VersionSet::FromPackage(Cache, Prov, select, *this); } - if (select == APT::VersionSet::CANDINST) - return APT::CacheSetHelper::canNotFindCandInstVer(Cache, Pkg); - return APT::CacheSetHelper::canNotFindInstCandVer(Cache, Pkg); + return APT::VersionSet(); } inline bool allPkgNamedExplicitly() const { return explicitlyNamed; } @@ -1649,7 +1798,6 @@ bool DoInstall(CommandLine &CmdL) if (Cache->BrokenCount() != 0) BrokenFix = true; - unsigned int AutoMarkChanged = 0; pkgProblemResolver Fix(Cache); static const unsigned short MOD_REMOVE = 1; @@ -1671,15 +1819,18 @@ bool DoInstall(CommandLine &CmdL) std::list mods; mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+", - APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDINST)); + APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDIDATE)); mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-", - APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::INSTCAND)); + APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::NEWEST)); CacheSetHelperAPTGet helper(c0out); std::map verset = APT::VersionSet::GroupedFromCommandLine(Cache, CmdL.FileList + 1, mods, fallback, helper); if (_error->PendingError() == true) + { + helper.showVirtualPackageErrors(Cache); return false; + } unsigned short order[] = { 0, 0, 0 }; if (fallback == MOD_INSTALL) { @@ -1690,45 +1841,19 @@ bool DoInstall(CommandLine &CmdL) order[1] = MOD_INSTALL; } + TryToInstall InstallAction(Cache, Fix, BrokenFix); + TryToRemove RemoveAction(Cache, Fix); + // new scope for the ActionGroup { pkgDepCache::ActionGroup group(Cache); + for (unsigned short i = 0; order[i] != 0; ++i) { if (order[i] == MOD_INSTALL) - for (APT::VersionSet::const_iterator Ver = verset[MOD_INSTALL].begin(); - Ver != verset[MOD_INSTALL].end(); ++Ver) - { - pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - Cache->SetCandidateVersion(Ver); - - if (TryToInstall(Pkg, Cache, Fix, false, BrokenFix) == 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 (Cache[Pkg].Install() == false && - (Cache[Pkg].Flags & pkgCache::Flag::Auto) && - _config->FindB("APT::Get::ReInstall",false) == false && - _config->FindB("APT::Get::Only-Upgrade",false) == false && - _config->FindB("APT::Get::Download-Only",false) == false) - { - ioprintf(c1out,_("%s set to manually installed.\n"), - Pkg.FullName(true).c_str()); - Cache->MarkAuto(Pkg,false); - AutoMarkChanged++; - } - } + InstallAction = std::for_each(verset[MOD_INSTALL].begin(), verset[MOD_INSTALL].end(), InstallAction); else if (order[i] == MOD_REMOVE) - for (APT::VersionSet::const_iterator Ver = verset[MOD_REMOVE].begin(); - Ver != verset[MOD_REMOVE].end(); ++Ver) - { - pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - - if (TryToInstall(Pkg, Cache, Fix, true, BrokenFix) == false) - return false; - } + RemoveAction = std::for_each(verset[MOD_REMOVE].begin(), verset[MOD_REMOVE].end(), RemoveAction); } if (_error->PendingError() == true) @@ -1899,7 +2024,7 @@ 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 && + if (InstallAction.AutoMarkChanged > 0 && Cache->DelCount() == 0 && Cache->InstCount() == 0 && Cache->BadCount() == 0 && _config->FindB("APT::Get::Simulate",false) == false) @@ -2521,7 +2646,7 @@ bool DoBuildDep(CommandLine &CmdL) */ if (IV.end() == false && Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) - TryToInstall(Pkg,Cache,Fix,true,false); + TryToInstallBuildDep(Pkg,Cache,Fix,true,false); } else // BuildDep || BuildDepIndep { @@ -2637,7 +2762,7 @@ bool DoBuildDep(CommandLine &CmdL) if (_config->FindB("Debug::BuildDeps",false) == true) cout << " Trying to install " << (*D).Package << endl; - if (TryToInstall(Pkg,Cache,Fix,false,false) == true) + if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false) == true) { // We successfully installed something; skip remaining alternatives skipAlternatives = hasAlternatives; diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index 4d6d6a87c..b96b60450 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -323,7 +323,6 @@ APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, errors = helper.showErrors(false); for (PackageSet::const_iterator P = pkgset.begin(); P != pkgset.end(); ++P) { - helper.canNotFindCandidateVer(Cache, P); if (vertag == string::npos) { verset.insert(VersionSet::FromPackage(Cache, P, fallback, helper)); continue; -- cgit v1.2.3 From 21d4c9f192b5af9c8edb39356712aac853881348 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 3 Jul 2010 23:55:12 +0200 Subject: reorder classes a bit and make TryToInstallBuildDep use them --- cmdline/apt-get.cc | 610 ++++++++++++++++++++++------------------------------- 1 file changed, 250 insertions(+), 360 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index d17300943..38b93e7e5 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -609,6 +609,240 @@ void Stats(ostream &out,pkgDepCache &Dep) Dep.BadCount()); } /*}}}*/ +// CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/ +class CacheSetHelperAPTGet : public APT::CacheSetHelper { + /** \brief stream message should be printed to */ + std::ostream &out; + /** \brief were things like Task or RegEx used to select packages? */ + bool explicitlyNamed; + + APT::PackageSet virtualPkgs; + +public: + CacheSetHelperAPTGet(std::ostream &out) : APT::CacheSetHelper(true), out(out) { + explicitlyNamed = true; + } + + virtual void showTaskSelection(APT::PackageSet const &pkgset, string const &pattern) { + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + ioprintf(out, _("Note, selecting '%s' for task '%s'\n"), + Pkg.FullName(true).c_str(), pattern.c_str()); + explicitlyNamed = false; + } + virtual void showRegExSelection(APT::PackageSet const &pkgset, string const &pattern) { + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"), + Pkg.FullName(true).c_str(), pattern.c_str()); + explicitlyNamed = false; + } + 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()); + } + + bool showVirtualPackageErrors(pkgCacheFile &Cache) { + if (virtualPkgs.empty() == true) + return true; + for (APT::PackageSet::const_iterator Pkg = virtualPkgs.begin(); + Pkg != virtualPkgs.end(); ++Pkg) { + if (Pkg->ProvidesList != 0) { + ioprintf(c1out,_("Package %s is a virtual package provided by:\n"), + Pkg.FullName(true).c_str()); + + pkgCache::PrvIterator I = Pkg.ProvidesList(); + unsigned short provider = 0; + for (; I.end() == false; ++I) { + pkgCache::PkgIterator Pkg = I.OwnerPkg(); + + if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) { + out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr(); + if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) + out << _(" [Installed]"); + out << endl; + ++provider; + } + } + // if we found no candidate which provide this package, show non-candidates + if (provider == 0) + for (I = Pkg.ProvidesList(); I.end() == false; I++) + out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr() + << _(" [Not candidate version]") << endl; + else + out << _("You should explicitly select one to install.") << endl; + } else { + ioprintf(out, + _("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.FullName(true).c_str()); + + string List; + string VersionsList; + SPtrArray Seen = new bool[Cache.GetPkgCache()->Head().PackageCount]; + memset(Seen,0,Cache.GetPkgCache()->Head().PackageCount*sizeof(*Seen)); + for (pkgCache::DepIterator Dep = Pkg.RevDependsList(); + Dep.end() == false; Dep++) { + if (Dep->Type != pkgCache::Dep::Replaces) + continue; + if (Seen[Dep.ParentPkg()->ID] == true) + continue; + Seen[Dep.ParentPkg()->ID] = true; + List += Dep.ParentPkg().FullName(true) + " "; + //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ??? + } + ShowList(out,_("However the following packages replace it:"),List,VersionsList); + } + out << std::endl; + } + return false; + } + + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDIDATE); + if (verset.empty() == false) + return *(verset.begin()); + if (ShowError == true) { + _error->Error(_("Package '%s' has no installation candidate"),Pkg.FullName(true).c_str()); + virtualPkgs.insert(Pkg); + } + return pkgCache::VerIterator(Cache, 0); + } + + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::NEWEST); + if (verset.empty() == false) + return *(verset.begin()); + if (ShowError == true) + ioprintf(out, _("Virtual packages like '%s' can't be removed\n"), Pkg.FullName(true).c_str()); + return pkgCache::VerIterator(Cache, 0); + } + + APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, + APT::VersionSet::Version const &select) { + /* This is a pure virtual package and there is a single available + candidate providing it. */ + if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) + return APT::VersionSet(); + + pkgCache::PkgIterator Prov; + bool found_one = false; + for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; ++P) { + pkgCache::VerIterator const PVer = P.OwnerVer(); + pkgCache::PkgIterator const PPkg = PVer.ParentPkg(); + + /* Ignore versions that are not a candidate. */ + if (Cache[PPkg].CandidateVer != PVer) + continue; + + if (found_one == false) { + Prov = PPkg; + found_one = true; + } else if (PPkg != Prov) { + found_one = false; // we found at least two + break; + } + } + + if (found_one == true) { + ioprintf(out, _("Note, selecting '%s' instead of '%s'\n"), + Prov.FullName(true).c_str(), Pkg.FullName(true).c_str()); + return APT::VersionSet::FromPackage(Cache, Prov, select, *this); + } + return APT::VersionSet(); + } + + inline bool allPkgNamedExplicitly() const { return explicitlyNamed; } + +}; + /*}}}*/ +// TryToInstall - Mark a package for installation /*{{{*/ +struct TryToInstall { + pkgCacheFile* Cache; + pkgProblemResolver* Fix; + bool FixBroken; + unsigned long AutoMarkChanged; + + TryToInstall(pkgCacheFile &Cache, pkgProblemResolver &PM, bool const &FixBroken) : Cache(&Cache), Fix(&PM), + FixBroken(FixBroken), AutoMarkChanged(0) {}; + + void operator() (pkgCache::VerIterator const &Ver) { + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + Cache->GetDepCache()->SetCandidateVersion(Ver); + pkgDepCache::StateCache &State = (*Cache)[Pkg]; + + // Handle the no-upgrade case + if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0) + ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"), + Pkg.FullName(true).c_str()); + // Ignore request for install if package would be new + else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0) + ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"), + Pkg.FullName(true).c_str()); + else { + Fix->Clear(Pkg); + Fix->Protect(Pkg); + Cache->GetDepCache()->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.FullName(true).c_str()); + else + Cache->GetDepCache()->SetReInstall(Pkg, true); + } else + ioprintf(c1out,_("%s is already the newest version.\n"), + Pkg.FullName(true).c_str()); + } + + // Install it with autoinstalling enabled (if we not respect the minial + // required deps or the policy) + if ((State.InstBroken() == true || State.InstPolicyBroken() == true) && FixBroken == false) + Cache->GetDepCache()->MarkInstall(Pkg,true); + } + + // see if we need to fix the auto-mark flag + // e.g. apt-get install foo + // where foo is marked automatic + if (State.Install() == false && + (State.Flags & pkgCache::Flag::Auto) && + _config->FindB("APT::Get::ReInstall",false) == false && + _config->FindB("APT::Get::Only-Upgrade",false) == false && + _config->FindB("APT::Get::Download-Only",false) == false) + { + ioprintf(c1out,_("%s set to manually installed.\n"), + Pkg.FullName(true).c_str()); + Cache->GetDepCache()->MarkAuto(Pkg,false); + AutoMarkChanged++; + } + } +}; + /*}}}*/ +// TryToRemove - Mark a package for removal /*{{{*/ +struct TryToRemove { + pkgCacheFile* Cache; + pkgProblemResolver* Fix; + bool FixBroken; + unsigned long AutoMarkChanged; + + TryToRemove(pkgCacheFile &Cache, pkgProblemResolver &PM) : Cache(&Cache), Fix(&PM) {}; + + void operator() (pkgCache::VerIterator const &Ver) + { + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + + Fix->Clear(Pkg); + Fix->Protect(Pkg); + Fix->Remove(Pkg); + + if (Pkg->CurrentVer == 0) + ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.FullName(true).c_str()); + else + Cache->GetDepCache()->MarkDelete(Pkg,_config->FindB("APT::Get::Purge",false)); + } +}; + /*}}}*/ // CacheFile::NameComp - QSort compare by name /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -1077,143 +1311,30 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, // --------------------------------------------------------------------- /* This used to be inlined in DoInstall, but with the advent of regex package name matching it was split out.. */ -bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgDepCache &Cache, +bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache, pkgProblemResolver &Fix,bool Remove,bool BrokenFix, bool AllowFail = true) { - - // 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.FullName(true).c_str()); - return true; - } - - // Ignore request for install if package would be new - if (_config->FindB("APT::Get::Only-Upgrade", false) == true && - Pkg->CurrentVer == 0) - { - if (AllowFail == true) - ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\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.FullName(true).c_str()); - return true; - } - - if (State.CandidateVer == 0 && Remove == false) + if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0) { - if (AllowFail == false) - return false; - - if (Pkg->ProvidesList != 0) - { - ioprintf(c1out,_("Package %s is a virtual package provided by:\n"), - Pkg.FullName(true).c_str()); - - pkgCache::PrvIterator I = Pkg.ProvidesList(); - unsigned short provider = 0; - for (; I.end() == false; I++) - { - pkgCache::PkgIterator Pkg = I.OwnerPkg(); - - if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) - { - c1out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr(); - if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) - c1out << _(" [Installed]"); - c1out << endl; - ++provider; - } - } - // if we found no candidate which provide this package, show non-candidates - if (provider == 0) - for (I = Pkg.ProvidesList(); I.end() == false; I++) - c1out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr() - << _(" [Not candidate version]") << endl; - else - 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.FullName(true).c_str()); - - string List; - string VersionsList; - SPtrArray 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 += Dep.ParentPkg().FullName(true) + " "; - //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.FullName(true).c_str()); - return false; + CacheSetHelperAPTGet helper(c1out); + helper.showErrors(AllowFail == false); + pkgCache::VerIterator Ver = helper.canNotFindNewestVer(Cache, Pkg); + if (Ver.end() == false) + Pkg = Ver.ParentPkg(); + else if (helper.showVirtualPackageErrors(Cache) == false) + return AllowFail; } - 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.FullName(true).c_str()); - else - Cache.SetReInstall(Pkg,true); - } - else - { - if (AllowFail == true) - ioprintf(c1out,_("%s is already the newest version.\n"), - Pkg.FullName(true).c_str()); - } - } - - // Install it with autoinstalling enabled (if we not respect the minial - // required deps or the policy) - if ((State.InstBroken() == true || State.InstPolicyBroken() == true) && BrokenFix == false) - Cache.MarkInstall(Pkg,true); + TryToRemove RemoveAction(Cache, Fix); + RemoveAction(Pkg.VersionList()); + } else if (Cache[Pkg].CandidateVer != 0) { + TryToInstall InstallAction(Cache, Fix, BrokenFix); + InstallAction(Cache[Pkg].CandidateVerIter(Cache)); + } else + return AllowFail; return true; } @@ -1552,237 +1673,6 @@ bool DoUpgrade(CommandLine &CmdL) return InstallPackages(Cache,true); } /*}}}*/ -// TryToInstall - Mark a package for installation /*{{{*/ -struct TryToInstall { - pkgCacheFile* Cache; - pkgProblemResolver* Fix; - bool FixBroken; - unsigned long AutoMarkChanged; - - TryToInstall(pkgCacheFile &Cache, pkgProblemResolver &PM, bool const &FixBroken) : Cache(&Cache), Fix(&PM), - FixBroken(FixBroken), AutoMarkChanged(0) {}; - - void operator() (pkgCache::VerIterator const &Ver) { - pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - Cache->GetDepCache()->SetCandidateVersion(Ver); - pkgDepCache::StateCache &State = (*Cache)[Pkg]; - - // Handle the no-upgrade case - if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0) - ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"), - Pkg.FullName(true).c_str()); - // Ignore request for install if package would be new - else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0) - ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"), - Pkg.FullName(true).c_str()); - else { - Fix->Clear(Pkg); - Fix->Protect(Pkg); - Cache->GetDepCache()->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.FullName(true).c_str()); - else - Cache->GetDepCache()->SetReInstall(Pkg, true); - } else - ioprintf(c1out,_("%s is already the newest version.\n"), - Pkg.FullName(true).c_str()); - } - - // Install it with autoinstalling enabled (if we not respect the minial - // required deps or the policy) - if ((State.InstBroken() == true || State.InstPolicyBroken() == true) && FixBroken == false) - Cache->GetDepCache()->MarkInstall(Pkg,true); - } - - // see if we need to fix the auto-mark flag - // e.g. apt-get install foo - // where foo is marked automatic - if (State.Install() == false && - (State.Flags & pkgCache::Flag::Auto) && - _config->FindB("APT::Get::ReInstall",false) == false && - _config->FindB("APT::Get::Only-Upgrade",false) == false && - _config->FindB("APT::Get::Download-Only",false) == false) - { - ioprintf(c1out,_("%s set to manually installed.\n"), - Pkg.FullName(true).c_str()); - Cache->GetDepCache()->MarkAuto(Pkg,false); - AutoMarkChanged++; - } - } -}; - /*}}}*/ -// TryToRemove - Mark a package for removal /*{{{*/ -struct TryToRemove { - pkgCacheFile* Cache; - pkgProblemResolver* Fix; - bool FixBroken; - unsigned long AutoMarkChanged; - - TryToRemove(pkgCacheFile &Cache, pkgProblemResolver &PM) : Cache(&Cache), Fix(&PM) {}; - - void operator() (pkgCache::VerIterator const &Ver) - { - pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - - Fix->Clear(Pkg); - Fix->Protect(Pkg); - Fix->Remove(Pkg); - - if (Pkg->CurrentVer == 0) - ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.FullName(true).c_str()); - else - Cache->GetDepCache()->MarkDelete(Pkg,_config->FindB("APT::Get::Purge",false)); - } -}; - /*}}}*/ -// CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/ -class CacheSetHelperAPTGet : public APT::CacheSetHelper { - /** \brief stream message should be printed to */ - std::ostream &out; - /** \brief were things like Task or RegEx used to select packages? */ - bool explicitlyNamed; - - APT::PackageSet virtualPkgs; - -public: - CacheSetHelperAPTGet(std::ostream &out) : APT::CacheSetHelper(true), out(out) { - explicitlyNamed = true; - } - - virtual void showTaskSelection(APT::PackageSet const &pkgset, string const &pattern) { - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - ioprintf(out, _("Note, selecting '%s' for task '%s'\n"), - Pkg.FullName(true).c_str(), pattern.c_str()); - explicitlyNamed = false; - } - virtual void showRegExSelection(APT::PackageSet const &pkgset, string const &pattern) { - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"), - Pkg.FullName(true).c_str(), pattern.c_str()); - explicitlyNamed = false; - } - 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()); - } - - void showVirtualPackageErrors(pkgCacheFile &Cache) { - for (APT::PackageSet::const_iterator Pkg = virtualPkgs.begin(); - Pkg != virtualPkgs.end(); ++Pkg) { - if (Pkg->ProvidesList != 0) { - ioprintf(c1out,_("Package %s is a virtual package provided by:\n"), - Pkg.FullName(true).c_str()); - - pkgCache::PrvIterator I = Pkg.ProvidesList(); - unsigned short provider = 0; - for (; I.end() == false; ++I) { - pkgCache::PkgIterator Pkg = I.OwnerPkg(); - - if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer()) { - out << " " << Pkg.FullName(true) << " " << I.OwnerVer().VerStr(); - if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false) - out << _(" [Installed]"); - out << endl; - ++provider; - } - } - // if we found no candidate which provide this package, show non-candidates - if (provider == 0) - for (I = Pkg.ProvidesList(); I.end() == false; I++) - out << " " << I.OwnerPkg().FullName(true) << " " << I.OwnerVer().VerStr() - << _(" [Not candidate version]") << endl; - else - out << _("You should explicitly select one to install.") << endl; - } else { - ioprintf(out, - _("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.FullName(true).c_str()); - - string List; - string VersionsList; - SPtrArray Seen = new bool[Cache.GetPkgCache()->Head().PackageCount]; - memset(Seen,0,Cache.GetPkgCache()->Head().PackageCount*sizeof(*Seen)); - for (pkgCache::DepIterator Dep = Pkg.RevDependsList(); - Dep.end() == false; Dep++) { - if (Dep->Type != pkgCache::Dep::Replaces) - continue; - if (Seen[Dep.ParentPkg()->ID] == true) - continue; - Seen[Dep.ParentPkg()->ID] = true; - List += Dep.ParentPkg().FullName(true) + " "; - //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ??? - } - ShowList(out,_("However the following packages replace it:"),List,VersionsList); - } - out << std::endl; - } - } - - virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDIDATE); - if (verset.empty() == false) - return *(verset.begin()); - if (ShowError == true) { - _error->Error(_("Package '%s' has no installation candidate"),Pkg.FullName(true).c_str()); - virtualPkgs.insert(Pkg); - } - return pkgCache::VerIterator(Cache, 0); - } - - virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::NEWEST); - if (verset.empty() == false) - return *(verset.begin()); - if (ShowError == true) - ioprintf(out, _("Virtual packages like '%s' can't be removed\n"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache, 0); - } - - APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, - APT::VersionSet::Version const &select) { - /* This is a pure virtual package and there is a single available - candidate providing it. */ - if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) - return APT::VersionSet(); - - pkgCache::PkgIterator Prov; - bool found_one = false; - for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; ++P) { - pkgCache::VerIterator const PVer = P.OwnerVer(); - pkgCache::PkgIterator const PPkg = PVer.ParentPkg(); - - /* Ignore versions that are not a candidate. */ - if (Cache[PPkg].CandidateVer != PVer) - continue; - - if (found_one == false) { - Prov = PPkg; - found_one = true; - } else if (PPkg != Prov) { - found_one = false; // we found at least two - break; - } - } - - if (found_one == true) { - ioprintf(out, _("Note, selecting '%s' instead of '%s'\n"), - Prov.FullName(true).c_str(), Pkg.FullName(true).c_str()); - return APT::VersionSet::FromPackage(Cache, Prov, select, *this); - } - return APT::VersionSet(); - } - - inline bool allPkgNamedExplicitly() const { return explicitlyNamed; } - -}; - /*}}}*/ // DoInstall - Install packages from the command line /*{{{*/ // --------------------------------------------------------------------- /* Install named packages */ -- cgit v1.2.3 From 2fbfb111312257fa5fc29b0c2ed386fb712f960e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 4 Jul 2010 00:32:52 +0200 Subject: prefer the Policy if it is built instead of the DepCache and if DepCache is not available as fallback built the Policy --- cmdline/apt-get.cc | 3 +++ cmdline/cacheset.cc | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 38b93e7e5..9a6c12ee0 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -768,6 +768,9 @@ struct TryToInstall { void operator() (pkgCache::VerIterator const &Ver) { pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + +std::clog << "INSTALL " << Pkg << " VER " << Ver.VerStr() << std::endl; + Cache->GetDepCache()->SetCandidateVersion(Ver); pkgDepCache::StateCache &State = (*Cache)[Pkg]; diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index b96b60450..78c9d3f6c 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -416,12 +416,13 @@ VersionSet VersionSet::FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator co pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { pkgCache::VerIterator Cand; - if (Cache.IsDepCacheBuilt() == true) - Cand = Cache[Pkg].CandidateVerIter(Cache); - else { + if (Cache.IsPolicyBuilt() == true || Cache.IsDepCacheBuilt() == false) + { if (unlikely(Cache.GetPolicy() == 0)) return pkgCache::VerIterator(Cache); Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); + } else { + Cand = Cache[Pkg].CandidateVerIter(Cache); } if (Cand.end() == true) return helper.canNotFindCandidateVer(Cache, Pkg); -- cgit v1.2.3 From 6806db8ac030ab7401b7b8b8324c62bb7b4a0275 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 5 Jul 2010 11:34:35 +0200 Subject: make the specify order of packages irrelevant (half-close #196021) --- cmdline/apt-get.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 9a6c12ee0..7cf760c27 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -762,6 +762,7 @@ struct TryToInstall { pkgProblemResolver* Fix; bool FixBroken; unsigned long AutoMarkChanged; + APT::PackageSet doAutoInstallLater; TryToInstall(pkgCacheFile &Cache, pkgProblemResolver &PM, bool const &FixBroken) : Cache(&Cache), Fix(&PM), FixBroken(FixBroken), AutoMarkChanged(0) {}; @@ -769,8 +770,6 @@ struct TryToInstall { void operator() (pkgCache::VerIterator const &Ver) { pkgCache::PkgIterator Pkg = Ver.ParentPkg(); -std::clog << "INSTALL " << Pkg << " VER " << Ver.VerStr() << std::endl; - Cache->GetDepCache()->SetCandidateVersion(Ver); pkgDepCache::StateCache &State = (*Cache)[Pkg]; @@ -801,8 +800,8 @@ std::clog << "INSTALL " << Pkg << " VER " << Ver.VerStr() << std::endl; // Install it with autoinstalling enabled (if we not respect the minial // required deps or the policy) - if ((State.InstBroken() == true || State.InstPolicyBroken() == true) && FixBroken == false) - Cache->GetDepCache()->MarkInstall(Pkg,true); + if (FixBroken == false) + doAutoInstallLater.insert(Pkg); } // see if we need to fix the auto-mark flag @@ -820,6 +819,17 @@ std::clog << "INSTALL " << Pkg << " VER " << Ver.VerStr() << std::endl; AutoMarkChanged++; } } + + void doAutoInstall() { + for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin(); + P != doAutoInstallLater.end(); ++P) { + pkgDepCache::StateCache &State = (*Cache)[P]; + if (State.InstBroken() == false && State.InstPolicyBroken() == false) + continue; + Cache->GetDepCache()->MarkInstall(P, true); + } + doAutoInstallLater.clear(); + } }; /*}}}*/ // TryToRemove - Mark a package for removal /*{{{*/ @@ -1336,6 +1346,7 @@ bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache, } else if (Cache[Pkg].CandidateVer != 0) { TryToInstall InstallAction(Cache, Fix, BrokenFix); InstallAction(Cache[Pkg].CandidateVerIter(Cache)); + InstallAction.doAutoInstall(); } else return AllowFail; @@ -1743,8 +1754,10 @@ bool DoInstall(CommandLine &CmdL) for (unsigned short i = 0; order[i] != 0; ++i) { - if (order[i] == MOD_INSTALL) + if (order[i] == MOD_INSTALL) { InstallAction = std::for_each(verset[MOD_INSTALL].begin(), verset[MOD_INSTALL].end(), InstallAction); + InstallAction.doAutoInstall(); + } else if (order[i] == MOD_REMOVE) RemoveAction = std::for_each(verset[MOD_REMOVE].begin(), verset[MOD_REMOVE].end(), RemoveAction); } -- cgit v1.2.3 From fe1af091b871f9af715d729e515f2e3a62802c6f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 16 Jul 2010 17:42:54 +0200 Subject: * cmdline/apt-cache.cc: - be able to omit dependency types in (r)depends (Closes: #319006) --- cmdline/apt-cache.cc | 77 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 15 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 338be7029..557996693 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -569,9 +569,18 @@ bool Depends(CommandLine &CmdL) for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; - bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool Installed = _config->FindB("APT::Cache::Installed",false); - bool Important = _config->FindB("APT::Cache::Important",false); + bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false); + bool const Installed = _config->FindB("APT::Cache::Installed", false); + bool const Important = _config->FindB("APT::Cache::Important", false); + bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",true); + bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); + bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); + bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); + bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false); + bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false); + bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); + bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); + bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); bool DidSomething; do { @@ -594,12 +603,17 @@ bool Depends(CommandLine &CmdL) for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) { - // Important deps only - if (Important == true) - if (D->Type != pkgCache::Dep::PreDepends && - D->Type != pkgCache::Dep::Depends) - continue; - + switch (D->Type) { + case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; + case pkgCache::Dep::Depends: if (!ShowDepends) continue; break; + case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break; + case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break; + case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; + case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break; + case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break; + case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; + } + pkgCache::PkgIterator Trg = D.TargetPkg(); if((Installed && Trg->CurrentVer != 0) || !Installed) @@ -611,10 +625,12 @@ bool Depends(CommandLine &CmdL) cout << " "; // Show the package + if (ShowDepType == true) + cout << D.DepType() << ": "; if (Trg->VersionList == 0) - cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; + cout << "<" << Trg.FullName(true) << ">" << endl; else - cout << D.DepType() << ": " << Trg.FullName(true) << endl; + cout << Trg.FullName(true) << endl; if (Recurse == true) Colours[D.TargetPkg()->ID]++; @@ -660,8 +676,18 @@ bool RDepends(CommandLine &CmdL) for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; - bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool Installed = _config->FindB("APT::Cache::Installed",false); + bool const Recurse = _config->FindB("APT::Cache::RecurseDepends",false); + bool const Installed = _config->FindB("APT::Cache::Installed",false); + bool const Important = _config->FindB("APT::Cache::Important", false); + bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",false); + bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); + bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); + bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); + bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false); + bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false); + bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); + bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); + bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); bool DidSomething; do { @@ -684,7 +710,18 @@ bool RDepends(CommandLine &CmdL) cout << "Reverse Depends:" << endl; for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++) - { + { + switch (D->Type) { + case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; + case pkgCache::Dep::Depends: if (!ShowDepends) continue; break; + case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break; + case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break; + case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; + case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break; + case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break; + case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; + } + // Show the package pkgCache::PkgIterator Trg = D.ParentPkg(); @@ -696,8 +733,10 @@ bool RDepends(CommandLine &CmdL) else cout << " "; + if (ShowDepType == true) + cout << D.DepType() << ": "; if (Trg->VersionList == 0) - cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; + cout << "<" << Trg.FullName(true) << ">" << endl; else cout << Trg.FullName(true) << endl; @@ -1820,6 +1859,14 @@ int main(int argc,const char *argv[]) /*{{{*/ {'c',"config-file",0,CommandLine::ConfigFile}, {'o',"option",0,CommandLine::ArbItem}, {0,"installed","APT::Cache::Installed",0}, + {0,"pre-depends","APT::Cache::ShowPreDepends",0}, + {0,"depends","APT::Cache::ShowDepends",0}, + {0,"recommends","APT::Cache::ShowRecommends",0}, + {0,"suggests","APT::Cache::ShowSuggests",0}, + {0,"replaces","APT::Cache::ShowReplaces",0}, + {0,"breaks","APT::Cache::ShowBreaks",0}, + {0,"conflicts","APT::Cache::ShowConflicts",0}, + {0,"enhances","APT::Cache::ShowEnhances",0}, {0,0,0,0}}; CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp}, {"add",&DoAdd}, -- cgit v1.2.3 From 9ba5aa3b01f1f7c08c74f5d0a21971db221d30f1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 17 Jul 2010 19:07:00 +0200 Subject: factor regex package name matches into newly created cachefilter classes --- cmdline/cacheset.cc | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'cmdline') diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc index 78c9d3f6c..0b099f442 100644 --- a/cmdline/cacheset.cc +++ b/cmdline/cacheset.cc @@ -10,6 +10,7 @@ /*}}}*/ // Include Files /*{{{*/ #include +#include #include #include #include @@ -97,22 +98,14 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, Cache arch = "native"; } - regex_t Pattern; - int Res; - if ((Res = regcomp(&Pattern, pattern.c_str() , REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0) { - char Error[300]; - regerror(Res, &Pattern, Error, sizeof(Error)); - _error->Error(_("Regex compilation error - %s"), Error); - return PackageSet(REGEX); - } - if (unlikely(Cache.GetPkgCache() == 0)) return PackageSet(REGEX); + APT::CacheFilter::PackageNameMatchesRegEx regexfilter(pattern); + PackageSet pkgset(REGEX); - for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) - { - if (regexec(&Pattern, Grp.Name(), 0, 0, 0) != 0) + for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { + if (regexfilter(Grp) == false) continue; pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); if (Pkg.end() == true) { @@ -128,7 +121,6 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, Cache pkgset.insert(Pkg); } - regfree(&Pattern); if (pkgset.empty() == true) return helper.canNotFindRegEx(Cache, pattern); -- cgit v1.2.3 From 8fde723961709118837153cdf94f150c680e10e9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 17 Jul 2010 20:04:44 +0200 Subject: * apt-pkg/cacheset.cc: - move them back to the library as they look stable now --- cmdline/apt-cache.cc | 3 +- cmdline/apt-get.cc | 2 +- cmdline/cacheset.cc | 507 --------------------------------------------------- cmdline/cacheset.h | 375 ------------------------------------- cmdline/makefile | 4 +- 5 files changed, 4 insertions(+), 887 deletions(-) delete mode 100644 cmdline/cacheset.cc delete mode 100644 cmdline/cacheset.h (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 557996693..1a1ddcb8c 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -30,8 +31,6 @@ #include #include -#include "cacheset.h" - #include #include diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 7cf760c27..eaa982856 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,6 @@ #include #include "acqprogress.h" -#include "cacheset.h" #include #include diff --git a/cmdline/cacheset.cc b/cmdline/cacheset.cc deleted file mode 100644 index 0b099f442..000000000 --- a/cmdline/cacheset.cc +++ /dev/null @@ -1,507 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/* ###################################################################### - - Simple wrapper around a std::set to provide a similar interface to - a set of cache structures as to the complete set of all structures - in the pkgCache. Currently only Package is supported. - - ##################################################################### */ - /*}}}*/ -// Include Files /*{{{*/ -#include -#include -#include -#include -#include - -#include - -#include "cacheset.h" - -#include - -#include - /*}}}*/ -namespace APT { -// FromTask - Return all packages in the cache from a specific task /*{{{*/ -PackageSet PackageSet::FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { - size_t const archfound = pattern.find_last_of(':'); - std::string arch = "native"; - if (archfound != std::string::npos) { - arch = pattern.substr(archfound+1); - pattern.erase(archfound); - } - - if (pattern[pattern.length() -1] != '^') - return APT::PackageSet(TASK); - pattern.erase(pattern.length()-1); - - if (unlikely(Cache.GetPkgCache() == 0 || Cache.GetDepCache() == 0)) - return APT::PackageSet(TASK); - - PackageSet pkgset(TASK); - // get the records - pkgRecords Recs(Cache); - - // build regexp for the task - regex_t Pattern; - char S[300]; - snprintf(S, sizeof(S), "^Task:.*[, ]%s([, ]|$)", pattern.c_str()); - if(regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0) { - _error->Error("Failed to compile task regexp"); - return pkgset; - } - - for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) { - pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); - if (Pkg.end() == true) - continue; - pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache); - if(ver.end() == true) - continue; - - pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); - const char *start, *end; - parser.GetRec(start,end); - unsigned int const length = end - start; - char buf[length]; - strncpy(buf, start, length); - buf[length-1] = '\0'; - if (regexec(&Pattern, buf, 0, 0, 0) != 0) - continue; - - pkgset.insert(Pkg); - } - regfree(&Pattern); - - if (pkgset.empty() == true) - return helper.canNotFindTask(Cache, pattern); - - helper.showTaskSelection(pkgset, pattern); - return pkgset; -} - /*}}}*/ -// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/ -PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { - static const char * const isregex = ".?+*|[^$"; - if (pattern.find_first_of(isregex) == std::string::npos) - return PackageSet(REGEX); - - size_t archfound = pattern.find_last_of(':'); - std::string arch = "native"; - if (archfound != std::string::npos) { - arch = pattern.substr(archfound+1); - if (arch.find_first_of(isregex) == std::string::npos) - pattern.erase(archfound); - else - arch = "native"; - } - - if (unlikely(Cache.GetPkgCache() == 0)) - return PackageSet(REGEX); - - APT::CacheFilter::PackageNameMatchesRegEx regexfilter(pattern); - - PackageSet pkgset(REGEX); - for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { - if (regexfilter(Grp) == false) - continue; - pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); - if (Pkg.end() == true) { - if (archfound == std::string::npos) { - std::vector archs = APT::Configuration::getArchitectures(); - for (std::vector::const_iterator a = archs.begin(); - a != archs.end() && Pkg.end() != true; ++a) - Pkg = Grp.FindPkg(*a); - } - if (Pkg.end() == true) - continue; - } - - pkgset.insert(Pkg); - } - - if (pkgset.empty() == true) - return helper.canNotFindRegEx(Cache, pattern); - - helper.showRegExSelection(pkgset, pattern); - return pkgset; -} - /*}}}*/ -// FromName - Returns the package defined by this string /*{{{*/ -pkgCache::PkgIterator PackageSet::FromName(pkgCacheFile &Cache, - std::string const &str, CacheSetHelper &helper) { - std::string pkg = str; - size_t archfound = pkg.find_last_of(':'); - std::string arch; - if (archfound != std::string::npos) { - arch = pkg.substr(archfound+1); - pkg.erase(archfound); - } - - if (Cache.GetPkgCache() == 0) - return pkgCache::PkgIterator(Cache, 0); - - pkgCache::PkgIterator Pkg(Cache, 0); - if (arch.empty() == true) { - pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); - if (Grp.end() == false) - Pkg = Grp.FindPreferredPkg(); - } else - Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch); - - if (Pkg.end() == true) - return helper.canNotFindPkgName(Cache, str); - return Pkg; -} - /*}}}*/ -// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ -std::map PackageSet::GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback, CacheSetHelper &helper) { - std::map pkgsets; - for (const char **I = cmdline; *I != 0; ++I) { - unsigned short modID = fallback; - std::string str = *I; - bool modifierPresent = false; - for (std::list::const_iterator mod = mods.begin(); - mod != mods.end(); ++mod) { - size_t const alength = strlen(mod->Alias); - switch(mod->Pos) { - case PackageSet::Modifier::POSTFIX: - if (str.compare(str.length() - alength, alength, - mod->Alias, 0, alength) != 0) - continue; - str.erase(str.length() - alength); - modID = mod->ID; - break; - case PackageSet::Modifier::PREFIX: - continue; - case PackageSet::Modifier::NONE: - continue; - } - modifierPresent = true; - break; - } - if (modifierPresent == true) { - bool const errors = helper.showErrors(false); - pkgCache::PkgIterator Pkg = FromName(Cache, *I, helper); - helper.showErrors(errors); - if (Pkg.end() == false) { - pkgsets[fallback].insert(Pkg); - continue; - } - } - pkgsets[modID].insert(PackageSet::FromString(Cache, str, helper)); - } - return pkgsets; -} - /*}}}*/ -// FromCommandLine - Return all packages specified on commandline /*{{{*/ -PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { - PackageSet pkgset; - for (const char **I = cmdline; *I != 0; ++I) { - PackageSet pset = FromString(Cache, *I, helper); - pkgset.insert(pset.begin(), pset.end()); - } - return pkgset; -} - /*}}}*/ -// FromString - Return all packages matching a specific string /*{{{*/ -PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) { - _error->PushToStack(); - - PackageSet pkgset; - pkgCache::PkgIterator Pkg = FromName(Cache, str, helper); - if (Pkg.end() == false) - pkgset.insert(Pkg); - else { - pkgset = FromTask(Cache, str, helper); - if (pkgset.empty() == true) { - pkgset = FromRegEx(Cache, str, helper); - if (pkgset.empty() == true) - pkgset = helper.canNotFindPackage(Cache, str); - } - } - - if (pkgset.empty() == false) - _error->RevertToStack(); - else - _error->MergeWithStack(); - return pkgset; -} - /*}}}*/ -// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/ -std::map VersionSet::GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback, CacheSetHelper &helper) { - std::map versets; - for (const char **I = cmdline; *I != 0; ++I) { - unsigned short modID = fallback; - VersionSet::Version select = VersionSet::NEWEST; - std::string str = *I; - bool modifierPresent = false; - for (std::list::const_iterator mod = mods.begin(); - mod != mods.end(); ++mod) { - if (modID == fallback && mod->ID == fallback) - select = mod->SelectVersion; - size_t const alength = strlen(mod->Alias); - switch(mod->Pos) { - case VersionSet::Modifier::POSTFIX: - if (str.compare(str.length() - alength, alength, - mod->Alias, 0, alength) != 0) - continue; - str.erase(str.length() - alength); - modID = mod->ID; - select = mod->SelectVersion; - break; - case VersionSet::Modifier::PREFIX: - continue; - case VersionSet::Modifier::NONE: - continue; - } - modifierPresent = true; - break; - } - - if (modifierPresent == true) { - bool const errors = helper.showErrors(false); - VersionSet const vset = VersionSet::FromString(Cache, std::string(*I), select, helper, true); - helper.showErrors(errors); - if (vset.empty() == false) { - versets[fallback].insert(vset); - continue; - } - } - versets[modID].insert(VersionSet::FromString(Cache, str, select , helper)); - } - return versets; -} - /*}}}*/ -// FromCommandLine - Return all versions specified on commandline /*{{{*/ -APT::VersionSet VersionSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper) { - VersionSet verset; - for (const char **I = cmdline; *I != 0; ++I) - verset.insert(VersionSet::FromString(Cache, *I, fallback, helper)); - return verset; -} - /*}}}*/ -// FromString - Returns all versions spedcified by a string /*{{{*/ -APT::VersionSet VersionSet::FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper, - bool const &onlyFromName) { - std::string ver; - bool verIsRel = false; - size_t const vertag = pkg.find_last_of("/="); - if (vertag != string::npos) { - ver = pkg.substr(vertag+1); - verIsRel = (pkg[vertag] == '/'); - pkg.erase(vertag); - } - PackageSet pkgset; - if (onlyFromName == false) - pkgset = PackageSet::FromString(Cache, pkg, helper); - else { - pkgset.insert(PackageSet::FromName(Cache, pkg, helper)); - } - - VersionSet verset; - bool errors = true; - if (pkgset.getConstructor() != PackageSet::UNKNOWN) - errors = helper.showErrors(false); - for (PackageSet::const_iterator P = pkgset.begin(); - P != pkgset.end(); ++P) { - if (vertag == string::npos) { - verset.insert(VersionSet::FromPackage(Cache, P, fallback, helper)); - continue; - } - pkgCache::VerIterator V; - if (ver == "installed") - V = getInstalledVer(Cache, P, helper); - else if (ver == "candidate") - V = getCandidateVer(Cache, P, helper); - else { - pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : - pkgVersionMatch::Version)); - V = Match.Find(P); - if (V.end() == true) { - if (verIsRel == true) - _error->Error(_("Release '%s' for '%s' was not found"), - ver.c_str(), P.FullName(true).c_str()); - else - _error->Error(_("Version '%s' for '%s' was not found"), - ver.c_str(), P.FullName(true).c_str()); - continue; - } - } - if (V.end() == true) - continue; - helper.showSelectedVersion(P, V, ver, verIsRel); - verset.insert(V); - } - if (pkgset.getConstructor() != PackageSet::UNKNOWN) - helper.showErrors(errors); - return verset; -} - /*}}}*/ -// FromPackage - versions from package based on fallback /*{{{*/ -VersionSet VersionSet::FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, - VersionSet::Version const &fallback, CacheSetHelper &helper) { - VersionSet verset; - pkgCache::VerIterator V; - bool showErrors; - switch(fallback) { - case VersionSet::ALL: - if (P->VersionList != 0) - for (V = P.VersionList(); V.end() != true; ++V) - verset.insert(V); - else - verset.insert(helper.canNotFindAllVer(Cache, P)); - break; - case VersionSet::CANDANDINST: - verset.insert(getInstalledVer(Cache, P, helper)); - verset.insert(getCandidateVer(Cache, P, helper)); - break; - case VersionSet::CANDIDATE: - verset.insert(getCandidateVer(Cache, P, helper)); - break; - case VersionSet::INSTALLED: - verset.insert(getInstalledVer(Cache, P, helper)); - break; - case VersionSet::CANDINST: - showErrors = helper.showErrors(false); - V = getCandidateVer(Cache, P, helper); - if (V.end() == true) - V = getInstalledVer(Cache, P, helper); - helper.showErrors(showErrors); - if (V.end() == false) - verset.insert(V); - else - verset.insert(helper.canNotFindInstCandVer(Cache, P)); - break; - case VersionSet::INSTCAND: - showErrors = helper.showErrors(false); - V = getInstalledVer(Cache, P, helper); - if (V.end() == true) - V = getCandidateVer(Cache, P, helper); - helper.showErrors(showErrors); - if (V.end() == false) - verset.insert(V); - else - verset.insert(helper.canNotFindInstCandVer(Cache, P)); - break; - case VersionSet::NEWEST: - if (P->VersionList != 0) - verset.insert(P.VersionList()); - else - verset.insert(helper.canNotFindNewestVer(Cache, P)); - break; - } - return verset; -} - /*}}}*/ -// getCandidateVer - Returns the candidate version of the given package /*{{{*/ -pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { - pkgCache::VerIterator Cand; - if (Cache.IsPolicyBuilt() == true || Cache.IsDepCacheBuilt() == false) - { - if (unlikely(Cache.GetPolicy() == 0)) - return pkgCache::VerIterator(Cache); - Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); - } else { - Cand = Cache[Pkg].CandidateVerIter(Cache); - } - if (Cand.end() == true) - return helper.canNotFindCandidateVer(Cache, Pkg); - return Cand; -} - /*}}}*/ -// getInstalledVer - Returns the installed version of the given package /*{{{*/ -pkgCache::VerIterator VersionSet::getInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { - if (Pkg->CurrentVer == 0) - return helper.canNotFindInstalledVer(Cache, Pkg); - return Pkg.CurrentVer(); -} - /*}}}*/ -// canNotFindPkgName - handle the case no package has this name /*{{{*/ -pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache, - std::string const &str) { - if (ShowError == true) - _error->Error(_("Unable to locate package %s"), str.c_str()); - return pkgCache::PkgIterator(Cache, 0); -} - /*}}}*/ -// canNotFindTask - handle the case no package is found for a task /*{{{*/ -PackageSet CacheSetHelper::canNotFindTask(pkgCacheFile &Cache, std::string pattern) { - if (ShowError == true) - _error->Error(_("Couldn't find task '%s'"), pattern.c_str()); - return PackageSet(); -} - /*}}}*/ -// canNotFindRegEx - handle the case no package is found by a regex /*{{{*/ -PackageSet CacheSetHelper::canNotFindRegEx(pkgCacheFile &Cache, std::string pattern) { - if (ShowError == true) - _error->Error(_("Couldn't find any package by regex '%s'"), pattern.c_str()); - return PackageSet(); -} - /*}}}*/ -// canNotFindPackage - handle the case no package is found from a string/*{{{*/ -PackageSet CacheSetHelper::canNotFindPackage(pkgCacheFile &Cache, std::string const &str) { - return PackageSet(); -} - /*}}}*/ -// canNotFindAllVer /*{{{*/ -VersionSet CacheSetHelper::canNotFindAllVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select versions from package '%s' as it purely virtual"), Pkg.FullName(true).c_str()); - return VersionSet(); -} - /*}}}*/ -// canNotFindInstCandVer /*{{{*/ -VersionSet CacheSetHelper::canNotFindInstCandVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); - return VersionSet(); -} - /*}}}*/ -// canNotFindInstCandVer /*{{{*/ -VersionSet CacheSetHelper::canNotFindCandInstVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); - return VersionSet(); -} - /*}}}*/ -// canNotFindNewestVer /*{{{*/ -pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache, 0); -} - /*}}}*/ -// canNotFindCandidateVer /*{{{*/ -pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache, 0); -} - /*}}}*/ -// canNotFindInstalledVer /*{{{*/ -pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg) { - if (ShowError == true) - _error->Error(_("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); - return pkgCache::VerIterator(Cache, 0); -} - /*}}}*/ -} diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h deleted file mode 100644 index c8c3dd096..000000000 --- a/cmdline/cacheset.h +++ /dev/null @@ -1,375 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/** \file cacheset.h - Wrappers around std::set to have set::iterators which behave - similar to the Iterators of the cache structures. - - Provides also a few helper methods which work with these sets */ - /*}}}*/ -#ifndef APT_CACHESET_H -#define APT_CACHESET_H -// Include Files /*{{{*/ -#include -#include -#include -#include -#include -#include - -#include -#include - /*}}}*/ -namespace APT { -class PackageSet; -class VersionSet; -class CacheSetHelper { /*{{{*/ -/** \class APT::CacheSetHelper - Simple base class with a lot of virtual methods which can be overridden - to alter the behavior or the output of the CacheSets. - - This helper is passed around by the static methods in the CacheSets and - used every time they hit an error condition or something could be - printed out. -*/ -public: /*{{{*/ - CacheSetHelper(bool const &ShowError = true) : ShowError(ShowError) {}; - virtual ~CacheSetHelper() {}; - - virtual void showTaskSelection(PackageSet const &pkgset, string const &pattern) {}; - virtual void showRegExSelection(PackageSet const &pkgset, string const &pattern) {}; - virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, - string const &ver, bool const &verIsRel) {}; - - virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); - virtual PackageSet canNotFindTask(pkgCacheFile &Cache, std::string pattern); - virtual PackageSet canNotFindRegEx(pkgCacheFile &Cache, std::string pattern); - virtual PackageSet canNotFindPackage(pkgCacheFile &Cache, std::string const &str); - virtual VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - virtual VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - virtual VersionSet canNotFindCandInstVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg); - - bool showErrors() const { return ShowError; }; - bool showErrors(bool const &newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }; - /*}}}*/ -protected: - bool ShowError; -}; /*}}}*/ -class PackageSet : public std::set { /*{{{*/ -/** \class APT::PackageSet - - Simple wrapper around a std::set to provide a similar interface to - a set of packages as to the complete set of all packages in the - pkgCache. */ -public: /*{{{*/ - /** \brief smell like a pkgCache::PkgIterator */ - class const_iterator : public std::set::const_iterator {/*{{{*/ - public: - const_iterator(std::set::const_iterator x) : - std::set::const_iterator(x) {} - - operator pkgCache::PkgIterator(void) { return **this; } - - inline const char *Name() const {return (**this).Name(); } - inline std::string FullName(bool const &Pretty) const { return (**this).FullName(Pretty); } - inline std::string FullName() const { return (**this).FullName(); } - inline const char *Section() const {return (**this).Section(); } - inline bool Purge() const {return (**this).Purge(); } - inline const char *Arch() const {return (**this).Arch(); } - inline pkgCache::GrpIterator Group() const { return (**this).Group(); } - inline pkgCache::VerIterator VersionList() const { return (**this).VersionList(); } - inline pkgCache::VerIterator CurrentVer() const { return (**this).CurrentVer(); } - inline pkgCache::DepIterator RevDependsList() const { return (**this).RevDependsList(); } - inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); } - inline pkgCache::PkgIterator::OkState State() const { return (**this).State(); } - inline const char *CandVersion() const { return (**this).CandVersion(); } - inline const char *CurVersion() const { return (**this).CurVersion(); } - inline pkgCache *Cache() const { return (**this).Cache(); }; - inline unsigned long Index() const {return (**this).Index();}; - // we have only valid iterators here - inline bool end() const { return false; }; - - friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } - - inline pkgCache::Package const * operator->() const { - return &***this; - }; - }; - // 103. set::iterator is required to be modifiable, but this allows modification of keys - typedef APT::PackageSet::const_iterator iterator; - /*}}}*/ - - using std::set::insert; - inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; - inline void insert(PackageSet const &pkgset) { insert(pkgset.begin(), pkgset.end()); }; - - /** \brief returns all packages in the cache who belong to the given task - - A simple helper responsible for search for all members of a task - in the cache. Optional it prints a a notice about the - packages chosen cause of the given task. - \param Cache the packages are in - \param pattern name of the task - \param helper responsible for error and message handling */ - static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); - static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { - CacheSetHelper helper; - return APT::PackageSet::FromTask(Cache, pattern, helper); - } - - /** \brief returns all packages in the cache whose name matchs a given pattern - - A simple helper responsible for executing a regular expression on all - package names in the cache. Optional it prints a a notice about the - packages chosen cause of the given package. - \param Cache the packages are in - \param pattern regular expression for package names - \param helper responsible for error and message handling */ - static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); - static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { - CacheSetHelper helper; - return APT::PackageSet::FromRegEx(Cache, pattern, helper); - } - - /** \brief returns all packages specified by a string - - \param Cache the packages are in - \param string String the package name(s) should be extracted from - \param helper responsible for error and message handling */ - static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); - static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { - CacheSetHelper helper; - return APT::PackageSet::FromString(Cache, string, helper); - } - - /** \brief returns a package specified by a string - - \param Cache the package is in - \param string String the package name should be extracted from - \param helper responsible for error and message handling */ - static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); - static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string) { - CacheSetHelper helper; - return APT::PackageSet::FromName(Cache, string, helper); - } - - /** \brief returns all packages specified on the commandline - - Get all package names from the commandline and executes regex's if needed. - No special package command is supported, just plain names. - \param Cache the packages are in - \param cmdline Command line the package names should be extracted from - \param helper responsible for error and message handling */ - static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); - static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { - CacheSetHelper helper; - return APT::PackageSet::FromCommandLine(Cache, cmdline, helper); - } - - struct Modifier { - enum Position { NONE, PREFIX, POSTFIX }; - unsigned short ID; - const char * const Alias; - Position Pos; - Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; - }; - - /** \brief group packages by a action modifiers - - At some point it is needed to get from the same commandline - different package sets grouped by a modifier. Take - apt-get install apt awesome- - as an example. - \param Cache the packages are in - \param cmdline Command line the package names should be extracted from - \param mods list of modifiers the method should accept - \param fallback the default modifier group for a package - \param helper responsible for error and message handling */ - static std::map GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback, CacheSetHelper &helper); - static std::map GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback) { - CacheSetHelper helper; - return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, - mods, fallback, helper); - } - - enum Constructor { UNKNOWN, REGEX, TASK }; - Constructor getConstructor() const { return ConstructedBy; }; - - PackageSet() : ConstructedBy(UNKNOWN) {}; - PackageSet(Constructor const &by) : ConstructedBy(by) {}; - /*}}}*/ -private: /*{{{*/ - Constructor ConstructedBy; - /*}}}*/ -}; /*}}}*/ -class VersionSet : public std::set { /*{{{*/ -/** \class APT::VersionSet - - Simple wrapper around a std::set to provide a similar interface to - a set of versions as to the complete set of all versions in the - pkgCache. */ -public: /*{{{*/ - /** \brief smell like a pkgCache::VerIterator */ - class const_iterator : public std::set::const_iterator {/*{{{*/ - public: - const_iterator(std::set::const_iterator x) : - std::set::const_iterator(x) {} - - operator pkgCache::VerIterator(void) { return **this; } - - inline pkgCache *Cache() const { return (**this).Cache(); }; - inline unsigned long Index() const {return (**this).Index();}; - // we have only valid iterators here - inline bool end() const { return false; }; - - inline pkgCache::Version const * operator->() const { - return &***this; - }; - - inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); }; - inline const char *VerStr() const { return (**this).VerStr(); }; - inline const char *Section() const { return (**this).Section(); }; - inline const char *Arch() const { return (**this).Arch(); }; - inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); }; - inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); }; - inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); }; - inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); }; - inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); }; - inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }; - inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); }; - inline bool Downloadable() const { return (**this).Downloadable(); }; - inline const char *PriorityType() const { return (**this).PriorityType(); }; - inline string RelStr() const { return (**this).RelStr(); }; - inline bool Automatic() const { return (**this).Automatic(); }; - inline bool Pseudo() const { return (**this).Pseudo(); }; - inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); }; - }; - /*}}}*/ - // 103. set::iterator is required to be modifiable, but this allows modification of keys - typedef APT::VersionSet::const_iterator iterator; - - using std::set::insert; - inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set::insert(V); }; - inline void insert(VersionSet const &verset) { insert(verset.begin(), verset.end()); }; - - /** \brief specifies which version(s) will be returned if non is given */ - enum Version { - /** All versions */ - ALL, - /** Candidate and installed version */ - CANDANDINST, - /** Candidate version */ - CANDIDATE, - /** Installed version */ - INSTALLED, - /** Candidate or if non installed version */ - CANDINST, - /** Installed or if non candidate version */ - INSTCAND, - /** Newest version */ - NEWEST - }; - - /** \brief returns all versions specified on the commandline - - Get all versions from the commandline, uses given default version if - non specifically requested and executes regex's if needed on names. - \param Cache the packages and versions are in - \param cmdline Command line the versions should be extracted from - \param helper responsible for error and message handling */ - static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper); - static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - APT::VersionSet::Version const &fallback) { - CacheSetHelper helper; - return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, helper); - } - static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { - return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); - } - - static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper, - bool const &onlyFromName = false); - static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback) { - CacheSetHelper helper; - return APT::VersionSet::FromString(Cache, pkg, fallback, helper); - } - static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg) { - return APT::VersionSet::FromString(Cache, pkg, CANDINST); - } - - /** \brief returns all versions specified for the package - - \param Cache the package and versions are in - \param P the package in question - \param fallback the version(s) you want to get - \param helper the helper used for display and error handling */ - static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, - VersionSet::Version const &fallback, CacheSetHelper &helper); - static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, - APT::VersionSet::Version const &fallback) { - CacheSetHelper helper; - return APT::VersionSet::FromPackage(Cache, P, fallback, helper); - } - static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { - return APT::VersionSet::FromPackage(Cache, P, CANDINST); - } - - struct Modifier { - enum Position { NONE, PREFIX, POSTFIX }; - unsigned short ID; - const char * const Alias; - Position Pos; - VersionSet::Version SelectVersion; - Modifier (unsigned short const &id, const char * const alias, Position const &pos, - VersionSet::Version const &select) : ID(id), Alias(alias), Pos(pos), - SelectVersion(select) {}; - }; - - static std::map GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback, CacheSetHelper &helper); - static std::map GroupedFromCommandLine( - pkgCacheFile &Cache, const char **cmdline, - std::list const &mods, - unsigned short const &fallback) { - CacheSetHelper helper; - return APT::VersionSet::GroupedFromCommandLine(Cache, cmdline, - mods, fallback, helper); - } - /*}}}*/ -protected: /*{{{*/ - - /** \brief returns the candidate version of the package - - \param Cache to be used to query for information - \param Pkg we want the candidate version from this package */ - static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); - - /** \brief returns the installed version of the package - - \param Cache to be used to query for information - \param Pkg we want the installed version from this package */ - static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); - /*}}}*/ -}; /*}}}*/ -} -#endif diff --git a/cmdline/makefile b/cmdline/makefile index 4ffe49ee0..917ccc96a 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -9,14 +9,14 @@ include ../buildlib/defaults.mak PROGRAM=apt-cache SLIBS = -lapt-pkg $(INTLLIBS) LIB_MAKES = apt-pkg/makefile -SOURCE = apt-cache.cc cacheset.cc +SOURCE = apt-cache.cc include $(PROGRAM_H) # The apt-get program PROGRAM=apt-get SLIBS = -lapt-pkg -lutil $(INTLLIBS) LIB_MAKES = apt-pkg/makefile -SOURCE = apt-get.cc acqprogress.cc cacheset.cc +SOURCE = apt-get.cc acqprogress.cc include $(PROGRAM_H) # The apt-config program -- cgit v1.2.3 From a5032f842366f482371173d030e505d79366fd19 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 26 Jul 2010 09:22:53 +0200 Subject: add APT::Cache::ShowOnlyFirstOr option to print only the first alternative in the apt-cache (r)depends commands --- cmdline/apt-cache.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 1a1ddcb8c..88bf3a049 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -580,6 +580,7 @@ bool Depends(CommandLine &CmdL) bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); + bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); bool DidSomething; do { @@ -618,7 +619,7 @@ bool Depends(CommandLine &CmdL) if((Installed && Trg->CurrentVer != 0) || !Installed) { - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) + if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false) cout << " |"; else cout << " "; @@ -650,6 +651,9 @@ bool Depends(CommandLine &CmdL) if (Recurse == true) Colours[D.ParentPkg()->ID]++; } + + if (ShowOnlyFirstOr == true) + while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } } } @@ -687,6 +691,7 @@ bool RDepends(CommandLine &CmdL) bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); + bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); bool DidSomething; do { @@ -727,7 +732,7 @@ bool RDepends(CommandLine &CmdL) if((Installed && Trg->CurrentVer != 0) || !Installed) { - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) + if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false) cout << " |"; else cout << " "; @@ -758,6 +763,9 @@ bool RDepends(CommandLine &CmdL) if (Recurse == true) Colours[D.ParentPkg()->ID]++; } + + if (ShowOnlyFirstOr == true) + while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } } } -- cgit v1.2.3 From 3de4647b39216259678f40f4bf6e8122acd923b5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 26 Jul 2010 12:43:25 +0200 Subject: - show in (r)depends the canidate per default instead of newest - share the (r)depends code instead of codecopy --- cmdline/apt-cache.cc | 210 ++++++++++++++++----------------------------------- 1 file changed, 64 insertions(+), 146 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 88bf3a049..70732e4d0 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -551,27 +551,40 @@ bool DumpAvail(CommandLine &Cmd) return !_error->PendingError(); } /*}}}*/ -// Depends - Print out a dependency tree /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool Depends(CommandLine &CmdL) +// ShowDepends - Helper for printing out a dependency tree /*{{{*/ +class CacheSetHelperDepends: public APT::CacheSetHelper { +public: + APT::PackageSet virtualPkgs; + + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return pkgCache::VerIterator(Cache, 0); + } + + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return pkgCache::VerIterator(Cache, 0); + } + + CacheSetHelperDepends() : CacheSetHelper(false) {} +}; +bool ShowDepends(CommandLine &CmdL, bool const RevDepends) { pkgCacheFile CacheFile; pkgCache *Cache = CacheFile.GetPkgCache(); if (unlikely(Cache == NULL)) return false; - SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - Colours[Pkg->ID] = 1; + CacheSetHelperDepends helper; + APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); + if (verset.empty() == true && helper.virtualPkgs.empty() == true) + return false; + std::vector Shown(Cache->Head().PackageCount); bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false); bool const Installed = _config->FindB("APT::Cache::Installed", false); bool const Important = _config->FindB("APT::Cache::Important", false); - bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",true); + bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false); bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); @@ -581,27 +594,20 @@ bool Depends(CommandLine &CmdL) bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); - bool DidSomething; - do + + while (verset.empty() != true) { - DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) - { - if (Colours[Pkg->ID] != 1) - continue; - Colours[Pkg->ID] = 2; - DidSomething = true; - - pkgCache::VerIterator Ver = Pkg.VersionList(); - if (Ver.end() == true) - { - cout << '<' << Pkg.FullName(true) << '>' << endl; - continue; - } - + pkgCache::VerIterator Ver = *verset.begin(); + verset.erase(verset.begin()); + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + Shown[Pkg->ID] = true; + cout << Pkg.FullName(true) << endl; - - for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) + + if (RevDepends == true) + cout << "Reverse Depends:" << endl; + for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList(); + D.end() == false; D++) { switch (D->Type) { case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; @@ -614,7 +620,7 @@ bool Depends(CommandLine &CmdL) case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; } - pkgCache::PkgIterator Trg = D.TargetPkg(); + pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg(); if((Installed && Trg->CurrentVer != 0) || !Installed) { @@ -632,8 +638,11 @@ bool Depends(CommandLine &CmdL) else cout << Trg.FullName(true) << endl; - if (Recurse == true) - Colours[D.TargetPkg()->ID]++; + if (Recurse == true && Shown[Trg->ID] == false) + { + Shown[Trg->ID] = true; + verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::VersionSet::CANDIDATE, helper)); + } } @@ -647,131 +656,40 @@ bool Depends(CommandLine &CmdL) V->ParentPkg == D->Package) continue; cout << " " << V.ParentPkg().FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; + + if (Recurse == true && Shown[V.ParentPkg()->ID] == false) + { + Shown[V.ParentPkg()->ID] = true; + verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::VersionSet::CANDIDATE, helper)); + } } if (ShowOnlyFirstOr == true) while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } - } - } - while (DidSomething == true); - + } + + for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin(); + Pkg != helper.virtualPkgs.end(); ++Pkg) + cout << '<' << Pkg.FullName(true) << '>' << endl; + return true; } /*}}}*/ -// RDepends - Print out a reverse dependency tree - mbc /*{{{*/ +// Depends - Print out a dependency tree /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool Depends(CommandLine &CmdL) +{ + return ShowDepends(CmdL, false); +} + /*}}}*/ +// RDepends - Print out a reverse dependency tree /*{{{*/ // --------------------------------------------------------------------- /* */ bool RDepends(CommandLine &CmdL) { - pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - if (unlikely(Cache == NULL)) - return false; - - SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - Colours[Pkg->ID] = 1; - - bool const Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool const Installed = _config->FindB("APT::Cache::Installed",false); - bool const Important = _config->FindB("APT::Cache::Important", false); - bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",false); - bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); - bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); - bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); - bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false); - bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false); - bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); - bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); - bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); - bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); - bool DidSomething; - do - { - DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) - { - if (Colours[Pkg->ID] != 1) - continue; - Colours[Pkg->ID] = 2; - DidSomething = true; - - pkgCache::VerIterator Ver = Pkg.VersionList(); - if (Ver.end() == true) - { - cout << '<' << Pkg.FullName(true) << '>' << endl; - continue; - } - - cout << Pkg.FullName(true) << endl; - - cout << "Reverse Depends:" << endl; - for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++) - { - switch (D->Type) { - case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; - case pkgCache::Dep::Depends: if (!ShowDepends) continue; break; - case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break; - case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break; - case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; - case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break; - case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break; - case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; - } - - // Show the package - pkgCache::PkgIterator Trg = D.ParentPkg(); - - if((Installed && Trg->CurrentVer != 0) || !Installed) - { - - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false) - cout << " |"; - else - cout << " "; - - if (ShowDepType == true) - cout << D.DepType() << ": "; - if (Trg->VersionList == 0) - cout << "<" << Trg.FullName(true) << ">" << endl; - else - cout << Trg.FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; - - } - - // Display all solutions - SPtrArray List = D.AllTargets(); - pkgPrioSortList(*Cache,List); - for (pkgCache::Version **I = List; *I != 0; I++) - { - pkgCache::VerIterator V(*Cache,*I); - if (V != Cache->VerP + V.ParentPkg()->VersionList || - V->ParentPkg == D->Package) - continue; - cout << " " << V.ParentPkg().FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; - } - - if (ShowOnlyFirstOr == true) - while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; - } - } - } - while (DidSomething == true); - - return true; + return ShowDepends(CmdL, true); } /*}}}*/ // xvcg - Generate a graph for xvcg /*{{{*/ -- cgit v1.2.3 From 4b12ea903c5166e6215764e6507f6271782df6ff Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 27 Jul 2010 13:27:26 +0200 Subject: * cmdline/apt-get.cc: - Support large filesystems by using statvfs64() instead of statvfs() and statfs64() instead of statfs() (Closes: #590513). --- cmdline/apt-get.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 7cf760c27..a6dfd82ed 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -25,6 +25,9 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE + #include #include #include @@ -63,6 +66,9 @@ #include #include #include + +#define statfs statfs64 +#define statvfs statvfs64 /*}}}*/ #define RAMFS_MAGIC 0x858458f6 -- cgit v1.2.3 From cd7bbc479f8e2f277092a9557bb486ab664deba6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 30 Jul 2010 09:51:42 +0200 Subject: - [ABI BREAK] add an ErrorType option to CacheSetHelper * cmdline/apt-cache.cc: - use Notice instead of Error in the CacheSetHelper messages for compat reasons. Otherwise tools like sbuild blow up --- cmdline/apt-cache.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 70732e4d0..2a4e200a7 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -173,7 +173,9 @@ bool UnMet(CommandLine &CmdL) } else { - APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::CacheSetHelper helper(true, GlobalError::NOTICE); + APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, + APT::VersionSet::CANDIDATE, helper); for (APT::VersionSet::iterator V = verset.begin(); V != verset.end(); ++V) if (ShowUnMet(V, Important) == false) return false; @@ -187,7 +189,8 @@ bool UnMet(CommandLine &CmdL) bool DumpPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::CacheSetHelper helper(true, GlobalError::NOTICE); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1, helper); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { @@ -566,7 +569,7 @@ public: return pkgCache::VerIterator(Cache, 0); } - CacheSetHelperDepends() : CacheSetHelper(false) {} + CacheSetHelperDepends() : CacheSetHelper(false, GlobalError::NOTICE) {} }; bool ShowDepends(CommandLine &CmdL, bool const RevDepends) { @@ -754,11 +757,12 @@ bool XVcg(CommandLine &CmdL) } // Load the list of packages from the command line into the show list + APT::CacheSetHelper helper(true, GlobalError::NOTICE); std::list mods; mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX)); mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX)); std::map pkgsets = - APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0); + APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper); for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin(); Pkg != pkgsets[0].end(); ++Pkg) @@ -968,11 +972,12 @@ bool Dotty(CommandLine &CmdL) } // Load the list of packages from the command line into the show list + APT::CacheSetHelper helper(true, GlobalError::NOTICE); std::list mods; mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX)); mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX)); std::map pkgsets = - APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0); + APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper); for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin(); Pkg != pkgsets[0].end(); ++Pkg) @@ -1403,9 +1408,10 @@ bool ShowAuto(CommandLine &CmdL) bool ShowPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; + APT::CacheSetHelper helper(true, GlobalError::NOTICE); APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? APT::VersionSet::ALL : APT::VersionSet::CANDIDATE; - APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select); + APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) if (DisplayRecord(CacheFile, Ver) == false) return false; @@ -1564,7 +1570,8 @@ bool Policy(CommandLine &CmdL) (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; // Print out detailed information for each package - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::CacheSetHelper helper(true, GlobalError::NOTICE); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1, helper); for (APT::PackageSet::const_iterator I = pkgset.begin(); I != pkgset.end(); ++I) { pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); @@ -1644,7 +1651,8 @@ bool Madison(CommandLine &CmdL) if (_error->PendingError() == true) _error->Discard(); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::CacheSetHelper helper(true, GlobalError::NOTICE); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1, helper); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (Pkg.end() == false) -- cgit v1.2.3 From 65f810811a5f66a934f933900c185bfd012a6b3e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 30 Jul 2010 11:02:24 +0200 Subject: - return success in show if a virtual package was given * --- cmdline/apt-cache.cc | 64 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 26 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 2a4e200a7..6813d2978 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -46,6 +46,29 @@ using namespace std; +// CacheSetHelper saving virtual packages /*{{{*/ +class CacheSetHelperVirtuals: public APT::CacheSetHelper { +public: + APT::PackageSet virtualPkgs; + + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotFindCandidateVer(Cache, Pkg); + } + + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotFindNewestVer(Cache, Pkg); + } + + virtual APT::VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotFindAllVer(Cache, Pkg); + } + + CacheSetHelperVirtuals(bool const &ShowErrors = true, GlobalError::MsgType const &ErrorType = GlobalError::NOTICE) : CacheSetHelper(ShowErrors, ErrorType) {} +}; + /*}}}*/ // LocalitySort - Sort a version list by package file locality /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -173,7 +196,7 @@ bool UnMet(CommandLine &CmdL) } else { - APT::CacheSetHelper helper(true, GlobalError::NOTICE); + CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); for (APT::VersionSet::iterator V = verset.begin(); V != verset.end(); ++V) @@ -555,22 +578,6 @@ bool DumpAvail(CommandLine &Cmd) } /*}}}*/ // ShowDepends - Helper for printing out a dependency tree /*{{{*/ -class CacheSetHelperDepends: public APT::CacheSetHelper { -public: - APT::PackageSet virtualPkgs; - - virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - virtualPkgs.insert(Pkg); - return pkgCache::VerIterator(Cache, 0); - } - - virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { - virtualPkgs.insert(Pkg); - return pkgCache::VerIterator(Cache, 0); - } - - CacheSetHelperDepends() : CacheSetHelper(false, GlobalError::NOTICE) {} -}; bool ShowDepends(CommandLine &CmdL, bool const RevDepends) { pkgCacheFile CacheFile; @@ -578,7 +585,7 @@ bool ShowDepends(CommandLine &CmdL, bool const RevDepends) if (unlikely(Cache == NULL)) return false; - CacheSetHelperDepends helper; + CacheSetHelperVirtuals helper(false); APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); if (verset.empty() == true && helper.virtualPkgs.empty() == true) return false; @@ -1408,7 +1415,7 @@ bool ShowAuto(CommandLine &CmdL) bool ShowPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; - APT::CacheSetHelper helper(true, GlobalError::NOTICE); + CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? APT::VersionSet::ALL : APT::VersionSet::CANDIDATE; APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); @@ -1416,9 +1423,14 @@ bool ShowPackage(CommandLine &CmdL) if (DisplayRecord(CacheFile, Ver) == false) return false; - if (verset.empty() == false) - return true; - return _error->Error(_("No packages found")); + if (verset.empty() == true) + { + if (helper.virtualPkgs.empty() == true) + return _error->Error(_("No packages found")); + else + _error->Notice(_("No packages found")); + } + return true; } /*}}}*/ // ShowPkgNames - Show package names /*{{{*/ @@ -1491,10 +1503,10 @@ bool ShowSrcPackage(CommandLine &CmdL) _error->Warning(_("Unable to locate package %s"),*I); continue; } - } - if (found > 0) - return true; - return _error->Error(_("No packages found")); + } + if (found == 0) + _error->Notice(_("No packages found")); + return true; } /*}}}*/ // Policy - Show the results of the preferences file /*{{{*/ -- cgit v1.2.3