summaryrefslogtreecommitdiff
path: root/cmdline/apt-mark.cc
diff options
context:
space:
mode:
authorTris Emmy Wilson <anemptystring@gmail.com>2020-01-08 18:24:31 -0600
committerTris Emmy Wilson <anemptystring@gmail.com>2020-01-09 12:44:22 -0600
commit009b144dc466856b05473c73bdf75ea21755b037 (patch)
treea59a5d73e25cf528ecf3710e3414e30160201a70 /cmdline/apt-mark.cc
parent84176f6cde1fda522a3aad21d8238c7bd603da87 (diff)
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.
Diffstat (limited to 'cmdline/apt-mark.cc')
-rw-r--r--cmdline/apt-mark.cc30
1 files changed, 21 insertions, 9 deletions
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<string> 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<string>::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;
}
/*}}}*/