summaryrefslogtreecommitdiffstats
path: root/apt-pkg/statechanges.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:00:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:00:48 +0000
commit851b6a097165af4d51c0db01b5e05256e5006896 (patch)
tree5f7c388ec894a7806c49a99f3bdb605d0b299a7c /apt-pkg/statechanges.h
parentInitial commit. (diff)
downloadapt-851b6a097165af4d51c0db01b5e05256e5006896.tar.xz
apt-851b6a097165af4d51c0db01b5e05256e5006896.zip
Adding upstream version 2.6.1.upstream/2.6.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--apt-pkg/statechanges.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/apt-pkg/statechanges.h b/apt-pkg/statechanges.h
new file mode 100644
index 0000000..2f63d51
--- /dev/null
+++ b/apt-pkg/statechanges.h
@@ -0,0 +1,58 @@
+#include <apt-pkg/cacheset.h>
+#include <apt-pkg/macros.h>
+#include <apt-pkg/pkgcache.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
+#define APT_GETTERSETTER(Name) \
+ APT::VersionVector& Name(); \
+ void Name(pkgCache::VerIterator const &Ver)
+ APT_GETTERSETTER(Hold);
+ APT_GETTERSETTER(Unhold);
+ APT_GETTERSETTER(Install);
+ APT_GETTERSETTER(Remove);
+ APT_GETTERSETTER(Purge);
+ APT::VersionVector& Error();
+#undef APT_GETTERSETTER
+
+ // operate on all containers at once
+ void clear();
+ bool empty() const;
+
+ /** 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;
+};
+
+}