src/libpakfire/snapshot.c \
src/libpakfire/solution.c \
src/libpakfire/transaction.c \
+ src/libpakfire/ui.c \
src/libpakfire/util.c
pkginclude_HEADERS += \
src/libpakfire/include/pakfire/solution.h \
src/libpakfire/include/pakfire/transaction.h \
src/libpakfire/include/pakfire/types.h \
+ src/libpakfire/include/pakfire/ui.h \
src/libpakfire/include/pakfire/util.h
libpakfire_la_CFLAGS = \
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2021 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef PAKFIRE_UI_H
+#define PAKFIRE_UI_H
+
+#ifdef PAKFIRE_PRIVATE
+
+int pakfire_ui_confirm(Pakfire pakfire, const char* message, const char* question);
+
+#endif
+
+#endif /* PAKFIRE_UI_H */
#include <pakfire/repo.h>
#include <pakfire/transaction.h>
#include <pakfire/types.h>
+#include <pakfire/ui.h>
#include <pakfire/util.h>
struct pakfire_transaction {
return 0;
}
+ // Show what would be done
+ char* dump = pakfire_transaction_dump(transaction, 80);
+
+ // Check if we should continue
+ r = pakfire_ui_confirm(transaction->pakfire, dump, _("Is this okay? [y/N]"));
+ if (r) {
+ ERROR(transaction->pakfire, "Transaction aborted upon user request\n");
+ goto ERROR;
+ }
+
+ // Write transaction dump to log
+ INFO(transaction->pakfire, "%s\n", dump);
+
// Download what we need
r = pakfire_transaction_download(transaction);
if (r)
- return r;
+ goto ERROR;
// Perform all steps
r = pakfire_transaction_perform(transaction);
if (r)
- return r;
+ goto ERROR;
- return 0;
+ERROR:
+ free(dump);
+
+ return r;
}
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2021 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <pakfire/pakfire.h>
+#include <pakfire/ui.h>
+
+int pakfire_ui_confirm(Pakfire pakfire, const char* message, const char* question) {
+ // The message is only printed once
+ printf("%s\n", message);
+
+ // Skip this, if running in non-interactive mode
+ if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_NON_INTERACTIVE))
+ return 1;
+
+ while (1) {
+ // Print question
+ printf("%s ", question);
+
+ // Wait for user to enter something
+ char p = getchar();
+
+ switch (p) {
+ // Positive response
+ case 'Y':
+ case 'y':
+ return 1;
+
+ // Negative response
+ case EOF:
+ case 'N':
+ case 'n':
+ return 0;
+
+ // Unknown input, repeat
+ default:
+ continue;
+ }
+ }
+
+ return 0;
+}
self.ui.message(line)
def _execute_transaction(self, transaction):
- # Don't do anything if the transaction is empty
- if len(transaction) == 0:
- self.ui.message(_("Nothing to do"))
- return
-
- # Dump the transaction
- self._dump_transaction(transaction)
-
- # Ask the user to confirm to go ahead
- if not self.ui.confirm():
- self.ui.message(_("Aborted by user"))
- return
-
- # Run the transaction
transaction.run()
def handle_info(self, ns):