Delete upgrade files when they are no longer needed 16/275416/7
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 24 May 2022 14:59:24 +0000 (16:59 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 27 May 2022 08:34:43 +0000 (10:34 +0200)
Change-Id: I950b79274a9050b8ba8e3d10a3a2799fd13f3ec4

scripts/upgrade-fota.sh
scripts/upgrade-full.sh
scripts/upgrade-partial.sh
scripts/upgrade-prepare-partitions.sh
scripts/upgrade-trigger.sh

index 0067b5cb34aad174e3ee4c507deaf0f24d936f7e..f998ac85381cae9b8cc0781570fe063ebddfc7b0 100755 (executable)
@@ -17,7 +17,7 @@ FOTA_UPDATE_PREFIX="/run/upgrade-sysroot"
 VERSION_FILE="$FOTA_UPDATE_PREFIX/opt/etc/version"
 DO_RW_UPDATE_FILE="$FOTA_UPDATE_PREFIX/opt/.do_rw_update"
 
-SCRIPT_NAME="update-fota.sh"
+SCRIPT_NAME="upgrade-fota.sh"
 LOG_FILE="/tmp/update-fota.log"
 
 untrap() {
@@ -68,6 +68,14 @@ cleanup() {
 
        done
        CLEANUP_PARTITION=()
+       cleanup_files
+}
+
+cleanup_files() {
+       rm -f -- "$FOTA_DIR"/upgrade-common.inc
+       rm -f -- "$FOTA_DIR/$SCRIPT_NAME"
+       rm -f -- "$FOTA_DIR/$CONFIG_FILE"
+       rm -f -- "$FOTA_DIR/upgrade-trigger.sh"
 }
 
 should_mount_rootfs() {
@@ -106,6 +114,7 @@ reboot_to_fota() {
                critical_flog "[Error] Failed to switch board slot to $NEXT_AB"
                exit 1
        fi
+       cleanup_files
        /bin/sync
        flog "[Info] Rebooting to fota"
        if ! /sbin/reboot fota; then
index 85dd3e51f9f864d31824adeb9a5c003acbfef780..ee9a383eb95c1ff2c132c451041b1b0b6afa9955 100755 (executable)
@@ -33,6 +33,13 @@ DELTA_TAR="$DOWNLOAD_DELTA"
 
 flog "[Info] Using <$DELTA_TAR> delta file."
 
+cleanup_files() {
+       rm -f -- "$DELTA_TAR"
+       rm -f -- "$FOTA_DIR/$SCRIPT_NAME"
+       rm -f -- "$FOTA_DIR/$CONFIG_FILE"
+       rm -f -- "$FOTA_DIR/upgrade-trigger.sh"
+}
+
 reboot_to_fota() {
        flog "[Info] Write paths..."
        touch "$DO_RW_UPDATE_FILE"
@@ -43,6 +50,7 @@ reboot_to_fota() {
                critical_flog "[Error] Failed to switch board slot to $NEXT_AB"
                exit 1
        fi
+       cleanup_files
        /bin/sync
        flog "[Info] Rebooting to fota"
        if ! /sbin/reboot fota; then
@@ -60,3 +68,4 @@ set_upgrade_status 20
 upgrade_images "$DOWNLOAD_DELTA"
 set_upgrade_status 80
 reboot_to_fota
+cleanup_files
index b1d64700a659ad3dd9ca363b95f58048d3e37503..02932798e2acbae34ecf9c98fba10745d05eba74 100755 (executable)
@@ -48,8 +48,8 @@ copy_delta() {
                flog "[Info] delta.tar[.gz] is already placed in correct directory."
        elif [ "$DELTA_TAR_GZ" != "TRUE" ]; then
                # skip copying .tar.gz to fota dir beacause it will have to be extracted, so there is no point in doing so
-               flog "[Info] Copy delta.tar[.gz]..."
-               /bin/cp "$DOWNLOAD_DELTA" "$DELTA_TAR"
+               flog "[Info] Move delta.tar[.gz] from $DOWNLOAD_DELTA to $DELTA_TAR"
+               /bin/mv "$DOWNLOAD_DELTA" "$DELTA_TAR"
        fi
 
        # delta.tar.gz has to be uncompressed to .tar beacause ua and libtota does not support .tar.gz
@@ -103,6 +103,14 @@ cleanup() {
 
        done
        CLEANUP_PARTITION=()
+       cleanup_files
+}
+
+cleanup_files() {
+       rm -f -- "$DELTA_TAR"
+       rm -f -- "$FOTA_DIR/delta.ua"
+       rm -f -- "$FOTA_DIR/$SCRIPT_NAME"
+       rm -f -- "$FOTA_DIR/patchfile.file"
 }
 
 should_mount_rootfs() {
index 0ccb149358c37155f773a1a3924a078d8d6c4717..d7dc7867816e431b923d86270d5dfa872ef7b64f 100755 (executable)
@@ -35,7 +35,12 @@ check_optional_partition() {
        exit "$exit_code"
 }
 
+cleanup_files() {
+       rm -f -- "$FOTA_DIR/$SCRIPT_NAME"
+}
+
 check_ab_partition_scheme
 check_used_block_device
 load_background_copy_list
 background_copy
+cleanup_files
index 2d5cdc307053f9e486f2676d815df64f51333081..f094d2a12e6dff9ea733bf06826ed17dab50bd77 100755 (executable)
@@ -21,7 +21,17 @@ SCRIPT_UPGRADE_PARTIAL="upgrade-partial.sh"
 SCRIPT_UPGRADE_FOTA="upgrade-fota.sh"
 
 prepare_fota_dir() {
-       if [ ! -d "$FOTA_DIR" ]; then
+       if [ -d "$FOTA_DIR" ]; then
+               # Cleanup FOTA_DIR
+               if [ "$(dirname $DOWNLOAD_DELTA)" = "$FOTA_DIR" ]; then
+                       # If provided delta is from inside the FOTA_DIR, delete everything else
+                       DELTA_FILE_NAME=$(basename $DOWNLOAD_DELTA)
+                       rm -rf -- "$FOTA_DIR/!($DELTA_FILE_NAME)"
+               else
+                       # If provided delta is from outside the FOTA_DIR delete everything
+                       rm -rf -- "$FOTA_DIR/*"
+               fi
+       else
                log "[Info] Create fota dir..." "$LOG_FILE"
                mkdir -p "$FOTA_DIR"
        fi