[4/4] xt_geoip_update: Always call the cleanup function when some step fails

Message ID 20191014144756.7674-4-daniel.weismueller@ipfire.org
State Accepted
Headers
Series [1/4] xt_geoip_update: Perform cleanup after successful operation |

Commit Message

Daniel Weismueller Oct. 14, 2019, 2:47 p.m. UTC
  Signed-off-by: Daniel Weism├╝ller <daniel.weismueller@ipfire.org>
---
 src/scripts/xt_geoip_update | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)
  

Patch

diff --git a/src/scripts/xt_geoip_update b/src/scripts/xt_geoip_update
index 6c0b70db0..ebd266533 100644
--- a/src/scripts/xt_geoip_update
+++ b/src/scripts/xt_geoip_update
@@ -117,27 +117,22 @@  function cleanup() {
 }
 
 function main() {
-	# Download ruleset.
-	download || exit $?
+	local func
+	for func in download install build build_legacy; do
+		if ! ${func}; then
+			# Cleanup any temporary data
+			cleanup
 
-	if ! install; then
-		# Do cleanup.
-		cleanup || exit $?
-		exit 1
-	fi
-
-	# Remove temporary files.
-	cleanup || exit $?
-
-	# Convert the ruleset.
-	build || exit $?
+			return 1
+		fi
+	done
 
-	# Convert GeoIP2 to lagacy.
-	build_legacy || exit $?
+	# Cleanup
+	cleanup || return $?
 
-	# Remove temporary files.
-	cleanup || exit $?
+	# All done
+	return 0
 }
 
 # Run the main function.
-main
+main || exit $?