From 009b144dc466856b05473c73bdf75ea21755b037 Mon Sep 17 00:00:00 2001 From: Tris Emmy Wilson Date: Wed, 8 Jan 2020 18:24:31 -0600 Subject: apt-mark: don't lie about successful marks This commit fixes an issue where apt-mark would say it had made a change before actually making the change. For example, when running as a user without permission to write to extended_states, the package is not marked but apt-mark claims it is: ~ % apt-mark manual rxvt-unicode rxvt-unicode set to manually installed. E: Could not create [...snip...] (13: Permission denied) E: Failed to write temporary StateFile /var/lib/apt/extended_states This commit moves reporting of "[package] set to [manually | automatically] installed" after saving extended_states and confirming it was successful. --- cmdline/apt-mark.cc | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index 942f58f0f..92efa0c81 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -56,7 +56,8 @@ static bool DoAuto(CommandLine &CmdL) return _error->Error(_("No packages found")); bool MarkAuto = strcasecmp(CmdL.FileList[0],"auto") == 0; - int AutoMarkChanged = 0; + + vector PackagesMarked; for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { @@ -74,16 +75,27 @@ static bool DoAuto(CommandLine &CmdL) continue; } - if (MarkAuto == false) - ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.FullName(true).c_str()); - else - ioprintf(c1out,_("%s set to automatically installed.\n"), Pkg.FullName(true).c_str()); - + PackagesMarked.push_back(Pkg.FullName(true)); DepCache->MarkAuto(Pkg, MarkAuto); - ++AutoMarkChanged; } - if (AutoMarkChanged > 0 && _config->FindB("APT::Mark::Simulate", false) == false) - return DepCache->writeStateFile(NULL); + + bool MarkWritten = false; + bool IsSimulation = _config->FindB("APT::Mark::Simulate", false); + if (PackagesMarked.size() > 0 && !IsSimulation) { + MarkWritten = DepCache->writeStateFile(NULL); + if(!MarkWritten) { + return MarkWritten; + } + } + + if(IsSimulation || MarkWritten) { + for (vector::const_iterator I = PackagesMarked.begin(); I != PackagesMarked.end(); ++I) { + if (MarkAuto == false) + ioprintf(c1out,_("%s set to manually installed.\n"), (*I).c_str()); + else + ioprintf(c1out,_("%s set to automatically installed.\n"), (*I).c_str()); + } + } return true; } /*}}}*/ -- cgit v1.2.3