diff mbox series

[V2] Don't set (persistent) state in dry run mode

Message ID 20201122100109.80111-1-sbabic@denx.de
State Accepted
Headers show
Series [V2] Don't set (persistent) state in dry run mode | expand

Commit Message

Stefano Babic Nov. 22, 2020, 10:01 a.m. UTC
From: Christian Storm <christian.storm@siemens.com>

Signed-off-by: Christian Storm <christian.storm@siemens.com>
Signed-off-by: Stefano Babic <sbabic@denx.de>
---

Changes since V1:
	- do not use dry_run from request because this is evaluated
	and can overwrite the default at start-up. Use the result
	stored in globals.dry_run

 core/stream_interface.c | 12 ++++++------
 core/swupdate.c         |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/core/stream_interface.c b/core/stream_interface.c
index 39fa64e..0752e5c 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -243,7 +243,7 @@  static int extract_files(int fd, struct swupdate_cfg *software)
 				 * just once
 				 */
 				if (!installed_directly) {
-					if (software->bootloader_transaction_marker) {
+					if (!software->globals.dry_run && software->bootloader_transaction_marker) {
 						save_state_string((char*)BOOTVAR_TRANSACTION, STATE_IN_PROGRESS);
 					}
 					installed_directly = true;
@@ -572,19 +572,19 @@  void *network_initializer(void *data)
 			 * must be successful. Set we have
 			 * initiated an update
 			 */
-			if (software->bootloader_transaction_marker) {
+			if (!software->globals.dry_run && software->bootloader_transaction_marker) {
 				save_state_string((char*)BOOTVAR_TRANSACTION, STATE_IN_PROGRESS);
 			}
 
 			notify(RUN, RECOVERY_NO_ERROR, INFOLEVEL, "Installation in progress");
 			ret = install_images(software, 0, 0);
 			if (ret != 0) {
-				if (software->bootloader_transaction_marker) {
+				if (!software->globals.dry_run && software->bootloader_transaction_marker) {
 					save_state_string((char*)BOOTVAR_TRANSACTION, STATE_FAILED);
 				}
 				notify(FAILURE, RECOVERY_ERROR, ERRORLEVEL, "Installation failed !");
 				inst.last_install = FAILURE;
-				if (save_state((char *)STATE_KEY, STATE_FAILED) != SERVER_OK) {
+				if (!software->globals.dry_run && save_state((char *)STATE_KEY, STATE_FAILED) != SERVER_OK) {
 					WARN("Cannot persistently store FAILED update state.");
 				}
 			} else {
@@ -592,10 +592,10 @@  void *network_initializer(void *data)
 				 * Clear the recovery variable to indicate to bootloader
 				 * that it is not required to start recovery again
 				 */
-				if (software->bootloader_transaction_marker) {
+				if (!software->globals.dry_run && software->bootloader_transaction_marker) {
 					unset_state((char*)BOOTVAR_TRANSACTION);
 				}
-				if (save_state((char *)STATE_KEY, STATE_INSTALLED) != SERVER_OK) {
+				if (!software->globals.dry_run && save_state((char *)STATE_KEY, STATE_INSTALLED) != SERVER_OK) {
 					ERROR("Cannot persistently store INSTALLED update state.");
 					notify(FAILURE, RECOVERY_ERROR, ERRORLEVEL, "Installation failed !");
 					inst.last_install = FAILURE;
diff --git a/core/swupdate.c b/core/swupdate.c
index 0684de4..56e6c96 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -386,7 +386,7 @@  static int install_from_file(char *fname, int check)
 	/*
 	 * Set "recovery_status" as begin of the transaction"
 	 */
-	if (swcfg.bootloader_transaction_marker) {
+	if (!swcfg.globals.dry_run && swcfg.bootloader_transaction_marker) {
 		save_state_string((char*)BOOTVAR_TRANSACTION, STATE_IN_PROGRESS);
 	}
 
@@ -402,7 +402,7 @@  static int install_from_file(char *fname, int check)
 		return EXIT_FAILURE;
 	}
 
-	if (swcfg.bootloader_transaction_marker) {
+	if (!swcfg.globals.dry_run && swcfg.bootloader_transaction_marker) {
 		unset_state((char*)BOOTVAR_TRANSACTION);
 	}
 	fprintf(stdout, "Software updated successfully\n");
@@ -1069,7 +1069,7 @@  int main(int argc, char **argv)
 		result = install_from_file(fname, opt_c);
 		switch (result) {
 		case EXIT_FAILURE:
-			if (swcfg.bootloader_transaction_marker) {
+			if (!swcfg.globals.dry_run && swcfg.bootloader_transaction_marker) {
 				save_state_string((char*)BOOTVAR_TRANSACTION, STATE_FAILED);
 			}
 			break;