diff mbox series

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

Message ID 20201120190514.91888-1-christian.storm@siemens.com
State Changes Requested
Headers show
Series Don't set (persistent) state in dry run mode | expand

Commit Message

Storm, Christian Nov. 20, 2020, 7:05 p.m. UTC
Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 core/stream_interface.c | 12 ++++++------
 core/swupdate.c         |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

Comments

Stefano Babic Nov. 22, 2020, 2:32 p.m. UTC | #1
On 20.11.20 20:05, Christian Storm wrote:
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> ---
>   core/stream_interface.c | 12 ++++++------
>   core/swupdate.c         |  6 +++---
>   2 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/core/stream_interface.c b/core/stream_interface.c
> index 3f8a168..545318f 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;
> @@ -565,19 +565,19 @@ void *network_initializer(void *data)
>   			 * must be successful. Set we have
>   			 * initiated an update
>   			 */
> -			if (software->bootloader_transaction_marker) {
> +			if (!req->dry_run && software->bootloader_transaction_marker) {

run->dry_run and software->globals.dry_run are used, but the they are 
not interchangeable. I sent a V2 for this.

Regards,
Stefano

>   				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 (!req->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 (!req->dry_run && save_state((char *)STATE_KEY, STATE_FAILED) != SERVER_OK) {
>   					WARN("Cannot persistently store FAILED update state.");
>   				}
>   			} else {
> @@ -585,10 +585,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 (!req->dry_run && software->bootloader_transaction_marker) {
>   					unset_state((char*)BOOTVAR_TRANSACTION);
>   				}
> -				if (save_state((char *)STATE_KEY, STATE_INSTALLED) != SERVER_OK) {
> +				if (!req->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 5099abd..8ac6a37 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);
>   	}
>   
> @@ -401,7 +401,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");
> @@ -1068,7 +1068,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;
>
diff mbox series

Patch

diff --git a/core/stream_interface.c b/core/stream_interface.c
index 3f8a168..545318f 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;
@@ -565,19 +565,19 @@  void *network_initializer(void *data)
 			 * must be successful. Set we have
 			 * initiated an update
 			 */
-			if (software->bootloader_transaction_marker) {
+			if (!req->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 (!req->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 (!req->dry_run && save_state((char *)STATE_KEY, STATE_FAILED) != SERVER_OK) {
 					WARN("Cannot persistently store FAILED update state.");
 				}
 			} else {
@@ -585,10 +585,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 (!req->dry_run && software->bootloader_transaction_marker) {
 					unset_state((char*)BOOTVAR_TRANSACTION);
 				}
-				if (save_state((char *)STATE_KEY, STATE_INSTALLED) != SERVER_OK) {
+				if (!req->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 5099abd..8ac6a37 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);
 	}
 
@@ -401,7 +401,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");
@@ -1068,7 +1068,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;