summaryrefslogtreecommitdiff
path: root/apt-pkg/statechanges.h
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-09-25 11:25:25 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-11-04 18:04:00 +0100
commitb49068c566d749130e023536d54588c948c16edf (patch)
tree9d4b0921040f2b529eda14c2d2cc209be0815d37 /apt-pkg/statechanges.h
parent05ef357e575e9c25eb6a35cb693d1eb19bb14d45 (diff)
provide public interface to hold/unhold packages
We had this code lying around in apt-mark for a while now, but other frontends need this (and similar) functionality as well, so its high time that we provide a public interface in libapt for this stuff.
Diffstat (limited to 'apt-pkg/statechanges.h')
-rw-r--r--apt-pkg/statechanges.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/apt-pkg/statechanges.h b/apt-pkg/statechanges.h
new file mode 100644
index 000000000..fa60c5864
--- /dev/null
+++ b/apt-pkg/statechanges.h
@@ -0,0 +1,52 @@
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheset.h>
+#include <apt-pkg/macros.h>
+
+#include <memory>
+
+namespace APT
+{
+
+/** Simple wrapper class to abstract away the differences in storing different
+ * states in different places potentially in different versions.
+ */
+class APT_PUBLIC StateChanges
+{
+public:
+ // getter/setter for the different states
+ APT::VersionVector& Hold();
+ void Hold(pkgCache::VerIterator const &Ver);
+ APT::VersionVector& Unhold();
+ void Unhold(pkgCache::VerIterator const &Ver);
+ APT::VersionVector& Error();
+
+ // forgets all unsaved changes
+ void Discard();
+
+ /** commit the staged changes to the database(s).
+ *
+ * Makes the needed calls to store the requested states.
+ * After this call the state containers will hold only versions
+ * for which the storing operation succeeded. Versions where the
+ * storing operation failed are collected in #Error(). Note that
+ * error is an upper bound as states are changed in batches so it
+ * isn't always clear which version triggered the failure exactly.
+ *
+ * @param DiscardOutput controls if stdout/stderr should be used
+ * by subprocesses for (detailed) error reporting if needed.
+ * @return \b false if storing failed, true otherwise.
+ * Note that some states might be applied even if the whole operation failed.
+ */
+ bool Save(bool const DiscardOutput = false);
+
+ StateChanges();
+ StateChanges(StateChanges&&);
+ StateChanges& operator=(StateChanges&&);
+ ~StateChanges();
+
+private:
+ class APT_HIDDEN Private;
+ std::unique_ptr<Private> d;
+};
+
+}