From 6fddb156b51b443781aa376e60e443eda09d1cad Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 10 Feb 2012 19:34:35 +0100 Subject: * cmdline/apt-mark.cc: - detect if dpkg has multiarch support before calling --set-selections --- cmdline/apt-mark.cc | 129 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 112 insertions(+), 17 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index c7d9b6f6a..b067413e3 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -14,9 +14,15 @@ #include #include #include +#include #include +#include #include +#include +#include +#include +#include #include /*}}}*/ @@ -158,6 +164,56 @@ bool DoHold(CommandLine &CmdL) if (unlikely(Cache == NULL)) return false; + // Generate the base argument list for dpkg + std::vector Args; + string Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + { + string const dpkgChrootDir = _config->FindDir("DPkg::Chroot-Directory", "/"); + size_t dpkgChrootLen = dpkgChrootDir.length(); + if (dpkgChrootDir != "/" && Tmp.find(dpkgChrootDir) == 0) + { + if (dpkgChrootDir[dpkgChrootLen - 1] == '/') + --dpkgChrootLen; + Tmp = Tmp.substr(dpkgChrootLen); + } + } + Args.push_back(Tmp.c_str()); + + // Stick in any custom dpkg options + Configuration::Item const *Opts = _config->Tree("DPkg::Options"); + if (Opts != 0) + { + Opts = Opts->Child; + for (; Opts != 0; Opts = Opts->Next) + { + if (Opts->Value.empty() == true) + continue; + Args.push_back(Opts->Value.c_str()); + } + } + + size_t const BaseArgs = Args.size(); + // we need to detect if we can qualify packages with the architecture or not + Args.push_back("--assert-multi-arch"); + Args.push_back(NULL); + + + pid_t dpkgAssertMultiArch = ExecFork(); + if (dpkgAssertMultiArch == 0) + { + std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory"); + if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0) + _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --assert-multi-arch", chrootDir.c_str()); + // redirect everything to the ultimate sink as we only need the exit-status + int const nullfd = open("/dev/null", O_RDONLY); + dup2(nullfd, STDIN_FILENO); + dup2(nullfd, STDOUT_FILENO); + dup2(nullfd, STDERR_FILENO); + execvp(Args[0], (char**) &Args[0]); + _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!"); + _exit(2); + } + APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1); if (pkgset.empty() == true) return _error->Error(_("No packages found")); @@ -177,6 +233,21 @@ bool DoHold(CommandLine &CmdL) } } + bool dpkgMultiArch = false; + if (dpkgAssertMultiArch > 0) + { + int Status = 0; + while (waitpid(dpkgAssertMultiArch, &Status, 0) != dpkgAssertMultiArch) + { + if (errno == EINTR) + continue; + _error->WarningE("dpkgGo", _("Waited for %s but it wasn't there"), "dpkg --assert-multi-arch"); + break; + } + if (WIFEXITED(Status) == true && WEXITSTATUS(Status) == 0) + dpkgMultiArch = true; + } + if (pkgset.empty() == true) return true; @@ -192,36 +263,60 @@ bool DoHold(CommandLine &CmdL) return true; } - string dpkgcall = _config->Find("Dir::Bin::dpkg", "dpkg"); - std::vector const dpkgoptions = _config->FindVector("DPkg::options"); - for (std::vector::const_iterator o = dpkgoptions.begin(); - o != dpkgoptions.end(); ++o) - dpkgcall.append(" ").append(*o); - dpkgcall.append(" --set-selections"); - FILE *dpkg = popen(dpkgcall.c_str(), "w"); - if (dpkg == NULL) - return _error->Errno("DoHold", "fdopen on dpkg stdin failed"); + Args.erase(Args.begin() + BaseArgs, Args.end()); + Args.push_back("--set-selections"); + Args.push_back(NULL); + + int external[2] = {-1, -1}; + if (pipe(external) != 0) + return _error->WarningE("DoHold", "Can't create IPC pipe for dpkg --set-selections"); + + pid_t dpkgSelection = ExecFork(); + if (dpkgSelection == 0) + { + close(external[1]); + std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory"); + if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0) + _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --set-selections", chrootDir.c_str()); + int const nullfd = open("/dev/null", O_RDONLY); + dup2(nullfd, STDIN_FILENO); + dup2(external[0], STDOUT_FILENO); + dup2(nullfd, STDERR_FILENO); + execvp(Args[0], (char**) &Args[0]); + _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!"); + _exit(2); + } + FILE* dpkg = fdopen(external[1], "w"); for (APT::PackageList::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (MarkHold == true) { - fprintf(dpkg, "%s hold\n", Pkg.FullName(true).c_str()); + fprintf(dpkg, "%s hold\n", Pkg.FullName(!dpkgMultiArch).c_str()); ioprintf(c1out,_("%s set on hold.\n"), Pkg.FullName(true).c_str()); } else { - fprintf(dpkg, "%s install\n", Pkg.FullName(true).c_str()); + fprintf(dpkg, "%s install\n", Pkg.FullName(!dpkgMultiArch).c_str()); ioprintf(c1out,_("Canceled hold on %s.\n"), Pkg.FullName(true).c_str()); } } + fclose(dpkg); - int const status = pclose(dpkg); - if (status == -1) - return _error->Errno("DoHold", "dpkg execution failed in the end"); - if (WIFEXITED(status) == false || WEXITSTATUS(status) != 0) - return _error->Error(_("Executing dpkg failed. Are you root?")); - return true; + if (dpkgSelection > 0) + { + int Status = 0; + while (waitpid(dpkgSelection, &Status, 0) != dpkgSelection) + { + if (errno == EINTR) + continue; + _error->WarningE("dpkgGo", _("Waited for %s but it wasn't there"), "dpkg --set-selection"); + break; + } + if (WIFEXITED(Status) == true && WEXITSTATUS(Status) == 0) + return true; + } + return _error->Error(_("Executing dpkg failed. Are you root?")); } /*}}}*/ /* ShowHold - show packages set on hold in dpkg status {{{*/ -- cgit v1.2.3 From 5eb9a474dca2f48a935c234357c3adc9b372423e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 11 Feb 2012 18:54:48 +0100 Subject: correctly ignore already (un)hold packages --- cmdline/apt-mark.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index b067413e3..fa4134a20 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -220,7 +220,7 @@ bool DoHold(CommandLine &CmdL) bool const MarkHold = strcasecmp(CmdL.FileList[0],"hold") == 0; - for (APT::PackageList::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + for (APT::PackageList::iterator Pkg = pkgset.begin(); Pkg != pkgset.end();) { if ((Pkg->SelectedState == pkgCache::State::Hold) == MarkHold) { @@ -228,9 +228,10 @@ bool DoHold(CommandLine &CmdL) ioprintf(c1out,_("%s was already set on hold.\n"), Pkg.FullName(true).c_str()); else ioprintf(c1out,_("%s was already not hold.\n"), Pkg.FullName(true).c_str()); - pkgset.erase(Pkg); - continue; + Pkg = pkgset.erase(Pkg, true); } + else + ++Pkg; } bool dpkgMultiArch = false; -- cgit v1.2.3 From 5834d7a103cb8b68cd6eb072b4b789ca679a2d71 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 11 Feb 2012 19:46:52 +0100 Subject: fix the hold-testcase as it has problems with 'foreign' operations --- cmdline/apt-mark.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index fa4134a20..ef4331714 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -280,8 +280,8 @@ bool DoHold(CommandLine &CmdL) if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0) _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --set-selections", chrootDir.c_str()); int const nullfd = open("/dev/null", O_RDONLY); - dup2(nullfd, STDIN_FILENO); - dup2(external[0], STDOUT_FILENO); + dup2(external[0], STDIN_FILENO); + dup2(nullfd, STDOUT_FILENO); dup2(nullfd, STDERR_FILENO); execvp(Args[0], (char**) &Args[0]); _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!"); -- cgit v1.2.3 From 0c73b84b001028338c0862c045c0cc4e6b191fcb Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 18 Feb 2012 20:44:31 +0100 Subject: * cmdline/apt-get.cc: - if a package can't be removed as it is not installed, suggest to the user an (installed) multiarch silbing with 'Did you mean?' --- cmdline/apt-get.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 32ee46980..42a3929d6 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -904,7 +904,23 @@ struct TryToRemove { if ((Pkg->CurrentVer == 0 && PurgePkgs == false) || (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled)) { - ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.FullName(true).c_str()); + pkgCache::GrpIterator Grp = Pkg.Group(); + pkgCache::PkgIterator P = Grp.PackageList(); + for (; P.end() != true; P = Grp.NextPkg(P)) + { + if (P == Pkg) + continue; + if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled)) + { + // TRANSLATORS: Note, this is not an interactive question + ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"), + Pkg.FullName(true).c_str(), P.FullName(true).c_str()); + break; + } + } + if (P.end() == true) + ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str()); + // MarkInstall refuses to install packages on hold Pkg->SelectedState = pkgCache::State::Hold; } -- cgit v1.2.3 From ca5e41fdced7a5566b07dfc2d6adc67d74fa2d93 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 18 Feb 2012 21:20:57 +0100 Subject: improve 'error' message for packages which are only referenced e.g. in a Depends line and are now requested for removal --- cmdline/apt-get.cc | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 42a3929d6..f4ad75d1c 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -713,11 +713,32 @@ public: } 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()); + if (Pkg->ProvidesList != 0) + { + 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()); + } + else + { + pkgCache::GrpIterator Grp = Pkg.Group(); + pkgCache::PkgIterator P = Grp.PackageList(); + for (; P.end() != true; P = Grp.NextPkg(P)) + { + if (P == Pkg) + continue; + if (P->CurrentVer != 0) { + // TRANSLATORS: Note, this is not an interactive question + ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"), + Pkg.FullName(true).c_str(), P.FullName(true).c_str()); + break; + } + } + if (P.end() == true) + ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str()); + } return pkgCache::VerIterator(Cache, 0); } -- cgit v1.2.3 From 73edfd42d957468168551cf5a2927b7153961446 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 25 Feb 2012 19:44:55 +0100 Subject: * cmdline/apt-cache.cc: - correct --pre-depends option by using dash consistently (LP: #940837) --- 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 1cd5080cc..94654ffd4 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1739,7 +1739,7 @@ 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,"pre-depends","APT::Cache::ShowPre-Depends",0}, {0,"depends","APT::Cache::ShowDepends",0}, {0,"recommends","APT::Cache::ShowRecommends",0}, {0,"suggests","APT::Cache::ShowSuggests",0}, -- cgit v1.2.3 From dcaa1185506986142bccd990a5dca4c6ec1228cf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 4 Mar 2012 23:47:05 +0100 Subject: fix a bunch of cppcheck "(warning) Member variable '<#>' is not initialized in the constructor." messages (no functional change) --- cmdline/acqprogress.cc | 3 ++- cmdline/apt-extracttemplates.cc | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/acqprogress.cc b/cmdline/acqprogress.cc index 1ccb08804..3ac350aca 100644 --- a/cmdline/acqprogress.cc +++ b/cmdline/acqprogress.cc @@ -31,8 +31,9 @@ using namespace std; // --------------------------------------------------------------------- /* */ AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth,unsigned int Quiet) : - ScreenWidth(ScreenWidth), Quiet(Quiet) + ScreenWidth(ScreenWidth), ID(0), Quiet(Quiet) { + BlankLine[0] = 0; } /*}}}*/ // AcqTextStatus::Start - Downloading has started /*{{{*/ diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc index d5c1a3208..dc4c110a1 100644 --- a/cmdline/apt-extracttemplates.cc +++ b/cmdline/apt-extracttemplates.cc @@ -53,8 +53,8 @@ pkgCache *DebFile::Cache = 0; // --------------------------------------------------------------------- /* */ DebFile::DebFile(const char *debfile) - : File(debfile, FileFd::ReadOnly), Control(0), DepOp(0), - PreDepOp(0), Config(0), Template(0), Which(None) + : File(debfile, FileFd::ReadOnly), Size(0), Control(NULL), ControlLen(0), + DepOp(0), PreDepOp(0), Config(0), Template(0), Which(None) { } /*}}}*/ -- cgit v1.2.3 From 785412cf3b03878fc6857c7d453376a029d9eb6a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 5 Mar 2012 00:31:52 +0100 Subject: fix "(style) The scope of the variable 'count' can be reduced" --- cmdline/apt-cdrom.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index fa48debcd..0017d954e 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -150,10 +150,9 @@ bool DoAdd(CommandLine &) bool res = true; bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect", true); - unsigned int count = 0; - if (AutoDetect && UdevCdroms.Dlopen()) { + unsigned int count = 0; while (AutoDetectCdrom(UdevCdroms, count)) res &= cdrom.Add(&log); } else { @@ -178,10 +177,10 @@ bool DoIdent(CommandLine &) bool res = true; bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); - unsigned int count = 0; - + if (AutoDetect && UdevCdroms.Dlopen()) { + unsigned int count = 0; while (AutoDetectCdrom(UdevCdroms, count)) res &= cdrom.Ident(ident, &log); } else { -- cgit v1.2.3