diff mbox series

[RFC,5/9] cpio_utils: cleanup state chaining code

Message ID 20240603085602.2351411-6-dominique.martinet@atmark-techno.com
State RFC
Headers show
Series Proof of concept of chunked checksums | expand

Commit Message

Dominique Martinet June 3, 2024, 8:55 a.m. UTC
We don't need to nest ifs so much, chain steps as they become required.
The step order (input step, decryption, decompression) is preserved.

There is no intended functional change.

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
 core/cpio_utils.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)
diff mbox series

Patch

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index acb3f3b634f8..b0a97004baf6 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -616,31 +616,22 @@  int copyfile(struct swupdate_copy *args)
 		}
 	}
 
+	step = &input_step;
+	state = &input_state;
+
+	if (args->encrypted) {
+		decrypt_state.upstream_step = step;
+		decrypt_state.upstream_state = state;
+		step = &decrypt_step;
+		state = &decrypt_state;
+	}
+
 #if defined(CONFIG_GUNZIP) || defined(CONFIG_ZSTD)
 	if (args->compressed) {
-		if (args->encrypted) {
-			decrypt_state.upstream_step = &input_step;
-			decrypt_state.upstream_state = &input_state;
-			decompress_state.upstream_step = &decrypt_step;
-			decompress_state.upstream_state = &decrypt_state;
-		} else {
-			decompress_state.upstream_step = &input_step;
-			decompress_state.upstream_state = &input_state;
-		}
+		decompress_state.upstream_step = step;
+		decompress_state.upstream_state = state;
 		step = decompress_step;
 		state = &decompress_state;
-	} else {
-#endif
-		if (args->encrypted) {
-			decrypt_state.upstream_step = &input_step;
-			decrypt_state.upstream_state = &input_state;
-			step = &decrypt_step;
-			state = &decrypt_state;
-		} else {
-			step = &input_step;
-			state = &input_state;
-		}
-#if defined(CONFIG_GUNZIP) || defined(CONFIG_ZSTD)
 	}
 #endif